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

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
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
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;
Copy link
Collaborator

@Mugen87 Mugen87 Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CSMFrustum creates internal instances of CSMFrustum but without honoring the data parameter (see line 87).

It seems data must be a property so you can pass it later to the ctor.


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