Skip to content

Commit d005f12

Browse files
committed
refactor glsl for physical lights so there is no duplication.
1 parent d360627 commit d005f12

5 files changed

Lines changed: 21 additions & 25 deletions

File tree

src/renderers/shaders/ShaderChunk/ambient_pars.glsl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ uniform vec3 ambientLightColor;
22

33
vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
44

5-
#if defined ( PHYSICALLY_CORRECT_LIGHTS )
5+
vec3 irradiance = ambientLightColor;
66

7-
return ambientLightColor;
7+
#ifndef PHYSICALLY_CORRECT_LIGHTS
88

9-
#else
9+
irradiance *= PI;
1010

11-
return PI * ambientLightColor;
11+
#endif
1212

13-
#endif
13+
return irradiance;
1414

1515
}

src/renderers/shaders/ShaderChunk/lights_pars.glsl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@
140140
float dotNL = dot( geometry.normal, hemiLight.direction );
141141
float hemiDiffuseWeight = 0.5 * dotNL + 0.5;
142142

143-
#if defined( PHYSICALLY_CORRECT_LIGHTS )
143+
vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
144144

145-
return mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
145+
#ifndef PHYSICALLY_CORRECT_LIGHTS
146146

147-
#else
147+
irradiance *= PI;
148148

149-
return PI * mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
149+
#endif
150150

151-
#endif
151+
return irradiance;
152152

153153
}
154154

src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@ void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in Geometri
2626

2727
float dotNL = saturate( dot( geometry.normal, directLight.direction ) );
2828

29-
#if defined ( PHYSICALLY_CORRECT_LIGHTS )
30-
3129
vec3 irradiance = dotNL * directLight.color;
3230

33-
#else
31+
#ifndef PHYSICALLY_CORRECT_LIGHTS
3432

35-
vec3 irradiance = dotNL * PI * directLight.color; // punctual light
33+
irradiance *= PI; // punctual light
3634

37-
#endif
35+
#endif
3836

3937
reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );
4038
reflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;

src/renderers/shaders/ShaderChunk/lights_standard_pars_fragment.glsl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ void RE_Direct_Standard( const in IncidentLight directLight, const in GeometricC
1010

1111
float dotNL = saturate( dot( geometry.normal, directLight.direction ) );
1212

13-
#if defined ( PHYSICALLY_CORRECT_LIGHTS )
14-
1513
vec3 irradiance = dotNL * directLight.color;
1614

17-
#else
15+
#ifndef PHYSICALLY_CORRECT_LIGHTS
1816

19-
vec3 irradiance = dotNL * PI * directLight.color; // punctual light
17+
irradiance *= PI; // punctual light
2018

21-
#endif
19+
#endif
2220

2321
reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );
2422

src/renderers/shaders/ShaderChunk/lights_template.glsl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,16 @@ IncidentLight directLight;
8787

8888
#ifdef USE_LIGHTMAP
8989

90-
#if defined ( PHYSICALLY_CORRECT_LIGHTS )
90+
vec3 lightMapIrradiance = texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;
9191

92-
irradiance += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;
92+
#ifndef PHYSICALLY_CORRECT_LIGHTS
9393

94-
#else
95-
96-
irradiance += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity; // factor of PI should not be present; included here to prevent breakage
94+
lightMapIrradiance *= PI; // factor of PI should not be present; included here to prevent breakage
9795

9896
#endif
9997

98+
irradiance += lightMapIrradiance;
99+
100100
#endif
101101

102102
#if ( NUM_HEMI_LIGHTS > 0 )

0 commit comments

Comments
 (0)