diff --git a/files/shaders/objects_fragment.glsl b/files/shaders/objects_fragment.glsl index 2304d9ade..877e881f6 100644 --- a/files/shaders/objects_fragment.glsl +++ b/files/shaders/objects_fragment.glsl @@ -28,7 +28,7 @@ varying vec2 emissiveMapUV; #if @normalMap uniform sampler2D normalMap; varying vec2 normalMapUV; -varying vec3 viewTangent; +varying vec3 passTangent; #endif #if @envMap @@ -52,7 +52,7 @@ varying vec4 lighting; varying vec4 passColor; #endif varying vec3 passViewPos; -varying vec3 passViewNormal; +varying vec3 passNormal; #include "lighting.glsl" @@ -77,15 +77,17 @@ void main() gl_FragData[0].xyz = mix(gl_FragData[0].xyz, decalTex.xyz, decalTex.a); #endif - vec3 viewNormal = passViewNormal; - #if @normalMap vec3 normalTex = texture2D(normalMap, normalMapUV).xyz; - vec3 viewBinormal = cross(viewTangent, viewNormal); - mat3 tbn = mat3(viewTangent, viewBinormal, viewNormal); + vec3 normalizedNormal = normalize(passNormal); + 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 diff --git a/files/shaders/objects_vertex.glsl b/files/shaders/objects_vertex.glsl index b65e49666..9aabbe696 100644 --- a/files/shaders/objects_vertex.glsl +++ b/files/shaders/objects_vertex.glsl @@ -22,7 +22,7 @@ varying vec2 emissiveMapUV; #if @normalMap varying vec2 normalMapUV; -varying vec3 viewTangent; +varying vec3 passTangent; #endif #if @envMap @@ -43,7 +43,7 @@ varying vec4 lighting; varying vec4 passColor; #endif varying vec3 passViewPos; -varying vec3 passViewNormal; +varying vec3 passNormal; #include "lighting.glsl" @@ -85,7 +85,7 @@ void main(void) #if @normalMap normalMapUV = (gl_TextureMatrix[@normalMapUV] * gl_MultiTexCoord@normalMapUV).xy; - viewTangent = normalize(gl_NormalMatrix * gl_MultiTexCoord7.xyz); + passTangent = gl_MultiTexCoord7.xyz; #endif #if @specularMap @@ -98,5 +98,5 @@ void main(void) passColor = gl_Color; #endif passViewPos = viewPos.xyz; - passViewNormal = viewNormal; + passNormal = gl_Normal.xyz; }