瀏覽代碼

Merge pull request #9532 from sebavan/master

android lol fix
sebavan 4 年之前
父節點
當前提交
7632e8f254

+ 3 - 0
src/Materials/Node/Blocks/PBR/clearCoatBlock.ts

@@ -313,6 +313,9 @@ export class ClearCoatBlock extends NodeMaterialBlock {
                     ambientMonochrome,
                 #endif
             #endif
+            #if defined(CLEARCOAT_BUMP) || defined(TWOSIDEDLIGHTING)
+                gl_FrontFacing ? 1. : -1.,
+            #endif
                 clearcoatOut
             );
         #else

+ 10 - 4
src/Shaders/ShadersInclude/bumpFragment.fx

@@ -12,15 +12,21 @@
 	#if defined(TANGENT) && defined(NORMAL)
 		mat3 TBN = vTBN;
 	#elif defined(BUMP)
-		mat3 TBN = cotangent_frame(normalW * normalScale, vPositionW, vBumpUV);
-    #else
-		mat3 TBN = cotangent_frame(normalW * normalScale, vPositionW, vDetailUV, vec2(1., 1.));
+		// flip the uv for the backface
+		vec2 TBNUV = gl_FrontFacing ? vBumpUV : -vBumpUV;
+		mat3 TBN = cotangent_frame(normalW * normalScale, vPositionW, TBNUV);
+	#else
+		// flip the uv for the backface
+		vec2 TBNUV = gl_FrontFacing ? vDetailUV : -vDetailUV;
+		mat3 TBN = cotangent_frame(normalW * normalScale, vPositionW, TBNUV, vec2(1., 1.));
 	#endif
 #elif defined(ANISOTROPIC)
 	#if defined(TANGENT) && defined(NORMAL)
 		mat3 TBN = vTBN;
 	#else
-		mat3 TBN = cotangent_frame(normalW, vPositionW, vMainUV1, vec2(1., 1.));
+		// flip the uv for the backface
+		vec2 TBNUV = gl_FrontFacing ? vMainUV1 : -vMainUV1;
+		mat3 TBN = cotangent_frame(normalW, vPositionW, TBNUV, vec2(1., 1.));
 	#endif
 #endif
 

+ 0 - 3
src/Shaders/ShadersInclude/bumpFragmentMainFunctions.fx

@@ -24,9 +24,6 @@
 	// Thanks to http://www.thetenthplanet.de/archives/1180
 	mat3 cotangent_frame(vec3 normal, vec3 p, vec2 uv, vec2 tangentSpaceParams)
 	{
-		// flip the uv for the backface
-		uv = gl_FrontFacing ? uv : -uv;
-
 		// get edge vectors of the pixel triangle
 		vec3 dp1 = dFdx(p);
 		vec3 dp2 = dFdy(p);

+ 7 - 2
src/Shaders/ShadersInclude/pbrBlockClearcoat.fx

@@ -95,6 +95,9 @@ struct clearcoatOutParams
             const in float ambientMonochrome,
         #endif
     #endif
+    #if defined(CLEARCOAT_BUMP) || defined(TWOSIDEDLIGHTING)
+        const in float frontFacingMultiplier,
+    #endif
         out clearcoatOutParams outParams
     )
     {
@@ -165,7 +168,9 @@ struct clearcoatOutParams
             #if defined(TANGENT) && defined(NORMAL)
                 mat3 TBNClearCoat = vTBN;
             #else
-                mat3 TBNClearCoat = cotangent_frame(clearCoatNormalW * clearCoatNormalScale, vPositionW, vClearCoatBumpUV, vClearCoatTangentSpaceParams);
+                // flip the uv for the backface
+                vec2 TBNClearCoatUV = vClearCoatBumpUV * frontFacingMultiplier;
+                mat3 TBNClearCoat = cotangent_frame(clearCoatNormalW * clearCoatNormalScale, vPositionW, TBNClearCoatUV, vClearCoatTangentSpaceParams);
             #endif
 
             #if DEBUGMODE > 0
@@ -185,7 +190,7 @@ struct clearcoatOutParams
         #endif
 
         #if defined(TWOSIDEDLIGHTING) && defined(NORMAL)
-            clearCoatNormalW = gl_FrontFacing ? clearCoatNormalW : -clearCoatNormalW;
+            clearCoatNormalW = clearCoatNormalW * frontFacingMultiplier;
         #endif
 
         outParams.clearCoatNormalW = clearCoatNormalW;

+ 3 - 0
src/Shaders/pbr.fragment.fx

@@ -422,6 +422,9 @@ void main(void) {
                 ambientMonochrome,
             #endif
         #endif
+        #if defined(CLEARCOAT_BUMP) || defined(TWOSIDEDLIGHTING)
+            gl_FrontFacing ? 1. : -1.,
+        #endif
             clearcoatOut
         );
     #else