summaryrefslogtreecommitdiffstats
path: root/examples/qt3d/advancedcustommaterial/shaders/es2
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/shaders/es2
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/shaders/es2')
-rw-r--r--examples/qt3d/advancedcustommaterial/shaders/es2/water.frag12
-rw-r--r--examples/qt3d/advancedcustommaterial/shaders/es2/water.vert25
2 files changed, 14 insertions, 23 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