summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-12-01 13:34:41 +0100
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-12-02 10:40:16 +0000
commitff67c813fcd377d704bcb9d37b03546797be6193 (patch)
tree183751b99ebcc90cf680d19cef55b9b63dac2b88
parente81795101cad74a70599915028045b11f2763e3a (diff)
Migrate PerVertexMaterial to be light-aware
The original version has no specular component so leave that out in this version as well. To make this simple, introduce adModel(). Change-Id: I474485a19163ec55e6f6e025d94d8172297e847c Reviewed-by: Kevin Ottens <kevin.ottens@kdab.com>
-rw-r--r--src/quick3d/imports/render/defaults/qml/PerVertexColorMaterial.qml5
-rw-r--r--src/render/defaults/qpervertexcolormaterial.cpp5
-rw-r--r--src/render/defaults/qpervertexcolormaterial_p.h2
-rw-r--r--src/render/shaders/es2/light.inc.frag6
-rw-r--r--src/render/shaders/es2/pervertexcolor.frag19
-rw-r--r--src/render/shaders/gl3/light.inc.frag6
-rw-r--r--src/render/shaders/gl3/pervertexcolor.frag21
7 files changed, 20 insertions, 44 deletions
diff --git a/src/quick3d/imports/render/defaults/qml/PerVertexColorMaterial.qml b/src/quick3d/imports/render/defaults/qml/PerVertexColorMaterial.qml
index de5cda4b4..8d41a5043 100644
--- a/src/quick3d/imports/render/defaults/qml/PerVertexColorMaterial.qml
+++ b/src/quick3d/imports/render/defaults/qml/PerVertexColorMaterial.qml
@@ -40,11 +40,6 @@ import Qt3D.Render 2.0
Material {
id:root
- parameters: [
- Parameter { name: "lightPosition"; value: Qt.vector4d(1.0, 1.0, 0.0, 1.0) },
- Parameter { name: "lightIntensity"; value: Qt.vector3d(1.0, 1.0, 1.0) }
- ]
-
ShaderProgram {
id: gl3PerVertexColorShader
vertexShaderCode: loadSource("qrc:/shaders/gl3/pervertexcolor.vert")
diff --git a/src/render/defaults/qpervertexcolormaterial.cpp b/src/render/defaults/qpervertexcolormaterial.cpp
index 5ea8f9fbf..36468e90e 100644
--- a/src/render/defaults/qpervertexcolormaterial.cpp
+++ b/src/render/defaults/qpervertexcolormaterial.cpp
@@ -58,8 +58,6 @@ namespace Qt3DRender {
QPerVertexColorMaterialPrivate::QPerVertexColorMaterialPrivate()
: QMaterialPrivate()
, m_vertexEffect(new QEffect())
- , m_lightPositionParameter(new QParameter(QStringLiteral("lightPosition"), QVector4D(1.0f, 1.0f, 0.0f, 1.0f)))
- , m_lightIntensityParameter(new QParameter(QStringLiteral("lightIntensity"), QVector3D(1.0f, 1.0f, 1.0f)))
, m_vertexGL3Technique(new QTechnique())
, m_vertexGL2Technique(new QTechnique())
, m_vertexES2Technique(new QTechnique())
@@ -145,9 +143,6 @@ void QPerVertexColorMaterialPrivate::init()
m_vertexEffect->addTechnique(m_vertexGL2Technique);
m_vertexEffect->addTechnique(m_vertexES2Technique);
- m_vertexEffect->addParameter(m_lightPositionParameter);
- m_vertexEffect->addParameter(m_lightIntensityParameter);
-
q_func()->setEffect(m_vertexEffect);
}
diff --git a/src/render/defaults/qpervertexcolormaterial_p.h b/src/render/defaults/qpervertexcolormaterial_p.h
index 5b6079b0f..9e8298667 100644
--- a/src/render/defaults/qpervertexcolormaterial_p.h
+++ b/src/render/defaults/qpervertexcolormaterial_p.h
@@ -71,8 +71,6 @@ public:
void init();
QEffect *m_vertexEffect;
- QParameter *m_lightPositionParameter;
- QParameter *m_lightIntensityParameter;
QTechnique *m_vertexGL3Technique;
QTechnique *m_vertexGL2Technique;
QTechnique *m_vertexES2Technique;
diff --git a/src/render/shaders/es2/light.inc.frag b/src/render/shaders/es2/light.inc.frag
index 2879f189d..f75249e75 100644
--- a/src/render/shaders/es2/light.inc.frag
+++ b/src/render/shaders/es2/light.inc.frag
@@ -43,3 +43,9 @@ void adsModel(const in FP vec3 vpos, const in FP vec3 vnormal, const in FP vec3
diffuseColor += att * lights[0].intensity * diffuse * lights[0].color;
specularColor += specular;
}
+
+void adModel(const in FP vec3 vpos, const in FP vec3 vnormal, out FP vec3 diffuseColor)
+{
+ FP vec3 tmp;
+ adsModel(vpos, vnormal, vec3(0.0), 0.0, diffuseColor, tmp);
+}
diff --git a/src/render/shaders/es2/pervertexcolor.frag b/src/render/shaders/es2/pervertexcolor.frag
index e9a6800bb..70bdd3ccb 100644
--- a/src/render/shaders/es2/pervertexcolor.frag
+++ b/src/render/shaders/es2/pervertexcolor.frag
@@ -1,25 +1,14 @@
#define FP highp
-uniform FP vec4 lightPosition;
-uniform FP vec3 lightIntensity;
-
varying FP vec3 position;
varying FP vec3 normal;
varying FP vec3 color;
-FP vec3 adModel( const FP vec3 pos, const FP vec3 n, const FP vec3 col )
-{
- // Calculate the vector from the light to the fragment
- FP vec3 s = normalize( vec3( lightPosition ) - pos );
-
- // Calculate the diffuse component
- FP float diffuse = max( dot( s, n ), 0.0 );
-
- // Combine the ambient and diffuse
- return lightIntensity * ( col + col * diffuse );
-}
+#pragma include light.inc.frag
void main()
{
- gl_FragColor = vec4( adModel( position, normalize( normal ), color ), 1.0 );
+ FP vec3 diffuseColor;
+ adModel(position, normal, diffuseColor);
+ gl_FragColor = vec4( color + color * diffuseColor, 1.0 );
}
diff --git a/src/render/shaders/gl3/light.inc.frag b/src/render/shaders/gl3/light.inc.frag
index acd28b550..c608dd5de 100644
--- a/src/render/shaders/gl3/light.inc.frag
+++ b/src/render/shaders/gl3/light.inc.frag
@@ -45,3 +45,9 @@ void adsModel(const in vec3 vpos, const in vec3 vnormal, const in vec3 eye, cons
specularColor += specular;
}
}
+
+void adModel(const in vec3 vpos, const in vec3 vnormal, out vec3 diffuseColor)
+{
+ vec3 tmp;
+ adsModel(vpos, vnormal, vec3(0.0), 0.0, diffuseColor, tmp);
+}
diff --git a/src/render/shaders/gl3/pervertexcolor.frag b/src/render/shaders/gl3/pervertexcolor.frag
index a636781c4..14efdd8af 100644
--- a/src/render/shaders/gl3/pervertexcolor.frag
+++ b/src/render/shaders/gl3/pervertexcolor.frag
@@ -1,29 +1,16 @@
#version 150 core
-// TODO: Replace with a uniform block
-uniform vec4 lightPosition;
-uniform vec3 lightIntensity;
-
in vec3 position;
in vec3 normal;
in vec3 color;
out vec4 fragColor;
-vec3 adModel( const in vec3 pos, const in vec3 n, const in vec3 col )
-{
- // Calculate the vector from the light to the fragment
- vec3 s = normalize( vec3( lightPosition ) - pos );
-
- // Calculate the diffuse component
- float diffuse = max( dot( s, n ), 0.0 );
-
- // Combine the ambient and diffuse contributions
- return lightIntensity * ( col + col * diffuse );
-}
+#pragma include light.inc.frag
void main()
{
- fragColor = vec4( adModel( position, normalize( normal ), color ), 1.0 );
+ vec3 diffuseColor;
+ adModel(position, normal, diffuseColor);
+ fragColor = vec4( color + color * diffuseColor, 1.0 );
}
-