diff --git a/examples/jsm/lighting/LightProbeGridWebGL.js b/examples/jsm/lighting/LightProbeGridWebGL.js index 670b6b832684dd..abdb5f7f7c1e32 100644 --- a/examples/jsm/lighting/LightProbeGridWebGL.js +++ b/examples/jsm/lighting/LightProbeGridWebGL.js @@ -320,8 +320,6 @@ class LightProbeGridWebGL extends Object3D { renderer.getScissor( _currentScissor ); const currentScissorTest = renderer.getScissorTest(); - const replacedSunLights = _replaceSunLights( scene ); - // Scene is static across the bake — update once and disable per-render auto updates. const currentMatrixWorldAutoUpdate = scene.matrixWorldAutoUpdate; if ( currentMatrixWorldAutoUpdate === true ) { @@ -331,6 +329,8 @@ class LightProbeGridWebGL extends Object3D { } + const replacedSunLights = _replaceSunLights( scene ); + // Disable shadow map auto-update across all passes — lights don't move. // Force a single shadow update on the first render so maps are initialized. const currentShadowAutoUpdate = renderer.shadowMap.autoUpdate; diff --git a/examples/jsm/objects/Sky.js b/examples/jsm/objects/Sky.js index b7c29b7be4eb77..12252ec6e94c38 100644 --- a/examples/jsm/objects/Sky.js +++ b/examples/jsm/objects/Sky.js @@ -82,7 +82,6 @@ Sky.SkyShader = { 'mieCoefficient': { value: 0.005 }, 'mieDirectionalG': { value: 0.8 }, 'sunPosition': { value: new Vector3() }, - 'up': { value: new Vector3( 0, 1, 0 ) }, 'cloudScale': { value: 0.0002 }, 'cloudSpeed': { value: 0.0001 }, 'cloudCoverage': { value: 0.4 }, @@ -97,7 +96,6 @@ Sky.SkyShader = { uniform float rayleigh; uniform float turbidity; uniform float mieCoefficient; - uniform vec3 up; varying vec3 vWorldPosition; varying vec3 vSunDirection; @@ -149,7 +147,7 @@ Sky.SkyShader = { vSunDirection = normalize( sunPosition ); - vSunE = sunIntensity( dot( vSunDirection, up ) ); + vSunE = sunIntensity( vSunDirection.y ); vSunfade = 1.0 - clamp( 1.0 - exp( ( sunPosition.y / 450000.0 ) ), 0.0, 1.0 ); @@ -172,7 +170,6 @@ Sky.SkyShader = { varying float vSunE; uniform float mieDirectionalG; - uniform vec3 up; uniform float cloudScale; uniform float cloudSpeed; uniform float cloudCoverage; @@ -245,7 +242,7 @@ Sky.SkyShader = { // optical length // cutoff angle at 90 to avoid singularity in next formula. - float zenithAngle = acos( max( 0.0, dot( up, direction ) ) ); + float zenithAngle = acos( max( 0.0, direction.y ) ); float inverse = 1.0 / ( cos( zenithAngle ) + 0.15 * pow( 93.885 - ( ( zenithAngle * 180.0 ) / pi ), -1.253 ) ); float sR = rayleighZenithLength * inverse; float sM = mieZenithLength * inverse; @@ -263,7 +260,7 @@ Sky.SkyShader = { vec3 betaMTheta = vBetaM * mPhase; vec3 Lin = pow( vSunE * ( ( betaRTheta + betaMTheta ) / ( vBetaR + vBetaM ) ) * ( 1.0 - Fex ), vec3( 1.5 ) ); - Lin *= mix( vec3( 1.0 ), pow( vSunE * ( ( betaRTheta + betaMTheta ) / ( vBetaR + vBetaM ) ) * Fex, vec3( 1.0 / 2.0 ) ), clamp( pow( 1.0 - dot( up, vSunDirection ), 5.0 ), 0.0, 1.0 ) ); + Lin *= mix( vec3( 1.0 ), pow( vSunE * ( ( betaRTheta + betaMTheta ) / ( vBetaR + vBetaM ) ) * Fex, vec3( 1.0 / 2.0 ) ), clamp( pow( 1.0 - vSunDirection.y, 5.0 ), 0.0, 1.0 ) ); // nightsky float theta = acos( direction.y ); // elevation --> y-axis, [-pi/2, pi/2] diff --git a/examples/jsm/objects/SkyMesh.js b/examples/jsm/objects/SkyMesh.js index 5e90fea8f23a57..d1d720024b7b6e 100644 --- a/examples/jsm/objects/SkyMesh.js +++ b/examples/jsm/objects/SkyMesh.js @@ -85,13 +85,6 @@ class SkyMesh extends Mesh { */ this.sunPosition = uniform( new Vector3() ); - /** - * The up position. - * - * @type {UniformNode} - */ - this.upUniform = uniform( new Vector3( 0, 1, 0 ) ); - /** * The cloud scale uniform. * @@ -192,7 +185,7 @@ class SkyMesh extends Mesh { // varying sun intensity - const angle = dot( sunDirection, this.upUniform ); + const angle = sunDirection.y; const zenithAngleCos = clamp( angle, - 1, 1 ); const sunIntensity = EE.mul( max( 0.0, float( 1.0 ).sub( pow( e, cutoffAngle.sub( acos( zenithAngleCos ) ).div( steepness ).negate() ) ) ) ); vSunE.assign( sunIntensity ); @@ -247,7 +240,7 @@ class SkyMesh extends Mesh { // optical length // cutoff angle at 90 to avoid singularity in next formula. - const zenithAngle = acos( max( 0.0, dot( this.upUniform, direction ) ) ); + const zenithAngle = acos( max( 0.0, direction.y ) ); const inverse = float( 1.0 ).div( cos( zenithAngle ).add( float( 0.15 ).mul( pow( float( 93.885 ).sub( zenithAngle.mul( 180.0 ).div( pi ) ), - 1.253 ) ) ) ); const sR = rayleighZenithLength.mul( inverse ); const sM = mieZenithLength.mul( inverse ); @@ -272,7 +265,7 @@ class SkyMesh extends Mesh { const betaMTheta = vBetaM.mul( mPhase ); const Lin = pow( vSunE.mul( add( betaRTheta, betaMTheta ).div( add( vBetaR, vBetaM ) ) ).mul( sub( 1.0, Fex ) ), vec3( 1.5 ) ); - Lin.mulAssign( mix( vec3( 1.0 ), pow( vSunE.mul( add( betaRTheta, betaMTheta ).div( add( vBetaR, vBetaM ) ) ).mul( Fex ), vec3( 1.0 / 2.0 ) ), clamp( pow( sub( 1.0, dot( this.upUniform, vSunDirection ) ), 5.0 ), 0.0, 1.0 ) ) ); + Lin.mulAssign( mix( vec3( 1.0 ), pow( vSunE.mul( add( betaRTheta, betaMTheta ).div( add( vBetaR, vBetaM ) ) ).mul( Fex ), vec3( 1.0 / 2.0 ) ), clamp( pow( sub( 1.0, vSunDirection.y ), 5.0 ), 0.0, 1.0 ) ) ); // nightsky diff --git a/examples/jsm/tsl/display/GTAONode.js b/examples/jsm/tsl/display/GTAONode.js index 4a09081491b95d..cf0a58ac93bc7e 100644 --- a/examples/jsm/tsl/display/GTAONode.js +++ b/examples/jsm/tsl/display/GTAONode.js @@ -180,13 +180,21 @@ class GTAONode extends TempNode { */ this._resolution = uniform( new Vector2() ); + /** + * The internal noise texture used by the AO. + * + * @private + * @type {DataTexture} + */ + this._noiseTexture = generateMagicSquareNoise(); + /** * The node represents the internal noise texture used by the AO. * * @private * @type {TextureNode} */ - this._noiseNode = texture( generateMagicSquareNoise() ); + this._noiseNode = texture( this._noiseTexture ); /** * Represents the projection matrix of the scene's camera. @@ -590,6 +598,8 @@ class GTAONode extends TempNode { this._aoRenderTarget.dispose(); + this._noiseTexture.dispose(); + this._material.dispose(); } diff --git a/examples/screenshots/webgl_lightprobes_sponza.jpg b/examples/screenshots/webgl_lightprobes_sponza.jpg index b92ef93804a4f3..8986750e6b70f6 100644 Binary files a/examples/screenshots/webgl_lightprobes_sponza.jpg and b/examples/screenshots/webgl_lightprobes_sponza.jpg differ diff --git a/examples/screenshots/webgpu_lightprobes_sponza.jpg b/examples/screenshots/webgpu_lightprobes_sponza.jpg index 483604a5c083a2..a442c824cb6b69 100644 Binary files a/examples/screenshots/webgpu_lightprobes_sponza.jpg and b/examples/screenshots/webgpu_lightprobes_sponza.jpg differ diff --git a/examples/webgpu_lightprobes_sponza.html b/examples/webgpu_lightprobes_sponza.html index e2420ae63c5ea7..03b63d98c560da 100644 --- a/examples/webgpu_lightprobes_sponza.html +++ b/examples/webgpu_lightprobes_sponza.html @@ -178,7 +178,7 @@ countY: 7, countZ: 7, bounces: 1, - lightAzimuth: - 45, + lightAzimuth: 135, lightElevation: 55, lightIntensity: 100.0, shadows: true @@ -186,25 +186,16 @@ function updateLightPosition() { - const azimuth = THREE.MathUtils.degToRad( params.lightAzimuth ); const elevation = THREE.MathUtils.degToRad( params.lightElevation ); - const radius = lightBaseDistance; - const horizontal = Math.cos( elevation ) * radius; - const vertical = Math.sin( elevation ) * radius; - - dirLight.position.set( - modelCenter.x + Math.cos( azimuth ) * horizontal, - targetY + vertical, - modelCenter.z + Math.sin( azimuth ) * horizontal - ); - dirLight.target.position.set( modelCenter.x, targetY, modelCenter.z ); - dirLight.target.updateMatrixWorld(); + const azimuth = THREE.MathUtils.degToRad( params.lightAzimuth ); - const phi = THREE.MathUtils.degToRad( 90 - params.lightElevation ); - const theta = THREE.MathUtils.degToRad( params.lightAzimuth ); - sun.setFromSphericalCoords( 1, phi, theta ); + sun.setFromSphericalCoords( 1, Math.PI / 2 - elevation, azimuth ); sky.sunPosition.value.copy( sun ); + dirLight.target.position.set( modelCenter.x, targetY, modelCenter.z ); + dirLight.position.copy( dirLight.target.position ).addScaledVector( sun, lightBaseDistance ); + dirLight.target.updateMatrixWorld(); + } function scheduleRebake() {