Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGLRenderer: .physicallyCorrectLights -> .useLegacyLights #24975

Merged
merged 4 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/webgl_animation_skinning_ik.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.physicallyCorrectLights = true;
renderer.useLegacyLights = false;
document.body.appendChild( renderer.domElement );

stats = new Stats();
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_lights_physical.html
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@


renderer = new THREE.WebGLRenderer();
renderer.physicallyCorrectLights = true;
renderer.useLegacyLights = false;
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.shadowMap.enabled = true;
renderer.toneMapping = THREE.ReinhardToneMapping;
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_materials_envmaps_hdr.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
scene.background = new THREE.Color( 0x000000 );

renderer = new THREE.WebGLRenderer();
renderer.physicallyCorrectLights = true;
renderer.useLegacyLights = false;
renderer.toneMapping = THREE.ACESFilmicToneMapping;

//
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_nodes_playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.toneMapping = THREE.LinearToneMapping;
renderer.toneMappingExposure = 4000;
renderer.physicallyCorrectLights = true;
renderer.useLegacyLights = false;

renderer.domElement.className = 'renderer';

Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_pmrem_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( width, height );
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.physicallyCorrectLights = true;
renderer.useLegacyLights = false;

// tonemapping
renderer.toneMapping = THREE.ACESFilmicToneMapping;
Expand Down
2 changes: 1 addition & 1 deletion examples/webxr_ar_lighting.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.physicallyCorrectLights = true;
renderer.useLegacyLights = false;
renderer.xr.enabled = true;
container.appendChild( renderer.domElement );

Expand Down
30 changes: 27 additions & 3 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function WebGLRenderer( parameters = {} ) {

// physical lights

this.physicallyCorrectLights = false;
this.useLegacyLights = true;

// tone mapping

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

} );

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

scene.traverse( function ( object ) {

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

// render scene

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

if ( camera.isArrayCamera ) {

Expand Down Expand Up @@ -2251,4 +2251,28 @@ function WebGLRenderer( parameters = {} ) {

}

Object.defineProperties( WebGLRenderer.prototype, {

// @deprecated since r147

physicallyCorrectLights: {

get: function () {

console.warn( 'THREE.WebGLRenderer: the property .physicallyCorrectLights has been removed. Set renderer.useLegacyLights instead.' );
return ! this.useLegacyLights;

},

set: function ( value ) {

console.warn( 'THREE.WebGLRenderer: the property .physicallyCorrectLights has been removed. Set renderer.useLegacyLights instead.' );
this.useLegacyLights = ! value;

}

}

} );

export { WebGLRenderer };
22 changes: 11 additions & 11 deletions src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,17 @@ vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {

float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {

#if defined ( PHYSICALLY_CORRECT_LIGHTS )
#if defined ( LEGACY_LIGHTS )

if ( cutoffDistance > 0.0 && decayExponent > 0.0 ) {

return pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );

}

return 1.0;

#else

// based upon Frostbite 3 Moving to Physically-based Rendering
// page 32, equation 26: E[window1]
Expand All @@ -65,16 +75,6 @@ float getDistanceAttenuation( const in float lightDistance, const in float cutof

return distanceFalloff;

#else

if ( cutoffDistance > 0.0 && decayExponent > 0.0 ) {

return pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );

}

return 1.0;

#endif

}
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/webgl/WebGLLights.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function WebGLLights( extensions, capabilities ) {
const matrix4 = new Matrix4();
const matrix42 = new Matrix4();

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

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

Expand All @@ -224,7 +224,7 @@ function WebGLLights( extensions, capabilities ) {
lights.sort( shadowCastingAndTexturingLightsFirst );

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/webgl/WebGLMaterials.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function WebGLMaterials( renderer, properties ) {
uniforms.lightMap.value = material.lightMap;

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

uniforms.lightMapIntensity.value = material.lightMapIntensity * scaleFactor;

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/webgl/WebGLProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {

parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',

parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
parameters.useLegacyLights ? '#define LEGACY_LIGHTS' : '',

parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
( parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/webgl/WebGLPrograms.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
shadowMapType: renderer.shadowMap.type,

toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
physicallyCorrectLights: renderer.physicallyCorrectLights,
useLegacyLights: renderer.useLegacyLights,

premultipliedAlpha: material.premultipliedAlpha,

Expand Down Expand Up @@ -410,7 +410,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
_programLayers.enable( 8 );
if ( parameters.shadowMapEnabled )
_programLayers.enable( 9 );
if ( parameters.physicallyCorrectLights )
if ( parameters.useLegacyLights )
_programLayers.enable( 10 );
if ( parameters.doubleSided )
_programLayers.enable( 11 );
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( physicallyCorrectLights ) {
function setupLights( useLegacyLights ) {

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

}

Expand Down