summaryrefslogtreecommitdiffstats
path: root/examples/qt3d/advancedcustommaterial
diff options
context:
space:
mode:
authorKevin Ottens <kevin.ottens@kdab.com>2017-08-02 10:25:02 +0200
committerSean Harmer <sean.harmer@kdab.com>2017-09-22 11:21:08 +0000
commite67119b71d1b63c5710100349fa634113e93ada2 (patch)
tree4ada3a09ddfb38152c20ed7d16b062bc910ec234 /examples/qt3d/advancedcustommaterial
parent11b804f9cd70d0abe4ca6168c6fc7aaddf14b82c (diff)
Get rid of adsModelNormalMapped
All materials and examples are ported away from it. It was really not related to normal mapping at all, somehow it was an implementation of adsModel working in tangent space instead of world space. Now we got it all in world space, just like for the metal/rough implementation. Change-Id: I3346277ce9b91328d70d914b319ac25f947fff0e Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'examples/qt3d/advancedcustommaterial')
-rw-r--r--examples/qt3d/advancedcustommaterial/shaders/es2/water.frag12
-rw-r--r--examples/qt3d/advancedcustommaterial/shaders/es2/water.vert25
-rw-r--r--examples/qt3d/advancedcustommaterial/shaders/gl3/water.frag14
-rw-r--r--examples/qt3d/advancedcustommaterial/shaders/gl3/water.vert25
4 files changed, 30 insertions, 46 deletions
diff --git a/examples/qt3d/advancedcustommaterial/shaders/es2/water.frag b/examples/qt3d/advancedcustommaterial/shaders/es2/water.frag
index ea54a87f1..4a417ab34 100644
--- a/examples/qt3d/advancedcustommaterial/shaders/es2/water.frag
+++ b/examples/qt3d/advancedcustommaterial/shaders/es2/water.frag
@@ -1,6 +1,8 @@
#define FP highp
varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
+varying FP vec4 worldTangent;
varying FP vec2 texCoord;
varying FP vec2 waveTexCoord;
varying FP vec2 movtexCoord;
@@ -9,7 +11,6 @@ varying FP vec2 skyTexCoord;
varying FP vec3 vpos;
-varying FP mat3 tangentMatrix;
varying FP vec3 color;
uniform FP sampler2D diffuseTexture;
@@ -30,6 +31,7 @@ uniform FP float normalAmount;
uniform FP vec3 eyePosition;
#pragma include light.inc.frag
+#pragma include coordinatesystems.inc
void main()
{
@@ -50,16 +52,20 @@ void main()
// 2 Animated Layers of specularTexture mixed with the newCoord
FP vec4 specularTextureColor = texture2D( specularTexture, multexCoord+newCoord) + (texture2D( specularTexture, movtexCoord+newCoord ));
// 2 Animated Layers of normalTexture mixed with the newCoord
- FP vec3 normal = normalAmount * texture2D( normalTexture, movtexCoord+newCoord ).rgb - vec3( 1.0 )+(normalAmount * texture2D( normalTexture, multexCoord+newCoord ).rgb - vec3( 1.0 ));
+ FP vec3 tNormal = normalAmount * texture2D( normalTexture, movtexCoord+newCoord ).rgb - vec3( 1.0 )+(normalAmount * texture2D( normalTexture, multexCoord+newCoord ).rgb - vec3( 1.0 ));
// Animated skyTexture layer
FP vec4 skycolor = texture2D(skyTexture, skyTexCoord);
skycolor = skycolor * 0.4;
//Animated foamTexture layer
FP vec4 foamTextureColor = texture2D(foamTexture, texCoord);
+ FP mat3 tangentMatrix = calcWorldSpaceToTangentSpaceMatrix(worldNormal, worldTangent);
+ FP mat3 invertTangentMatrix = transpose(tangentMatrix);
+ FP vec3 wNormal = normalize(invertTangentMatrix * tNormal);
+
// Calculate the lighting model, keeping the specular component separate
FP vec3 diffuseColor, specularColor;
- adsModelNormalMapped(worldPosition, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor);
+ adsModel(worldPosition, wNormal, eyePosition, shininess, diffuseColor, specularColor);
// Combine final fragment color
FP vec4 outputColor = vec4(((skycolor.rgb + ka + diffuseTextureColor.rgb * (diffuseColor))+(specularColor * specularTextureColor.a*specularity)), vpos.y );
diff --git a/examples/qt3d/advancedcustommaterial/shaders/es2/water.vert b/examples/qt3d/advancedcustommaterial/shaders/es2/water.vert
index 1a7d46a46..76dd3f8c0 100644
--- a/examples/qt3d/advancedcustommaterial/shaders/es2/water.vert
+++ b/examples/qt3d/advancedcustommaterial/shaders/es2/water.vert
@@ -6,12 +6,13 @@ attribute FP vec2 vertexTexCoord;
attribute FP vec4 vertexTangent;
varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
+varying FP vec4 worldTangent;
varying FP vec2 texCoord;
varying FP vec2 movtexCoord;
varying FP vec2 multexCoord;
varying FP vec2 waveTexCoord;
varying FP vec2 skyTexCoord;
-varying FP mat3 tangentMatrix;
varying FP vec3 vpos;
uniform FP mat4 modelMatrix;
@@ -42,25 +43,9 @@ void main()
// Transform position, normal, and tangent to world coords
worldPosition = vec3(modelMatrix * vec4(vertexPosition, 1.0));
- FP vec3 normal = normalize(modelNormalMatrix * vertexNormal);
- FP vec3 tangent = normalize(vec3(modelMatrix * vec4(vertexTangent.xyz, 0.0)));
-
- // Make the tangent truly orthogonal to the normal by using Gram-Schmidt.
- // This allows to build the tangentMatrix below by simply transposing the
- // tangent -> world space matrix (which would now be orthogonal)
- tangent = normalize(tangent - dot(tangent, normal) * normal);
-
- // Calculate binormal vector. No "real" need to renormalize it,
- // as built by crossing two normal vectors.
- // To orient the binormal correctly, use the fourth coordinate of the tangent,
- // which is +1 for a right hand system, and -1 for a left hand system.
- FP vec3 binormal = cross(normal, tangent) * vertexTangent.w;
-
- // Construct matrix to transform from eye coords to tangent space
- tangentMatrix = mat3(
- tangent.x, binormal.x, normal.x,
- tangent.y, binormal.y, normal.y,
- tangent.z, binormal.z, normal.z);
+ worldNormal = normalize(modelNormalMatrix * vertexNormal);
+ worldTangent.xyz = normalize(vec3(modelMatrix * vec4(vertexTangent.xyz, 0.0)));
+ worldTangent.w = vertexTangent.w;
// Calculate animated vertex positions
diff --git a/examples/qt3d/advancedcustommaterial/shaders/gl3/water.frag b/examples/qt3d/advancedcustommaterial/shaders/gl3/water.frag
index 9657cc63a..de6e87281 100644
--- a/examples/qt3d/advancedcustommaterial/shaders/gl3/water.frag
+++ b/examples/qt3d/advancedcustommaterial/shaders/gl3/water.frag
@@ -1,6 +1,8 @@
#version 150 core
in vec3 worldPosition;
+in vec3 worldNormal;
+in vec4 worldTangent;
in vec2 texCoord;
in vec2 waveTexCoord;
in vec2 movtexCoord;
@@ -9,7 +11,6 @@ in vec2 skyTexCoord;
in vec3 vpos;
-in mat3 tangentMatrix;
in vec3 color;
uniform sampler2D diffuseTexture;
@@ -32,6 +33,7 @@ uniform vec3 eyePosition;
out vec4 fragColor;
#pragma include light.inc.frag
+#pragma include coordinatesystems.inc
void main()
{
@@ -52,16 +54,22 @@ void main()
// 2 Animated Layers of specularTexture mixed with the newCoord
vec4 specularTextureColor = texture( specularTexture, multexCoord+newCoord) + (texture( specularTexture, movtexCoord+newCoord ));
// 2 Animated Layers of normalTexture mixed with the newCoord
- vec3 normal = normalAmount * texture( normalTexture, movtexCoord+newCoord ).rgb - vec3( 1.0 )+(normalAmount * texture( normalTexture, multexCoord+newCoord ).rgb - vec3( 1.0 ));
+ vec3 tNormal = normalAmount * texture( normalTexture, movtexCoord+newCoord ).rgb - vec3( 1.0 )+(normalAmount * texture( normalTexture, multexCoord+newCoord ).rgb - vec3( 1.0 ));
// Animated skyTexture layer
vec4 skycolor = texture(skyTexture, skyTexCoord);
skycolor = skycolor * 0.4;
//Animated foamTexture layer
vec4 foamTextureColor = texture(foamTexture, texCoord);
+ mat3 tangentMatrix = calcWorldSpaceToTangentSpaceMatrix(worldNormal, worldTangent);
+ mat3 invertTangentMatrix = transpose(tangentMatrix);
+
+ vec3 wNormal = normalize(invertTangentMatrix * tNormal);
+
+
// Calculate the lighting model, keeping the specular component separate
vec3 diffuseColor, specularColor;
- adsModelNormalMapped(worldPosition, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor);
+ adsModel(worldPosition, wNormal, eyePosition, shininess, diffuseColor, specularColor);
// Combine final fragment color
vec4 outputColor = vec4(((skycolor.rgb + ka + diffuseTextureColor.rgb * (diffuseColor))+(specularColor * specularTextureColor.a*specularity)), vpos.y );
diff --git a/examples/qt3d/advancedcustommaterial/shaders/gl3/water.vert b/examples/qt3d/advancedcustommaterial/shaders/gl3/water.vert
index a4ddcf62b..3af37e9a5 100644
--- a/examples/qt3d/advancedcustommaterial/shaders/gl3/water.vert
+++ b/examples/qt3d/advancedcustommaterial/shaders/gl3/water.vert
@@ -6,12 +6,13 @@ in vec2 vertexTexCoord;
in vec4 vertexTangent;
out vec3 worldPosition;
+out vec3 worldNormal;
+out vec4 worldTangent;
out vec2 texCoord;
out vec2 movtexCoord;
out vec2 multexCoord;
out vec2 waveTexCoord;
out vec2 skyTexCoord;
-out mat3 tangentMatrix;
out vec3 vpos;
uniform mat4 modelMatrix;
@@ -42,25 +43,9 @@ void main()
// Transform position, normal, and tangent to world coords
worldPosition = vec3(modelMatrix * vec4(vertexPosition, 1.0));
- vec3 normal = normalize(modelNormalMatrix * vertexNormal);
- vec3 tangent = normalize(vec3(modelMatrix * vec4(vertexTangent.xyz, 0.0)));
-
- // Make the tangent truly orthogonal to the normal by using Gram-Schmidt.
- // This allows to build the tangentMatrix below by simply transposing the
- // tangent -> world space matrix (which would now be orthogonal)
- tangent = normalize(tangent - dot(tangent, normal) * normal);
-
- // Calculate binormal vector. No "real" need to renormalize it,
- // as built by crossing two normal vectors.
- // To orient the binormal correctly, use the fourth coordinate of the tangent,
- // which is +1 for a right hand system, and -1 for a left hand system.
- vec3 binormal = cross(normal, tangent) * vertexTangent.w;
-
- // Construct matrix to transform from eye coords to tangent space
- tangentMatrix = mat3(
- tangent.x, binormal.x, normal.x,
- tangent.y, binormal.y, normal.y,
- tangent.z, binormal.z, normal.z);
+ worldNormal = normalize(modelNormalMatrix * vertexNormal);
+ worldTangent.xyz = normalize(vec3(modelMatrix * vec4(vertexTangent.xyz, 0.0)));
+ worldTangent.w = vertexTangent.w;
// Calculate animated vertex positions