Skip to content

Commit

Permalink
Addons: WebGPU CSM shadows - using shadowNode (#29610)
Browse files Browse the repository at this point in the history
* CSM shadows - using shadowNode

* remove accidentally included file

* remove test logging

* Update CSMShadowNode.js

Fix main frustum with WebGL backend.

* rework

* handle camera changes

* CSMShadowNode: Clean up.

* CMSShadowNode: Fix cascade sampling.

* E2E: Update screenshot.

* CSMShadowNode: Clean up.

---------

Co-authored-by: aardgoose <angus.sawyer@email.com>
Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
  • Loading branch information
3 people authored Oct 26, 2024
1 parent f827e45 commit 59100c4
Show file tree
Hide file tree
Showing 8 changed files with 781 additions and 7 deletions.
1 change: 1 addition & 0 deletions examples/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@
"webgpu_sandbox",
"webgpu_shadertoy",
"webgpu_shadowmap",
"webgpu_shadowmap_csm",
"webgpu_shadowmap_opacity",
"webgpu_shadowmap_progressive",
"webgpu_shadowmap_vsm",
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;

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

0 comments on commit 59100c4

Please sign in to comment.