|
4 | 4 | <title>three.js webgpu - PMREM directional light test</title> |
5 | 5 | <meta charset="utf-8"> |
6 | 6 | <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> |
7 | | - <link type="text/css" rel="stylesheet" href="main.css"> |
| 7 | + <link type="text/css" rel="stylesheet" href="example.css"> |
8 | 8 | </head> |
9 | 9 | <body> |
10 | 10 |
|
11 | | - <div id="container"> |
12 | | - <div id="info"> |
13 | | - <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> webgpu - |
14 | | - PMREM test by <a href="https://github.com/elalish" target="_blank" rel="noopener">Emmett Lalish</a> |
15 | | - <br> |
16 | | - <br>1: white metal. 2: white dielectric. 3: black dielectric. |
| 11 | + <div id="info"> |
| 12 | + <a href="https://threejs.org/" target="_blank" rel="noopener" class="logo-link"></a> |
| 13 | + |
| 14 | + <div class="title-wrapper"> |
| 15 | + <a href="https://threejs.org/" target="_blank" rel="noopener">three.js</a><span>PMREM Directional Light Test</span> |
| 16 | + </div> |
| 17 | + |
| 18 | + <small> |
| 19 | + 1: white metal. 2: white dielectric. 3: black dielectric. |
17 | 20 | <br>PMREM on: HDR with a single bright pixel. PMREM off: DirectionalLight. |
18 | 21 | <br>The difference between these renders indicates the error in the PMREM approximations. |
19 | | - </div> |
| 22 | + <br>PMREM test by <a href="https://github.com/elalish" target="_blank" rel="noopener">Emmett Lalish</a> |
| 23 | + </small> |
20 | 24 | </div> |
21 | 25 |
|
22 | 26 | <script type="importmap"> |
23 | 27 | { |
24 | 28 | "imports": { |
25 | 29 | "three": "../build/three.webgpu.js", |
26 | | - "three/tsl": "../build/three.webgpu.js", |
| 30 | + "three/webgpu": "../build/three.webgpu.js", |
| 31 | + "three/tsl": "../build/three.tsl.js", |
27 | 32 | "three/addons/": "./jsm/" |
28 | 33 | } |
29 | 34 | } |
|
36 | 41 | import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; |
37 | 42 | import { HDRLoader } from 'three/addons/loaders/HDRLoader.js'; |
38 | 43 |
|
39 | | - import { GUI } from 'three/addons/libs/lil-gui.module.min.js'; |
40 | | - |
41 | | - import WebGPU from 'three/addons/capabilities/WebGPU.js'; |
| 44 | + import { Inspector } from 'three/addons/inspector/Inspector.js'; |
42 | 45 |
|
43 | 46 | let scene, camera, controls, renderer; |
44 | 47 |
|
|
53 | 56 | renderer = new THREE.WebGPURenderer( { antialias: true } ); |
54 | 57 | renderer.setPixelRatio( window.devicePixelRatio ); |
55 | 58 | renderer.setSize( width, height ); |
| 59 | + renderer.setAnimationLoop( render ); |
| 60 | + renderer.inspector = new Inspector(); |
56 | 61 |
|
57 | 62 | // tonemapping |
58 | 63 | renderer.toneMapping = THREE.ACESFilmicToneMapping; |
59 | 64 | renderer.toneMappingExposure = 1; |
60 | 65 |
|
61 | | - await renderer.init(); |
62 | | - |
63 | 66 | document.body.appendChild( renderer.domElement ); |
64 | 67 |
|
65 | 68 | window.addEventListener( 'resize', onWindowResize ); |
66 | 69 |
|
| 70 | + await renderer.init(); |
| 71 | + |
67 | 72 | // scene |
68 | 73 |
|
69 | 74 | scene = new THREE.Scene(); |
|
77 | 82 | // controls |
78 | 83 |
|
79 | 84 | controls = new OrbitControls( camera, renderer.domElement ); |
80 | | - controls.addEventListener( 'change', render ); // use if there is no animation loop |
81 | 85 | controls.minDistance = 4; |
82 | 86 | controls.maxDistance = 20; |
83 | 87 |
|
|
99 | 103 | // angle of the pixel in steradians. This image is 1024 x 512, |
100 | 104 | // so the value is 1 / ( sin( phi ) * ( pi / 512 ) ^ 2 ) = 27,490 nits. |
101 | 105 |
|
102 | | - const gui = new GUI(); |
| 106 | + const gui = renderer.inspector.createParameters( 'Settings' ); |
103 | 107 | gui.add( { enabled: true }, 'enabled' ) |
104 | 108 | .name( 'PMREM' ) |
105 | 109 | .onChange( value => { |
|
116 | 120 |
|
117 | 121 | } ); |
118 | 122 |
|
119 | | - render(); |
120 | | - |
121 | 123 | } ); |
122 | 124 |
|
123 | 125 | } |
124 | 126 |
|
125 | | - async function createObjects() { |
| 127 | + function createObjects() { |
126 | 128 |
|
127 | 129 | let radianceMap = null; |
128 | 130 | new HDRLoader() |
|
141 | 143 |
|
142 | 144 | for ( let y = 0; y <= 2; y ++ ) { |
143 | 145 |
|
144 | | - const material = new THREE.MeshPhysicalNodeMaterial( { |
| 146 | + const material = new THREE.MeshPhysicalMaterial( { |
145 | 147 | roughness: x / 10, |
146 | 148 | metalness: y < 1 ? 1 : 0, |
147 | 149 | color: y < 2 ? 0xffffff : 0x000000, |
|
158 | 160 |
|
159 | 161 | } |
160 | 162 |
|
161 | | - render(); |
162 | | - |
163 | 163 | } ); |
164 | 164 |
|
165 | 165 | const pmremGenerator = new THREE.PMREMGenerator( renderer ); |
|
177 | 177 |
|
178 | 178 | renderer.setSize( width, height ); |
179 | 179 |
|
180 | | - render(); |
181 | | - |
182 | 180 | } |
183 | 181 |
|
184 | 182 | function updateCamera() { |
|
198 | 196 |
|
199 | 197 | Promise.resolve() |
200 | 198 | .then( init ) |
201 | | - .then( createObjects ) |
202 | | - .then( render ); |
| 199 | + .then( createObjects ); |
203 | 200 |
|
204 | 201 | </script> |
205 | 202 | </body> |
|
0 commit comments