Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions examples/jsm/lighting/LightProbeGridWebGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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;
Expand Down
9 changes: 3 additions & 6 deletions examples/jsm/objects/Sky.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -97,7 +96,6 @@ Sky.SkyShader = {
uniform float rayleigh;
uniform float turbidity;
uniform float mieCoefficient;
uniform vec3 up;

varying vec3 vWorldPosition;
varying vec3 vSunDirection;
Expand Down Expand Up @@ -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 );

Expand All @@ -172,7 +170,6 @@ Sky.SkyShader = {
varying float vSunE;

uniform float mieDirectionalG;
uniform vec3 up;
uniform float cloudScale;
uniform float cloudSpeed;
uniform float cloudCoverage;
Expand Down Expand Up @@ -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;
Expand All @@ -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]
Expand Down
13 changes: 3 additions & 10 deletions examples/jsm/objects/SkyMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@ class SkyMesh extends Mesh {
*/
this.sunPosition = uniform( new Vector3() );

/**
* The up position.
*
* @type {UniformNode<vec3>}
*/
this.upUniform = uniform( new Vector3( 0, 1, 0 ) );

/**
* The cloud scale uniform.
*
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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

Expand Down
12 changes: 11 additions & 1 deletion examples/jsm/tsl/display/GTAONode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -590,6 +598,8 @@ class GTAONode extends TempNode {

this._aoRenderTarget.dispose();

this._noiseTexture.dispose();

this._material.dispose();

}
Expand Down
Binary file modified examples/screenshots/webgl_lightprobes_sponza.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_lightprobes_sponza.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 7 additions & 16 deletions examples/webgpu_lightprobes_sponza.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,33 +178,24 @@
countY: 7,
countZ: 7,
bounces: 1,
lightAzimuth: - 45,
lightAzimuth: 135,
lightElevation: 55,
lightIntensity: 100.0,
shadows: true
};

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() {
Expand Down