|
10 | 10 |
|
11 | 11 | <div id="info"> |
12 | 12 | <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 /> |
15 | 13 | </div> |
16 | 14 |
|
17 | 15 | <script type="importmap"> |
|
33 | 31 | import { traa } from 'three/addons/tsl/display/TRAANode.js'; |
34 | 32 |
|
35 | 33 | 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'; |
38 | 34 |
|
39 | 35 | import { GUI } from 'three/addons/libs/lil-gui.module.min.js'; |
40 | 36 | import Stats from 'three/addons/libs/stats.module.js'; |
|
45 | 41 |
|
46 | 42 | async function init() { |
47 | 43 |
|
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 ); |
50 | 46 |
|
51 | 47 | scene = new THREE.Scene(); |
52 | | - scene.background = new THREE.Color( 0xffffff ); |
| 48 | + scene.background = new THREE.Color( 0xaaaaaa ); |
53 | 49 |
|
54 | 50 | renderer = new THREE.WebGPURenderer(); |
55 | 51 | //renderer.setPixelRatio( window.devicePixelRatio ); // probably too costly for most hardware |
56 | 52 | renderer.setSize( window.innerWidth, window.innerHeight ); |
57 | 53 | renderer.setAnimationLoop( animate ); |
58 | | - renderer.toneMapping = THREE.NeutralToneMapping; |
59 | | - renderer.toneMappingExposure = 1.5; |
| 54 | + renderer.shadowMap.enabled = true; |
60 | 55 | document.body.appendChild( renderer.domElement ); |
61 | 56 |
|
62 | 57 | stats = new Stats(); |
|
65 | 60 | // |
66 | 61 |
|
67 | 62 | controls = new OrbitControls( camera, renderer.domElement ); |
68 | | - controls.target.set( 0, 1, 0 ); |
| 63 | + controls.target.set( 0, 7, 0 ); |
69 | 64 | controls.enablePan = true; |
70 | 65 | controls.minDistance = 1; |
71 | | - controls.maxDistance = 6; |
| 66 | + controls.maxDistance = 100; |
72 | 67 | controls.update(); |
73 | 68 |
|
74 | 69 | // |
|
121 | 116 | const traaPass = traa( compositePass, scenePassDepth, scenePassVelocity, camera ); |
122 | 117 | postProcessing.outputNode = traaPass; |
123 | 118 |
|
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); |
137 | 205 |
|
138 | 206 | window.addEventListener( 'resize', onWindowResize ); |
139 | 207 |
|
|
143 | 211 | output: 0 |
144 | 212 | }; |
145 | 213 |
|
146 | | - const types = { Default: 0, AO: 1, GI: 2, Beauty: 3 }; |
| 214 | + const types = { Combined: 0, Direct: 3, AO: 1, GI: 2 }; |
147 | 215 |
|
148 | 216 | const gui = new GUI(); |
149 | 217 | gui.title( 'SSGI settings' ); |
|
0 commit comments