Browse Source

ShaderChunk: Fixed compile crash with flat shaded materials.

Mr.doob 4 years ago
parent
commit
a7c3c87c95
1 changed files with 17 additions and 15 deletions
  1. 17 15
      src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js

+ 17 - 15
src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js

@@ -8,37 +8,39 @@ vec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPo
 
 	vec3 normal = normalize( cross( fdx, fdy ) );
 
+	bool isFrontFacing = dot( vec3( 0, 0, 1 ), normalize( cross( fdx, fdy ) ) ) > 0.0;
+
 #else
 
 	vec3 normal = normalize( vNormal );
 
-#endif
+	// Workaround for Adreno GPUs gl_FrontFacing bug. See #10331 and #15850.
 
-// Workaround for Adreno GPUs gl_FrontFacing bug. See #10331 and #15850.
+	bool isFrontFacing = dot( normal, normalize( cross( fdx, fdy ) ) ) > 0.0;
 
-bool isFrontFacing = dot( normal, normalize( cross( fdx, fdy ) ) ) > 0.0;
+	#ifdef DOUBLE_SIDED
 
-#ifdef DOUBLE_SIDED
+		normal = normal * ( float( isFrontFacing ) * 2.0 - 1.0 );
 
-	normal = normal * ( float( isFrontFacing ) * 2.0 - 1.0 );
+	#endif
 
-#endif
+	#ifdef USE_TANGENT
 
-#ifdef USE_TANGENT
+		vec3 tangent = normalize( vTangent );
+		vec3 bitangent = normalize( vBitangent );
 
-	vec3 tangent = normalize( vTangent );
-	vec3 bitangent = normalize( vBitangent );
+		#ifdef DOUBLE_SIDED
 
-	#ifdef DOUBLE_SIDED
+			tangent = tangent * ( float( isFrontFacing ) * 2.0 - 1.0 );
+			bitangent = bitangent * ( float( isFrontFacing ) * 2.0 - 1.0 );
 
-		tangent = tangent * ( float( isFrontFacing ) * 2.0 - 1.0 );
-		bitangent = bitangent * ( float( isFrontFacing ) * 2.0 - 1.0 );
+		#endif
 
-	#endif
+		#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )
 
-	#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )
+			mat3 vTBN = mat3( tangent, bitangent, normal );
 
-		mat3 vTBN = mat3( tangent, bitangent, normal );
+		#endif
 
 	#endif