Browse Source

refactor glsl for physical lights so there is no duplication.

Ben Houston 9 years ago
parent
commit
d005f129a5

+ 5 - 5
src/renderers/shaders/ShaderChunk/ambient_pars.glsl

@@ -2,14 +2,14 @@ uniform vec3 ambientLightColor;
 
 vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
 
-#if defined ( PHYSICALLY_CORRECT_LIGHTS )
+	vec3 irradiance = ambientLightColor;
 
-	return ambientLightColor;
+	#ifndef PHYSICALLY_CORRECT_LIGHTS
 
-#else
+		irradiance *= PI;
 
-	return PI * ambientLightColor;
+	#endif
 
-#endif
+	return irradiance;
 
 }

+ 5 - 5
src/renderers/shaders/ShaderChunk/lights_pars.glsl

@@ -140,15 +140,15 @@
 		float dotNL = dot( geometry.normal, hemiLight.direction );
 		float hemiDiffuseWeight = 0.5 * dotNL + 0.5;
 
-	#if defined( PHYSICALLY_CORRECT_LIGHTS )
+		vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
 
-		return mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
+		#ifndef PHYSICALLY_CORRECT_LIGHTS
 
-	#else
+			irradiance *= PI;
 
-		return PI * mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
+		#endif
 
-	#endif
+		return irradiance;
 
 	}
 

+ 3 - 5
src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl

@@ -26,15 +26,13 @@ void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in Geometri
 
 	float dotNL = saturate( dot( geometry.normal, directLight.direction ) );
 
-#if defined ( PHYSICALLY_CORRECT_LIGHTS )
-
 	vec3 irradiance = dotNL * directLight.color;
 
-#else
+	#ifndef PHYSICALLY_CORRECT_LIGHTS
 
-	vec3 irradiance = dotNL * PI * directLight.color; // punctual light
+		irradiance *= PI; // punctual light
 
-#endif
+	#endif
 
 	reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );
 	reflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;

+ 3 - 5
src/renderers/shaders/ShaderChunk/lights_standard_pars_fragment.glsl

@@ -10,15 +10,13 @@ void RE_Direct_Standard( const in IncidentLight directLight, const in GeometricC
 
 	float dotNL = saturate( dot( geometry.normal, directLight.direction ) );
 
-#if defined ( PHYSICALLY_CORRECT_LIGHTS )
-
 	vec3 irradiance = dotNL * directLight.color;
 
-#else
+	#ifndef PHYSICALLY_CORRECT_LIGHTS
 
-	vec3 irradiance = dotNL * PI * directLight.color; // punctual light
+		irradiance *= PI; // punctual light
 
-#endif
+	#endif
 
 	reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );
 

+ 5 - 5
src/renderers/shaders/ShaderChunk/lights_template.glsl

@@ -87,16 +87,16 @@ IncidentLight directLight;
 
 	#ifdef USE_LIGHTMAP
 
-		#if defined ( PHYSICALLY_CORRECT_LIGHTS )
+		vec3 lightMapIrradiance = texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;
 
-			irradiance += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;
+		#ifndef PHYSICALLY_CORRECT_LIGHTS
 
-		#else
-
-			irradiance += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity; // factor of PI should not be present; included here to prevent breakage
+			lightMapIrradiance *= PI; // factor of PI should not be present; included here to prevent breakage
 
 		#endif
 
+		irradiance += lightMapIrradiance;
+
 	#endif
 
 	#if ( NUM_HEMI_LIGHTS > 0 )