Skip to content

Commit e3dc226

Browse files
committed
ShaderChunk: Refactored clearcoat code.
1 parent 1062a5b commit e3dc226

File tree

4 files changed

+15
-26
lines changed

4 files changed

+15
-26
lines changed

src/renderers/shaders/ShaderChunk/common.glsl.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ struct GeometricContext {
3939
vec3 position;
4040
vec3 normal;
4141
vec3 viewDir;
42-
43-
#ifdef USE_CLEARCOAT_NORMALMAP
44-
45-
vec3 clearCoatNormal;
46-
47-
#endif
42+
vec3 clearCoatNormal;
4843
};
4944
5045
vec3 transformDirection( in vec3 dir, in mat4 matrix ) {

src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ geometry.viewDir = normalize( vViewPosition );
2424
2525
geometry.clearCoatNormal = clearCoatNormal;
2626
27+
#else
28+
29+
geometry.clearCoatNormal = geometryNormal;
30+
2731
#endif
2832
2933
IncidentLight directLight;

src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,19 @@ void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricC
7878
7979
#ifndef STANDARD
8080
81-
#ifdef USE_CLEARCOAT_NORMALMAP
82-
83-
float ccDotNL = saturate( dot( geometry.clearCoatNormal, directLight.direction ) );
84-
85-
vec3 ccIrradiance = ccDotNL * directLight.color;
86-
87-
#ifndef PHYSICALLY_CORRECT_LIGHTS
88-
89-
ccIrradiance *= PI; // punctual light
81+
float ccDotNL = saturate( dot( geometry.clearCoatNormal, directLight.direction ) );
9082
91-
#endif
83+
vec3 ccIrradiance = ccDotNL * directLight.color;
9284
93-
float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, ccDotNL );
85+
#ifndef PHYSICALLY_CORRECT_LIGHTS
9486
95-
reflectedLight.directSpecular += ccIrradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.clearCoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
87+
ccIrradiance *= PI; // punctual light
9688
97-
#else
98-
99-
float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );
89+
#endif
10090
101-
reflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.normal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
91+
float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, ccDotNL );
10292
103-
#endif
93+
reflectedLight.directSpecular += ccIrradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.clearCoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
10494
10595
#else
10696

src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export default /* glsl */`
3232
#endif
3333
3434
#endif
35-
#ifdef USE_CLEARCOAT_NORMALMAP
3635
37-
vec3 geometryNormal = normal;
36+
// non perturbed normal for clearcoat
37+
38+
vec3 geometryNormal = normal;
3839
39-
#endif
4040
`;

0 commit comments

Comments
 (0)