소스 검색

Fix math for TBN calculation when tangents are given

Gary Hsu 8 년 전
부모
커밋
0f6f2950d6
1개의 변경된 파일5개의 추가작업 그리고 3개의 파일을 삭제
  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