Sfoglia il codice sorgente

Fix math for TBN calculation when tangents are given

Gary Hsu 8 anni fa
parent
commit
0f6f2950d6
1 ha cambiato i file con 5 aggiunte e 3 eliminazioni
  1. 5 3
      src/Shaders/ShadersInclude/bumpVertex.fx

+ 5 - 3
src/Shaders/ShadersInclude/bumpVertex.fx

@@ -1,6 +1,8 @@
 #if defined(BUMP) || defined(PARALLAX)
-	#if defined(TANGENT) && defined(NORMAL) 
-		vec3 bitangent = cross(normal, tangent.xyz) * sign(tangent.w); //aka binormal
-		vTBN = mat3(tangent.xyz, bitangent, normal);
+	#if defined(TANGENT) && defined(NORMAL)
+		vec3 normalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));
+		vec3 tangentW = normalize(vec3(finalWorld * vec4(tangent.xyz, 0.0)));
+		vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
+		vTBN = mat3(tangentW, bitangentW, normalW);
 	#endif
 #endif