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

Addons: WebGPU CSM shadows - using shadowNode #29610

Merged
merged 12 commits into from
Oct 26, 2024
1 change: 1 addition & 0 deletions examples/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@
"webgpu_sandbox",
"webgpu_shadertoy",
"webgpu_shadowmap",
"webgpu_shadowmap_csm",
"webgpu_shadowmap_opacity",
"webgpu_shadowmap_vsm",
"webgpu_skinning",
Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/csm/CSM.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { CSMFrustum } from './CSMFrustum.js';
import { CSMShader } from './CSMShader.js';

const _cameraToLightMatrix = new Matrix4();
const _lightSpaceFrustum = new CSMFrustum();
const _lightSpaceFrustum = new CSMFrustum( { webGL: true } );
const _center = new Vector3();
const _bbox = new Box3();
const _uniformArray = [];
Expand All @@ -38,7 +38,7 @@ export class CSM {
this.lightMargin = data.lightMargin || 200;
this.customSplitsCallback = data.customSplitsCallback;
this.fade = false;
this.mainFrustum = new CSMFrustum();
this.mainFrustum = new CSMFrustum( { webGL: true } );
this.frustums = [];
this.breaks = [];

Expand Down
11 changes: 7 additions & 4 deletions examples/jsm/csm/CSMFrustum.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class CSMFrustum {

data = data || {};

this.zNear = data.webGL === true ? - 1 : 0;
Mugen87 marked this conversation as resolved.
Show resolved Hide resolved

this.vertices = {
near: [
new Vector3(),
Expand All @@ -33,6 +35,7 @@ class CSMFrustum {

setFromProjectionMatrix( projectionMatrix, maxFar ) {

const zNear = this.zNear;
const isOrthographic = projectionMatrix.elements[ 2 * 4 + 3 ] === 0;

inverseProjectionMatrix.copy( projectionMatrix ).invert();
Expand All @@ -42,10 +45,10 @@ class CSMFrustum {
// 2 --- 1
// clip space spans from [-1, 1]

this.vertices.near[ 0 ].set( 1, 1, - 1 );
this.vertices.near[ 1 ].set( 1, - 1, - 1 );
this.vertices.near[ 2 ].set( - 1, - 1, - 1 );
this.vertices.near[ 3 ].set( - 1, 1, - 1 );
this.vertices.near[ 0 ].set( 1, 1, zNear );
this.vertices.near[ 1 ].set( 1, - 1, zNear );
this.vertices.near[ 2 ].set( - 1, - 1, zNear );
this.vertices.near[ 3 ].set( - 1, 1, zNear );
this.vertices.near.forEach( function ( v ) {

v.applyMatrix4( inverseProjectionMatrix );
Expand Down
2 changes: 2 additions & 0 deletions examples/jsm/csm/CSMHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class CSMHelper extends Group {
const cascadePlanes = this.cascadePlanes;
const shadowLines = this.shadowLines;

if ( camera === null ) return;

this.position.copy( camera.position );
this.quaternion.copy( camera.quaternion );
this.scale.copy( camera.scale );
Expand Down
Loading