Skip to content

Commit

Permalink
Remove artist-friendly factor of PI from shaders (#22393)
Browse files Browse the repository at this point in the history
  • Loading branch information
WestLangley authored Aug 23, 2021
1 parent cd862ca commit bd67e49
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 73 deletions.
6 changes: 0 additions & 6 deletions examples/js/shaders/MMDToonShader.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in Geometri
vec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;
#ifndef PHYSICALLY_CORRECT_LIGHTS
irradiance *= PI; // punctual light
#endif
reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;
Expand Down
6 changes: 0 additions & 6 deletions examples/jsm/renderers/nodes/functions/BSDFs.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ void RE_Direct_BlinnPhong( vec3 lightDirection, vec3 lightColor ) {
float dotNL = saturate( dot( NormalView, lightDirection ) );
vec3 irradiance = dotNL * lightColor;
#ifndef PHYSICALLY_CORRECT_LIGHTS
irradiance *= PI; // punctual light
#endif
ReflectedLightDirectDiffuse += irradiance * BRDF_Lambert( MaterialDiffuseColor.rgb );
ReflectedLightDirectSpecular += irradiance * BRDF_BlinnPhong( lightDirection, MaterialSpecularColor, MaterialSpecularShininess );
Expand Down
6 changes: 0 additions & 6 deletions examples/jsm/shaders/MMDToonShader.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in Geometri
vec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;
#ifndef PHYSICALLY_CORRECT_LIGHTS
irradiance *= PI; // punctual light
#endif
reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ function WebGLRenderer( parameters = {} ) {

} );

currentRenderState.setupLights();
currentRenderState.setupLights( _this.physicallyCorrectLights );

scene.traverse( function ( object ) {

Expand Down Expand Up @@ -1033,7 +1033,7 @@ function WebGLRenderer( parameters = {} ) {

shadowMap.render( shadowsArray, scene, camera );

currentRenderState.setupLights();
currentRenderState.setupLights( _this.physicallyCorrectLights );
currentRenderState.setupLightsView( camera );

if ( _clippingEnabled === true ) clipping.endShadows();
Expand Down
12 changes: 6 additions & 6 deletions src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ vIndirectFront += getLightProbeIrradiance( lightProbe, geometry );
getPointLightInfo( pointLights[ i ], geometry, directLight );
dotNL = dot( geometry.normal, directLight.direction );
directLightColor_Diffuse = PI * directLight.color;
directLightColor_Diffuse = directLight.color;
vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
#ifdef DOUBLE_SIDED
vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;
vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;
#endif
Expand All @@ -65,13 +65,13 @@ vIndirectFront += getLightProbeIrradiance( lightProbe, geometry );
getSpotLightInfo( spotLights[ i ], geometry, directLight );
dotNL = dot( geometry.normal, directLight.direction );
directLightColor_Diffuse = PI * directLight.color;
directLightColor_Diffuse = directLight.color;
vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
#ifdef DOUBLE_SIDED
vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;
vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;
#endif
}
Expand All @@ -87,13 +87,13 @@ vIndirectFront += getLightProbeIrradiance( lightProbe, geometry );
getDirectionalLightInfo( directionalLights[ i ], geometry, directLight );
dotNL = dot( geometry.normal, directLight.direction );
directLightColor_Diffuse = PI * directLight.color;
directLightColor_Diffuse = directLight.color;
vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
#ifdef DOUBLE_SIDED
vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;
vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;
#endif
Expand Down
12 changes: 0 additions & 12 deletions src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
vec3 irradiance = ambientLightColor;
#ifndef PHYSICALLY_CORRECT_LIGHTS
irradiance *= PI;
#endif
return irradiance;
}
Expand Down Expand Up @@ -180,12 +174,6 @@ vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
#ifndef PHYSICALLY_CORRECT_LIGHTS
irradiance *= PI;
#endif
return irradiance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in Geometri
float dotNL = saturate( dot( geometry.normal, directLight.direction ) );
vec3 irradiance = dotNL * directLight.color;
#ifndef PHYSICALLY_CORRECT_LIGHTS
irradiance *= PI; // punctual light
#endif
reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,12 @@ void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricC
vec3 irradiance = dotNL * directLight.color;
#ifndef PHYSICALLY_CORRECT_LIGHTS
irradiance *= PI; // punctual light
#endif
#ifdef CLEARCOAT
float dotNLcc = saturate( dot( geometry.clearcoatNormal, directLight.direction ) );
vec3 ccIrradiance = dotNLcc * directLight.color;
#ifndef PHYSICALLY_CORRECT_LIGHTS
ccIrradiance *= PI; // punctual light
#endif
clearcoatSpecular += ccIrradiance * BRDF_GGX( directLight, geometry.viewDir, geometry.clearcoatNormal, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ void RE_Direct_Toon( const in IncidentLight directLight, const in GeometricConte
vec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;
#ifndef PHYSICALLY_CORRECT_LIGHTS
irradiance *= PI; // punctual light
#endif
reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
}
Expand Down
21 changes: 12 additions & 9 deletions src/renderers/webgl/WebGLLights.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function WebGLLights( extensions, capabilities ) {
const matrix4 = new Matrix4();
const matrix42 = new Matrix4();

function setup( lights ) {
function setup( lights, physicallyCorrectLights ) {

let r = 0, g = 0, b = 0;

Expand All @@ -217,6 +217,9 @@ function WebGLLights( extensions, capabilities ) {

lights.sort( shadowCastingLightsFirst );

// artist-friendly light intensity scaling factor
const scaleFactor = ( physicallyCorrectLights !== true ) ? Math.PI : 1;

for ( let i = 0, l = lights.length; i < l; i ++ ) {

const light = lights[ i ];
Expand All @@ -229,9 +232,9 @@ function WebGLLights( extensions, capabilities ) {

if ( light.isAmbientLight ) {

r += color.r * intensity;
g += color.g * intensity;
b += color.b * intensity;
r += color.r * intensity * scaleFactor;
g += color.g * intensity * scaleFactor;
b += color.b * intensity * scaleFactor;

} else if ( light.isLightProbe ) {

Expand All @@ -245,7 +248,7 @@ function WebGLLights( extensions, capabilities ) {

const uniforms = cache.get( light );

uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
uniforms.color.copy( light.color ).multiplyScalar( light.intensity * scaleFactor );

if ( light.castShadow ) {

Expand Down Expand Up @@ -276,7 +279,7 @@ function WebGLLights( extensions, capabilities ) {

uniforms.position.setFromMatrixPosition( light.matrixWorld );

uniforms.color.copy( color ).multiplyScalar( intensity );
uniforms.color.copy( color ).multiplyScalar( intensity * scaleFactor );
uniforms.distance = distance;

uniforms.coneCos = Math.cos( light.angle );
Expand Down Expand Up @@ -327,7 +330,7 @@ function WebGLLights( extensions, capabilities ) {

const uniforms = cache.get( light );

uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
uniforms.color.copy( light.color ).multiplyScalar( light.intensity * scaleFactor );
uniforms.distance = light.distance;
uniforms.decay = light.decay;

Expand Down Expand Up @@ -360,8 +363,8 @@ function WebGLLights( extensions, capabilities ) {

const uniforms = cache.get( light );

uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
uniforms.skyColor.copy( light.color ).multiplyScalar( intensity * scaleFactor );
uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity * scaleFactor );

state.hemi[ hemiLength ] = uniforms;

Expand Down
4 changes: 2 additions & 2 deletions src/renderers/webgl/WebGLRenderStates.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ function WebGLRenderState( extensions, capabilities ) {

}

function setupLights() {
function setupLights( physicallyCorrectLights ) {

lights.setup( lightsArray );
lights.setup( lightsArray, physicallyCorrectLights );

}

Expand Down

0 comments on commit bd67e49

Please sign in to comment.