Skip to content

Commit 2c8c137

Browse files
authored
SSGIExample: Add Cornell Box-Inspired Scene (#31897)
* SSGIExample: Add Cornell Box Inspired Scene * Improve the naming of everything * Fix some minor shadow biasing artifacts
1 parent ecaced5 commit 2c8c137

File tree

1 file changed

+93
-25
lines changed

1 file changed

+93
-25
lines changed

examples/webgpu_postprocessing_ssgi.html

Lines changed: 93 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
<div id="info">
1212
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> WebGPU - Post-Processing - SSGI<br />
13-
<a href="https://skfb.ly/YZoC" target="_blank" rel="noopener">Mirror's Edge Apartment</a> by
14-
<a href="https://sketchfab.com/aurelien_martel" target="_blank" rel="noopener">Aurélien Martel</a> is licensed under <a href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank" rel="noopener">Creative Commons Attribution-NonCommercial</a>.<br />
1513
</div>
1614

1715
<script type="importmap">
@@ -33,8 +31,6 @@
3331
import { traa } from 'three/addons/tsl/display/TRAANode.js';
3432

3533
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
36-
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
37-
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
3834

3935
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
4036
import Stats from 'three/addons/libs/stats.module.js';
@@ -45,18 +41,17 @@
4541

4642
async function init() {
4743

48-
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 50 );
49-
camera.position.set( 2.8, 1.8, 5 );
44+
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 0.1, 100 );
45+
camera.position.set( 0, 10, 30 );
5046

5147
scene = new THREE.Scene();
52-
scene.background = new THREE.Color( 0xffffff );
48+
scene.background = new THREE.Color( 0xaaaaaa );
5349

5450
renderer = new THREE.WebGPURenderer();
5551
//renderer.setPixelRatio( window.devicePixelRatio ); // probably too costly for most hardware
5652
renderer.setSize( window.innerWidth, window.innerHeight );
5753
renderer.setAnimationLoop( animate );
58-
renderer.toneMapping = THREE.NeutralToneMapping;
59-
renderer.toneMappingExposure = 1.5;
54+
renderer.shadowMap.enabled = true;
6055
document.body.appendChild( renderer.domElement );
6156

6257
stats = new Stats();
@@ -65,10 +60,10 @@
6560
//
6661

6762
controls = new OrbitControls( camera, renderer.domElement );
68-
controls.target.set( 0, 1, 0 );
63+
controls.target.set( 0, 7, 0 );
6964
controls.enablePan = true;
7065
controls.minDistance = 1;
71-
controls.maxDistance = 6;
66+
controls.maxDistance = 100;
7267
controls.update();
7368

7469
//
@@ -121,19 +116,92 @@
121116
const traaPass = traa( compositePass, scenePassDepth, scenePassVelocity, camera );
122117
postProcessing.outputNode = traaPass;
123118

