summaryrefslogtreecommitdiffstats
path: root/src/extras/shaders/es2/normaldiffusemap.frag
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 /src/extras/shaders/es2/normaldiffusemap.frag
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 'src/extras/shaders/es2/normaldiffusemap.frag')
-rw-r--r--src/extras/shaders/es2/normaldiffusemap.frag13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/extras/shaders/es2/normaldiffusemap.frag b/src/extras/shaders/es2/normaldiffusemap.frag
index c69aa8b81..e1f19b81a 100644
--- a/src/extras/shaders/es2/normaldiffusemap.frag
+++ b/src/extras/shaders/es2/normaldiffusemap.frag
@@ -1,8 +1,9 @@
#define FP highp
varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
+varying FP vec4 worldTangent;
varying FP vec2 texCoord;
-varying FP mat3 tangentMatrix;
uniform sampler2D diffuseTexture;
uniform sampler2D normalTexture;
@@ -15,16 +16,22 @@ uniform FP float shininess; // Specular shininess factor
uniform FP vec3 eyePosition;
#pragma include light.inc.frag
+#pragma include coordinatesystems.inc
void main()
{
// Sample the textures at the interpolated texCoords
FP vec4 diffuseTextureColor = texture2D( diffuseTexture, texCoord );
- FP vec3 normal = 2.0 * texture2D( normalTexture, texCoord ).rgb - vec3( 1.0 );
+ FP vec3 tNormal = 2.0 * texture2D( normalTexture, texCoord ).rgb - vec3( 1.0 );
+
+ 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 spec with ambient+diffuse for final fragment color
gl_FragColor = vec4( ka + diffuseTextureColor.rgb * diffuseColor + ks * specularColor, 1.0 );