ソースを参照

ShaderChunk: Refactored clearcoat code.

Mr.doob 6 年 前
コミット
e3dc2265df

+ 1 - 6
src/renderers/shaders/ShaderChunk/common.glsl.js

@@ -39,12 +39,7 @@ struct GeometricContext {
 	vec3 position;
 	vec3 normal;
 	vec3 viewDir;
-
-	#ifdef USE_CLEARCOAT_NORMALMAP
-
-		vec3 clearCoatNormal;
-
-	#endif
+	vec3 clearCoatNormal;
 };
 
 vec3 transformDirection( in vec3 dir, in mat4 matrix ) {

+ 4 - 0
src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js

@@ -24,6 +24,10 @@ geometry.viewDir = normalize( vViewPosition );
 
 	geometry.clearCoatNormal = clearCoatNormal;
 
+#else
+
+	geometry.clearCoatNormal = geometryNormal;
+
 #endif
 
 IncidentLight directLight;

+ 7 - 17
src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js

@@ -78,29 +78,19 @@ void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricC
 
 	#ifndef STANDARD
 
-		#ifdef USE_CLEARCOAT_NORMALMAP
-
-			float ccDotNL = saturate( dot( geometry.clearCoatNormal, directLight.direction ) );
-
-			vec3 ccIrradiance = ccDotNL * directLight.color;
-
-			#ifndef PHYSICALLY_CORRECT_LIGHTS
-
-				ccIrradiance *= PI; // punctual light
+		float ccDotNL = saturate( dot( geometry.clearCoatNormal, directLight.direction ) );
 
-			#endif
+		vec3 ccIrradiance = ccDotNL * directLight.color;
 
-			float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, ccDotNL );
+		#ifndef PHYSICALLY_CORRECT_LIGHTS
 
-			reflectedLight.directSpecular += ccIrradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.clearCoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
+			ccIrradiance *= PI; // punctual light
 
-		#else
-
-			float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );
+		#endif
 
-			reflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.normal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
+		float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, ccDotNL );
 
-		#endif
+		reflectedLight.directSpecular += ccIrradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.clearCoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
 
 	#else
 

+ 3 - 3
src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js

@@ -32,9 +32,9 @@ export default /* glsl */`
 	#endif
 
 #endif
-#ifdef USE_CLEARCOAT_NORMALMAP
 
-	vec3 geometryNormal = normal;
+// non perturbed normal for clearcoat
+
+vec3 geometryNormal = normal;
 
-#endif
 `;