124-
//
125-
126-
const dracoLoader = new DRACOLoader();
127-
dracoLoader.setDecoderPath( 'jsm/libs/draco/' );
128-
dracoLoader.setDecoderConfig( { type: 'js' } );
129-
const loader = new GLTFLoader();
130-
loader.setDRACOLoader( dracoLoader );
131-
loader.setPath( 'models/gltf/' );
132-
133-
const gltf = await loader.loadAsync( 'mirrors_edge.glb' );
134-
135-
const model = gltf.scene;
136-
scene.add( model );
119+
// Cornell Box inspired scene
120+
121+
// Walls
122+
const wallGeometry = new THREE.PlaneGeometry(1, 1);
123+
124+
// Left wall - red
125+
const redWallMaterial = new THREE.MeshPhysicalMaterial({ color: "#ff0000" });
126+
const leftWall = new THREE.Mesh(wallGeometry, redWallMaterial);
127+
leftWall.scale.set( 20, 15, 1 );
128+
leftWall.rotation.y = Math.PI * 0.5;
129+
leftWall.position.set(-10, 7.5, 0);
130+
leftWall.receiveShadow = true;
131+
scene.add(leftWall);
132+
133+
// Right wall - green
134+
const greenWallMaterial = new THREE.MeshPhysicalMaterial({ color: "#00ff00" });
135+
const rightWall = new THREE.Mesh(wallGeometry, greenWallMaterial);
136+
rightWall.scale.set( 20, 15, 1 );
137+
rightWall.rotation.y = Math.PI * -0.5;
138+
rightWall.position.set(10, 7.5, 0);
139+
rightWall.receiveShadow = true;
140+
scene.add(rightWall);
141+
142+
// White walls and boxes
143+
const whiteMaterial = new THREE.MeshPhysicalMaterial({ color: "#fff" });
144+
145+
// Floor
146+
const floor = new THREE.Mesh(wallGeometry, whiteMaterial);
147+
floor.scale.set( 20, 20, 1 );
148+
floor.rotation.x = Math.PI * -.5;
149+
floor.receiveShadow = true;
150+
scene.add(floor);
151+
152+
// Back wall
153+
const backWall = new THREE.Mesh(wallGeometry, whiteMaterial);
154+
backWall.scale.set( 15, 20, 1 );
155+
backWall.rotation.z = Math.PI * -0.5;
156+
backWall.position.set(0, 7.5, -10);
157+
backWall.receiveShadow = true;
158+
scene.add(backWall);
159+
160+
// Ceiling
161+
const ceiling = new THREE.Mesh(wallGeometry, whiteMaterial);
162+
ceiling.scale.set( 20, 20, 1 );
163+
ceiling.rotation.x = Math.PI * 0.5;
164+
ceiling.position.set(0, 15, 0);
165+
ceiling.receiveShadow = true;
166+
scene.add(ceiling);
167+
168+
// Boxes
169+
const tallBoxGeometry = new THREE.BoxGeometry(5, 7, 5);
170+
const tallBox = new THREE.Mesh(tallBoxGeometry, whiteMaterial);
171+
tallBox.rotation.y = Math.PI * 0.25;
172+
tallBox.position.set(-3, 3.5, -2);
173+
tallBox.castShadow = true;
174+
tallBox.receiveShadow = true;
175+
scene.add(tallBox);
176+
177+
const shortBoxGeometry = new THREE.BoxGeometry(4, 4, 4);
178+
const shortBox = new THREE.Mesh(shortBoxGeometry, whiteMaterial);
179+
shortBox.rotation.y = Math.PI * -0.1;
180+
shortBox.position.set(4, 2, 4);
181+
shortBox.castShadow = true;
182+
shortBox.receiveShadow = true;
183+
scene.add(shortBox);
184+
185+
// Light source geometry
186+
const lightSourceGeometry = new THREE.CylinderGeometry(2.5, 2.5, 1, 64);
187+
const lightSourceMaterial = new THREE.MeshBasicMaterial();
188+
const lightSource = new THREE.Mesh(lightSourceGeometry, lightSourceMaterial);
189+
lightSource.position.y = 15;
190+
scene.add(lightSource);
191+
192+
// Point light
193+
const pointLight = new THREE.PointLight("#ffffff", 100);
194+
pointLight.position.set(0, 13, 0);
195+
pointLight.distance = 100;
196+
pointLight.castShadow = true;
197+
pointLight.shadow.mapSize.width = 1024;
198+
pointLight.shadow.mapSize.height = 1024;
199+
pointLight.shadow.bias = -0.0025;
200+
scene.add(pointLight);
201+
202+
// Ambient light
203+
const ambientLight = new THREE.AmbientLight("#0c0c0c");
204+
scene.add(ambientLight);
137205

138206
window.addEventListener( 'resize', onWindowResize );
139207

@@ -143,7 +211,7 @@
143211
output: 0
144212
};
145213

146-
const types = { Default: 0, AO: 1, GI: 2, Beauty: 3 };
214+
const types = { Combined: 0, Direct: 3, AO: 1, GI: 2 };
147215

148216
const gui = new GUI();
149217
gui.title( 'SSGI settings' );

0 commit comments

Comments
 (0)