From e67119b71d1b63c5710100349fa634113e93ada2 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Wed, 2 Aug 2017 10:25:02 +0200 Subject: 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 --- src/extras/shaders/es2/normaldiffusemap.frag | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/extras/shaders/es2/normaldiffusemap.frag') 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 ); -- cgit v1.2.3