diff options
-rw-r--r-- | src/render/defaults/defaults.pri | 8 | ||||
-rw-r--r-- | src/render/defaults/qphongmaterial.cpp | 252 | ||||
-rw-r--r-- | src/render/defaults/qphongmaterial.h | 90 | ||||
-rw-r--r-- | src/render/defaults/qphongmaterial_p.h | 91 | ||||
-rw-r--r-- | src/render/render.pro | 5 | ||||
-rw-r--r-- | src/render/render.qrc | 4 | ||||
-rw-r--r-- | src/render/shaders/es2/phong.frag | 43 | ||||
-rw-r--r-- | src/render/shaders/es2/phong.vert | 19 | ||||
-rw-r--r-- | src/render/shaders/gl3/phong.frag | 45 | ||||
-rw-r--r-- | src/render/shaders/gl3/phong.vert | 19 |
10 files changed, 575 insertions, 1 deletions
diff --git a/src/render/defaults/defaults.pri b/src/render/defaults/defaults.pri new file mode 100644 index 000000000..c2f77f887 --- /dev/null +++ b/src/render/defaults/defaults.pri @@ -0,0 +1,8 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/qphongmaterial.h \ + $$PWD/qphongmaterial_p.h + +SOURCES += \ + $$PWD/qphongmaterial.cpp diff --git a/src/render/defaults/qphongmaterial.cpp b/src/render/defaults/qphongmaterial.cpp new file mode 100644 index 000000000..87c88ef54 --- /dev/null +++ b/src/render/defaults/qphongmaterial.cpp @@ -0,0 +1,252 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qphongmaterial.h" +#include "qphongmaterial_p.h" +#include <Qt3DRenderer/qmaterial.h> +#include <Qt3DRenderer/qeffect.h> +#include <Qt3DRenderer/qtechnique.h> +#include <Qt3DRenderer/qshaderprogram.h> +#include <Qt3DRenderer/qparameter.h> +#include <Qt3DRenderer/qrenderpass.h> +#include <Qt3DRenderer/qopenglfilter.h> +#include <Qt3DRenderer/qparametermapping.h> +#include <QUrl> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +QPhongMaterialPrivate::QPhongMaterialPrivate(QPhongMaterial *qq) + : QMaterialPrivate(qq) + , m_phongEffect(new QEffect()) + , m_ambientParameter(new QParameter(QStringLiteral("ambient"), QColor::fromRgbF(0.05f, 0.05f, 0.05f, 1.0f))) + , m_diffuseParameter(new QParameter(QStringLiteral("diffuse"), QColor::fromRgbF(0.7f, 0.7f, 0.7f, 1.0f))) + , m_specularParameter(new QParameter(QStringLiteral("specular"), QColor::fromRgbF(0.95f, 0.95f, 0.95f, 1.0f))) + , m_shininessParameter(new QParameter(QStringLiteral("shininess"), 150.0f)) + , m_phongGL3Technique(new QTechnique()) + , m_phongGL2Technique(new QTechnique()) + , m_phongES2Technique(new QTechnique()) + , m_phongGL3RenderPass(new QRenderPass()) + , m_phongGL2RenderPass(new QRenderPass()) + , m_phongES2RenderPass(new QRenderPass()) + , m_phongGL3Shader(new QShaderProgram()) + , m_phongGL2ES2Shader(new QShaderProgram()) + , m_ambientParameterMapping(new QParameterMapping(QStringLiteral("ambient"), QStringLiteral("ka"), QParameterMapping::Uniform)) + , m_diffuseParameterMapping(new QParameterMapping(QStringLiteral("diffuse"), QStringLiteral("kd"), QParameterMapping::Uniform)) + , m_specularParameterMapping(new QParameterMapping(QStringLiteral("specular"), QStringLiteral("ks"), QParameterMapping::Uniform)) +{ +} + +/*! + \class QPhongMaterial + \brief QPhongMaterial provides a default implementation of the phong lighting effect. + \inmodule Qt3DRender + \since 5.5 + + The phong lighting effect is based on the combination of 3 lighting components ambient, diffuse and specular. + The relative strengths of these components is controlled by means of their reflectivity coefficients which are modelled as RGB triplets: + \li Ambient is the color that is emitted by an object without any other light source. + \li Diffuse is the color that is emitted for rought surface reflections with the lights. + \li Specular is the color emitted for shiny surface reflections with the lights. + \li The shininess of a surface is controlled by a float property. + + This material uses an effect with a single render pass approach and performs per fragment lighting. + Techniques are provided for OpenGL 2, OpenGL 3 or above as well as OpenGL ES 2. +*/ + +/*! + \fn QPhongMaterial::QPhongMaterial + Contrusts a new QPhongMaterial instance. + */ +QPhongMaterial::QPhongMaterial(QNode *parent) + : QMaterial(*new QPhongMaterialPrivate(this), parent) +{ + Q_D(QPhongMaterial); + QObject::connect(d->m_ambientParameter, SIGNAL(valueChanged()), this, SIGNAL(ambientChanged())); + QObject::connect(d->m_diffuseParameter, SIGNAL(valueChanged()), this, SIGNAL(diffuseChanged())); + QObject::connect(d->m_specularParameter, SIGNAL(valueChanged()), this, SIGNAL(specularChanged())); + QObject::connect(d->m_shininessParameter, SIGNAL(valueChanged()), this, SIGNAL(shininessChanged())); + d->init(); +} + +QPhongMaterial::~QPhongMaterial() +{ +} + +/*! + \fn QPhongMaterial::ambient + \return the current QColor ambient value. + */ +QColor QPhongMaterial::ambient() const +{ + Q_D(const QPhongMaterial); + return d->m_ambientParameter->value().value<QColor>(); +} + +/*! + \fn QPhongMaterial::diffuse + \return the current QColor diffuse value. + */ +QColor QPhongMaterial::diffuse() const +{ + Q_D(const QPhongMaterial); + return d->m_diffuseParameter->value().value<QColor>(); +} + +/*! + \fn QPhongMaterial::specular + \return the current QColor specular value. + */ +QColor QPhongMaterial::specular() const +{ + Q_D(const QPhongMaterial); + return d->m_specularParameter->value().value<QColor>(); +} + +/*! + \fn QPhongMaterial::shininess + \return the current shininess as a float value. + */ +float QPhongMaterial::shininess() const +{ + Q_D(const QPhongMaterial); + return d->m_shininessParameter->value().toFloat(); +} + +/*! + \fn QPhongMaterial::setAmbient + Sets the current ambient color to \a color. + */ +void QPhongMaterial::setAmbient(const QColor &color) +{ + Q_D(QPhongMaterial); + d->m_shininessParameter->setValue(color); +} + +/*! + \fn QPhongMaterial::setDiffuse + Sets the current diffuse color to \a diffuse. + */ +void QPhongMaterial::setDiffuse(const QColor &diffuse) +{ + Q_D(QPhongMaterial); + d->m_diffuseParameter->setValue(diffuse); +} + +/*! + \fn QPhongMaterial::setSpecular + Sets the current specular color to \a color. + */ +void QPhongMaterial::setSpecular(const QColor &specular) +{ + Q_D(QPhongMaterial); + d->m_specularParameter->setValue(specular); +} + +/*! + \fn QPhongMaterial::setShininess + Sets the current shininess value to \a shininess. + */ +void QPhongMaterial::setShininess(float shininess) +{ + Q_D(QPhongMaterial); + d->m_shininessParameter->setValue(shininess); +} + +//TO DO: Define how lights are properties are set in the shaders +//Ideally using a QShaderData +void QPhongMaterialPrivate::init() +{ + m_phongGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/phong.vert")))); + m_phongGL3Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/phong.frag")))); + m_phongGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/phong.vert")))); + m_phongGL2ES2Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/phong.frag")))); + + m_phongGL3Technique->openGLFilter()->setApi(QOpenGLFilter::Desktop); + m_phongGL3Technique->openGLFilter()->setMajorVersion(3); + m_phongGL3Technique->openGLFilter()->setMinorVersion(1); + m_phongGL3Technique->openGLFilter()->setProfile(QOpenGLFilter::Core); + + m_phongGL2Technique->openGLFilter()->setApi(QOpenGLFilter::Desktop); + m_phongGL2Technique->openGLFilter()->setMajorVersion(2); + m_phongGL2Technique->openGLFilter()->setMinorVersion(0); + m_phongGL2Technique->openGLFilter()->setProfile(QOpenGLFilter::None); + + m_phongES2Technique->openGLFilter()->setApi(QOpenGLFilter::ES); + m_phongES2Technique->openGLFilter()->setMajorVersion(2); + m_phongES2Technique->openGLFilter()->setMinorVersion(0); + m_phongES2Technique->openGLFilter()->setProfile(QOpenGLFilter::None); + + m_phongGL3RenderPass->setShaderProgram(m_phongGL3Shader); + m_phongGL3RenderPass->addBinding(m_ambientParameterMapping); + m_phongGL3RenderPass->addBinding(m_diffuseParameterMapping); + m_phongGL3RenderPass->addBinding(m_specularParameterMapping); + + m_phongGL2RenderPass->setShaderProgram(m_phongGL2ES2Shader); + m_phongGL2RenderPass->addBinding(m_ambientParameterMapping); + m_phongGL2RenderPass->addBinding(m_diffuseParameterMapping); + m_phongGL2RenderPass->addBinding(m_specularParameterMapping); + + m_phongES2RenderPass->setShaderProgram(m_phongGL2ES2Shader); + m_phongES2RenderPass->addBinding(m_ambientParameterMapping); + m_phongES2RenderPass->addBinding(m_diffuseParameterMapping); + m_phongES2RenderPass->addBinding(m_specularParameterMapping); + + m_phongGL3Technique->addPass(m_phongGL3RenderPass); + m_phongGL2Technique->addPass(m_phongGL2RenderPass); + m_phongES2Technique->addPass(m_phongES2RenderPass); + + m_phongEffect->addTechnique(m_phongGL3Technique); + m_phongEffect->addTechnique(m_phongGL2Technique); + m_phongEffect->addTechnique(m_phongES2Technique); + + m_phongEffect->addParameter(m_ambientParameter); + m_phongEffect->addParameter(m_diffuseParameter); + m_phongEffect->addParameter(m_specularParameter); + m_phongEffect->addParameter(m_shininessParameter); + + static_cast<QMaterial *>(q_ptr)->setEffect(m_phongEffect); +} + +} // Qt3D + +QT_END_NAMESPACE diff --git a/src/render/defaults/qphongmaterial.h b/src/render/defaults/qphongmaterial.h new file mode 100644 index 000000000..49f677567 --- /dev/null +++ b/src/render/defaults/qphongmaterial.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3D_RENDER_QPHONGMATERIAL_H +#define QT3D_RENDER_QPHONGMATERIAL_H + +#include <Qt3DRenderer/qmaterial.h> +#include <QColor> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +class QPhongMaterialPrivate; + +class QT3DRENDERERSHARED_EXPORT QPhongMaterial : public QMaterial +{ + Q_OBJECT + Q_PROPERTY(QColor ambient READ ambient WRITE setAmbient NOTIFY ambientChanged) + Q_PROPERTY(QColor diffuse READ diffuse WRITE setDiffuse NOTIFY diffuseChanged) + Q_PROPERTY(QColor specular READ specular WRITE setSpecular NOTIFY specularChanged) + Q_PROPERTY(float shininess READ shininess WRITE setShininess NOTIFY shininessChanged) + +public: + QPhongMaterial(QNode *parent = 0); + ~QPhongMaterial(); + + QColor ambient() const; + QColor diffuse() const; + QColor specular() const; + float shininess() const; + + void setAmbient(const QColor &color); + void setDiffuse(const QColor &diffuse); + void setSpecular(const QColor &specular); + void setShininess(float shininess); + +Q_SIGNALS: + void ambientChanged(); + void diffuseChanged(); + void specularChanged(); + void shininessChanged(); + +private: + Q_DECLARE_PRIVATE(QPhongMaterial) +}; + +} // Qt3D + +QT_END_NAMESPACE + +#endif // QT3D_RENDER_QPHONGMATERIAL_H diff --git a/src/render/defaults/qphongmaterial_p.h b/src/render/defaults/qphongmaterial_p.h new file mode 100644 index 000000000..421a4c475 --- /dev/null +++ b/src/render/defaults/qphongmaterial_p.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3D_RENDER_QPHONGMATERIAL_P_H +#define QT3D_RENDER_QPHONGMATERIAL_P_H + +#include <Qt3DRenderer/private/qmaterial_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +class QEffect; +class QTechnique; +class QParameter; +class QShaderProgram; +class QRenderPass; +class QParameterMapping; + +class QPhongMaterial; + +class QPhongMaterialPrivate : public QMaterialPrivate +{ + QPhongMaterialPrivate(QPhongMaterial *qq); + + void init(); + + QEffect *m_phongEffect; + QParameter *m_ambientParameter; + QParameter *m_diffuseParameter; + QParameter *m_specularParameter; + QParameter *m_shininessParameter; + QTechnique *m_phongGL3Technique; + QTechnique *m_phongGL2Technique; + QTechnique *m_phongES2Technique; + QRenderPass *m_phongGL3RenderPass; + QRenderPass *m_phongGL2RenderPass; + QRenderPass *m_phongES2RenderPass; + QShaderProgram *m_phongGL3Shader; + QShaderProgram *m_phongGL2ES2Shader; + QParameterMapping *m_ambientParameterMapping; + QParameterMapping *m_diffuseParameterMapping; + QParameterMapping *m_specularParameterMapping; + + Q_DECLARE_PUBLIC(QPhongMaterial) +}; + +} // Qt3D + +QT_END_NAMESPACE + +#endif // QT3D_RENDER_QPHONGMATERIAL_P_H + diff --git a/src/render/render.pro b/src/render/render.pro index 8cf22576c..269074cc3 100644 --- a/src/render/render.pro +++ b/src/render/render.pro @@ -14,11 +14,14 @@ load(qt_module) include (backend/render-backend.pri) include (frontend/render-frontend.pri) include (io/render-io.pri) +include (defaults/defaults.pri) RESOURCES += $$PWD/render.qrc OTHER_FILES += \ - $$PWD/shaders/* + $$PWD/shaders/* \ + $$PWD/shaders/gl3/* \ + $$PWD/shaders/es2/* gcov { CONFIG += static diff --git a/src/render/render.qrc b/src/render/render.qrc index e89252ace..99d332339 100644 --- a/src/render/render.qrc +++ b/src/render/render.qrc @@ -15,5 +15,9 @@ <file>shaders/normaldiffusemap.vert</file> <file>shaders/normaldiffusemap.frag</file> <file>shaders/normaldiffusemapalpha.frag</file> + <file>shaders/gl3/phong.vert</file> + <file>shaders/gl3/phong.frag</file> + <file>shaders/es2/phong.vert</file> + <file>shaders/es2/phong.frag</file> </qresource> </RCC> diff --git a/src/render/shaders/es2/phong.frag b/src/render/shaders/es2/phong.frag new file mode 100644 index 000000000..2bcfe570b --- /dev/null +++ b/src/render/shaders/es2/phong.frag @@ -0,0 +1,43 @@ +#version 120 + +// TODO: Replace with a uniform block +uniform vec4 lightPosition = vec4(1.0, 1.0, 0.0, 1.0); +uniform vec3 lightIntensity = vec3(1.0, 0.0, 1.0); + +// TODO: Replace with a struct +uniform vec3 ka; // Ambient reflectivity +uniform vec3 kd; // Diffuse reflectivity +uniform vec3 ks; // Specular reflectivity +uniform float shininess; // Specular shininess factor + +varying vec3 position; +varying vec3 normal; + +vec3 adsModel( const vec3 pos, const vec3 n ) +{ + // Calculate the vector from the light to the fragment + vec3 s = normalize( vec3( lightPosition ) - pos ); + + // Calculate the vector from the fragment to the eye position + // (origin since this is in "eye" or "camera" space) + vec3 v = normalize( -pos ); + + // Reflect the light beam using the normal at this fragment + vec3 r = reflect( -s, n ); + + // Calculate the diffuse component + float diffuse = max( dot( s, n ), 0.0 ); + + // Calculate the specular component + float specular = 0.0; + if ( dot( s, n ) > 0.0 ) + specular = pow( max( dot( r, v ), 0.0 ), shininess ); + + // Combine the ambient, diffuse and specular contributions + return lightIntensity * ( ka + kd * diffuse + ks * specular ); +} + +void main() +{ + gl_FragColor = vec4( adsModel( position, normalize( normal ) ), 1.0 ); +} diff --git a/src/render/shaders/es2/phong.vert b/src/render/shaders/es2/phong.vert new file mode 100644 index 000000000..35813d19f --- /dev/null +++ b/src/render/shaders/es2/phong.vert @@ -0,0 +1,19 @@ +#version 120 + +attribute vec3 vertexPosition; +attribute vec3 vertexNormal; + +varying vec3 position; +varying vec3 normal; + +uniform mat4 modelView; +uniform mat3 modelViewNormal; +uniform mat4 mvp; + +void main() +{ + normal = normalize( modelViewNormal * vertexNormal ); + position = vec3( modelView * vec4( vertexPosition, 1.0 ) ); + + gl_Position = mvp * vec4( vertexPosition, 1.0 ); +} diff --git a/src/render/shaders/gl3/phong.frag b/src/render/shaders/gl3/phong.frag new file mode 100644 index 000000000..741f4da9f --- /dev/null +++ b/src/render/shaders/gl3/phong.frag @@ -0,0 +1,45 @@ +#version 150 core + +// TODO: Replace with a uniform block +uniform vec4 lightPosition = vec4(1.0, 1.0, 0.0, 1.0); +uniform vec3 lightIntensity = vec3(1.0, 0.0, 1.0); + +// TODO: Replace with a struct +uniform vec3 ka; // Ambient reflectivity +uniform vec3 kd; // Diffuse reflectivity +uniform vec3 ks; // Specular reflectivity +uniform float shininess; // Specular shininess factor + +in vec3 position; +in vec3 normal; + +out vec4 fragColor; + +vec3 adsModel( const in vec3 pos, const in vec3 n ) +{ + // Calculate the vector from the light to the fragment + vec3 s = normalize( vec3( lightPosition ) - pos ); + + // Calculate the vector from the fragment to the eye position + // (origin since this is in "eye" or "camera" space) + vec3 v = normalize( -pos ); + + // Reflect the light beam using the normal at this fragment + vec3 r = reflect( -s, n ); + + // Calculate the diffuse component + float diffuse = max( dot( s, n ), 0.0 ); + + // Calculate the specular component + float specular = 0.0; + if ( dot( s, n ) > 0.0 ) + specular = pow( max( dot( r, v ), 0.0 ), shininess ); + + // Combine the ambient, diffuse and specular contributions + return lightIntensity * ( ka + kd * diffuse + ks * specular ); +} + +void main() +{ + fragColor = vec4( adsModel( position, normalize( normal ) ), 1.0 ); +} diff --git a/src/render/shaders/gl3/phong.vert b/src/render/shaders/gl3/phong.vert new file mode 100644 index 000000000..c0f907f29 --- /dev/null +++ b/src/render/shaders/gl3/phong.vert @@ -0,0 +1,19 @@ +#version 150 core + +in vec3 vertexPosition; +in vec3 vertexNormal; + +out vec3 position; +out vec3 normal; + +uniform mat4 modelView; +uniform mat3 modelViewNormal; +uniform mat4 mvp; + +void main() +{ + normal = normalize( modelViewNormal * vertexNormal ); + position = vec3( modelView * vec4( vertexPosition, 1.0 ) ); + + gl_Position = mvp * vec4( vertexPosition, 1.0 ); +} |