Pass the tangent in object space

move
scrawl 9 years ago
parent 157c11398d
commit b4dda045a6

@ -28,7 +28,7 @@ varying vec2 emissiveMapUV;
#if @normalMap #if @normalMap
uniform sampler2D normalMap; uniform sampler2D normalMap;
varying vec2 normalMapUV; varying vec2 normalMapUV;
varying vec3 viewTangent; varying vec3 passTangent;
#endif #endif
#if @envMap #if @envMap
@ -52,7 +52,7 @@ varying vec4 lighting;
varying vec4 passColor; varying vec4 passColor;
#endif #endif
varying vec3 passViewPos; varying vec3 passViewPos;
varying vec3 passViewNormal; varying vec3 passNormal;
#include "lighting.glsl" #include "lighting.glsl"
@ -77,15 +77,17 @@ void main()
gl_FragData[0].xyz = mix(gl_FragData[0].xyz, decalTex.xyz, decalTex.a); gl_FragData[0].xyz = mix(gl_FragData[0].xyz, decalTex.xyz, decalTex.a);
#endif #endif
vec3 viewNormal = passViewNormal;
#if @normalMap #if @normalMap
vec3 normalTex = texture2D(normalMap, normalMapUV).xyz; vec3 normalTex = texture2D(normalMap, normalMapUV).xyz;
vec3 viewBinormal = cross(viewTangent, viewNormal); vec3 normalizedNormal = normalize(passNormal);
mat3 tbn = mat3(viewTangent, viewBinormal, viewNormal); vec3 normalizedTangent = normalize(passTangent);
vec3 binormal = cross(normalizedTangent, normalizedNormal);
mat3 tbn = mat3(normalizedTangent, binormal, normalizedNormal);
viewNormal = normalize(tbn * (normalTex * 2.0 - 1.0)); vec3 viewNormal = gl_NormalMatrix * normalize(tbn * (normalTex * 2.0 - 1.0));
#else
vec3 viewNormal = gl_NormalMatrix * normalize(passNormal);
#endif #endif

@ -22,7 +22,7 @@ varying vec2 emissiveMapUV;
#if @normalMap #if @normalMap
varying vec2 normalMapUV; varying vec2 normalMapUV;
varying vec3 viewTangent; varying vec3 passTangent;
#endif #endif
#if @envMap #if @envMap
@ -43,7 +43,7 @@ varying vec4 lighting;
varying vec4 passColor; varying vec4 passColor;
#endif #endif
varying vec3 passViewPos; varying vec3 passViewPos;
varying vec3 passViewNormal; varying vec3 passNormal;
#include "lighting.glsl" #include "lighting.glsl"
@ -85,7 +85,7 @@ void main(void)
#if @normalMap #if @normalMap
normalMapUV = (gl_TextureMatrix[@normalMapUV] * gl_MultiTexCoord@normalMapUV).xy; normalMapUV = (gl_TextureMatrix[@normalMapUV] * gl_MultiTexCoord@normalMapUV).xy;
viewTangent = normalize(gl_NormalMatrix * gl_MultiTexCoord7.xyz); passTangent = gl_MultiTexCoord7.xyz;
#endif #endif
#if @specularMap #if @specularMap
@ -98,5 +98,5 @@ void main(void)
passColor = gl_Color; passColor = gl_Color;
#endif #endif
passViewPos = viewPos.xyz; passViewPos = viewPos.xyz;
passViewNormal = viewNormal; passNormal = gl_Normal.xyz;
} }

Loading…
Cancel
Save