|
46 | 46 |
|
47 | 47 | async function init() { |
48 | 48 | scene = new THREE.Scene(); |
49 | | - scene.background = new THREE.Color("#333333"); |
| 49 | + scene.background = new THREE.Color( 0xffffff ); |
50 | 50 |
|
51 | 51 |
|
52 | 52 | camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); |
53 | | - camera.position.set(0, 0, -6); |
| 53 | + camera.position.set(-0.1, 5, 0.548); |
54 | 54 |
|
55 | 55 | renderer = new THREE.WebGPURenderer({ antialias: true }); |
56 | 56 | renderer.setPixelRatio(1.0); // important for performance |
57 | 57 | renderer.setSize(window.innerWidth, window.innerHeight); |
58 | 58 | renderer.toneMapping = THREE.NeutralToneMapping; |
59 | | - renderer.toneMappingExposure = 1.0; |
| 59 | + renderer.toneMappingExposure = 0.6; |
60 | 60 | renderer.setAnimationLoop(render); |
61 | 61 | document.body.appendChild(renderer.domElement); |
62 | 62 |
|
63 | 63 | canvas = document.querySelector("canvas"); |
64 | 64 | controls = new OrbitControls(camera, canvas); |
65 | | - controls.target.set(0, 0, 0); |
| 65 | + controls.target.set(0, 0, 0.548); |
66 | 66 |
|
67 | 67 | stats = new Stats(); |
68 | 68 | document.body.appendChild(stats.dom); |
69 | 69 |
|
70 | 70 | font = await new FontLoader().loadAsync("./fonts/helvetiker_regular.typeface.json"); |
71 | 71 |
|
72 | | - const text_mat = new THREE.MeshStandardMaterial(); |
73 | | - text_mat.colorNode = TSL.color("#fdfdfd"); |
74 | | - |
75 | 72 | base = new THREE.Group(); |
76 | | - base.rotation.set(0, -Math.PI/2, 0); |
| 73 | + base.rotation.set(0, 0, -Math.PI/2); |
| 74 | + base.position.set(0, 0, 0.548); |
77 | 75 | scene.add(base); |
78 | 76 |
|
| 77 | + const text_mat = new THREE.MeshStandardMaterial(); |
| 78 | + text_mat.colorNode = TSL.color("#000000"); |
| 79 | + |
79 | 80 |
|
80 | | - |
81 | 81 | for (let y = 0; y < Finishes.length; y++) { |
82 | 82 | const txt_geo = new TextGeometry(Finishes[y], { |
83 | 83 | font: font, |
|
100 | 100 | } |
101 | 101 |
|
102 | 102 |
|
103 | | - new HDRLoader().load("./textures/equirectangular/royal_esplanade_1k.hdr", async (env_map) => |
104 | | - { |
105 | | - env_map.mapping = THREE.EquirectangularReflectionMapping; |
106 | | - |
107 | | - scene.background = env_map; |
108 | | - scene.environment = env_map; |
109 | | - scene.environmentIntensity = 6; |
110 | | - |
111 | | - for (let x = 0; x < WoodGenuses.length; x++) |
112 | | - { |
113 | | - await add_wood(x, text_mat); |
114 | | - } |
| 103 | + const material = new THREE.MeshBasicNodeMaterial(); |
| 104 | + |
| 105 | + const gridXZ = TSL.Fn( ( [ gridSize = float( 1.0 ), dotWidth = float( 0.1 ), lineWidth = float( 0.02 ) ] ) => { |
| 106 | + |
| 107 | + const coord = TSL.positionWorld.xz.div( gridSize ); |
| 108 | + const grid = TSL.fract( coord ); |
| 109 | + |
| 110 | + // Screen-space derivative for automatic antialiasing |
| 111 | + const fw = TSL.fwidth( coord ); |
| 112 | + const smoothing = TSL.max( fw.x, fw.y ).mul( 0.5 ); |
| 113 | + |
| 114 | + // Create squares at cell centers |
| 115 | + const squareDist = TSL.max( TSL.abs( grid.x.sub( 0.5 ) ), TSL.abs( grid.y.sub( 0.5 ) ) ); |
| 116 | + const dots = TSL.smoothstep( dotWidth.add( smoothing ), dotWidth.sub( smoothing ), squareDist ); |
| 117 | + |
| 118 | + // Create grid lines |
| 119 | + const lineX = TSL.smoothstep( lineWidth.add( smoothing ), lineWidth.sub( smoothing ), TSL.abs( grid.x.sub( 0.5 ) ) ); |
| 120 | + const lineZ = TSL.smoothstep( lineWidth.add( smoothing ), lineWidth.sub( smoothing ), TSL.abs( grid.y.sub( 0.5 ) ) ); |
| 121 | + const lines = TSL.max( lineX, lineZ ); |
| 122 | + |
| 123 | + return TSL.max( dots, lines ); |
| 124 | + |
| 125 | + } ); |
| 126 | + |
| 127 | + const radialGradient = TSL.Fn( ( [ radius = float( 10.0 ), falloff = float( 1.0 ) ] ) => { |
| 128 | + |
| 129 | + return TSL.smoothstep( radius, radius.sub( falloff ), TSL.length( TSL.positionWorld ) ); |
| 130 | + |
| 131 | + } ); |
| 132 | + |
| 133 | + // Create grid pattern |
| 134 | + const gridPattern = gridXZ( 1.0, 0.03, 0.005 ); |
| 135 | + const baseColor = TSL.vec4( 1.0, 1.0, 1.0, 0.0 ); |
| 136 | + const gridColor = TSL.vec4( 0.5, 0.5, 0.5, 1.0 ); |
| 137 | + |
| 138 | + // Mix base color with grid lines |
| 139 | + material.colorNode = gridPattern.mix( baseColor, gridColor ).mul( radialGradient( 30.0, 20.0 ) ); |
| 140 | + material.transparent = true; |
| 141 | + |
| 142 | + const plane = new THREE.Mesh( new THREE.CircleGeometry( 40 ), material ); |
| 143 | + plane.rotation.x = - Math.PI / 2; |
| 144 | + plane.renderOrder = - 1; |
| 145 | + scene.add( plane ); |
| 146 | + |
| 147 | + new HDRLoader() |
| 148 | + .setPath( 'textures/equirectangular/' ) |
| 149 | + .load( 'san_giuseppe_bridge_2k.hdr', async ( texture ) => { |
| 150 | + |
| 151 | + texture.mapping = THREE.EquirectangularReflectionMapping; |
| 152 | + |
| 153 | + scene.environment = texture; |
| 154 | + scene.environmentIntensity = 2; |
115 | 155 | }); |
116 | 156 |
|
117 | | - |
| 157 | + for (let x = 0; x < WoodGenuses.length; x++) { |
| 158 | + for (let y = 0; y < Finishes.length; y++) { |
| 159 | + const cube = add_wood(x, y, text_mat); |
| 160 | + base.add(cube); |
| 161 | + await new Promise(resolve => setTimeout(resolve, 0)); |
| 162 | + } |
118 | 163 | } |
| 164 | + } |
119 | 165 |
|
120 | 166 | function render() { |
121 | 167 | controls.update(); |
|
138 | 184 | document.body.innerHTML = '<div id="info">WebGPU is not supported in this browser.</div>'; |
139 | 185 | } |
140 | 186 |
|
141 | | - async function add_wood(x, text_mat) |
| 187 | + function add_wood(x, y, text_mat) |
142 | 188 | { |
143 | 189 | const txt_geo = new TextGeometry(WoodGenuses[x], |
144 | 190 | { |
|
156 | 202 | txt_geo.translate(offx, offy, offz); |
157 | 203 |
|
158 | 204 | const txt = new THREE.Mesh(txt_geo, text_mat); |
159 | | - txt.position.set(0, Finishes.length/2 - 0.25, x - WoodGenuses.length/2 + 0.45); |
| 205 | + txt.position.set(0, Finishes.length/2, x - WoodGenuses.length/2 + 0.45); |
160 | 206 | txt.rotateY(-Math.PI/2); |
161 | 207 | base.add(txt); |
162 | 208 |
|
163 | | - for (let y = 0; y < Finishes.length; y++) |
| 209 | + const geometry = new RoundedBoxGeometry(0.125, 0.9, 0.9, 10, 0.02); |
| 210 | + const position = |
164 | 211 | { |
165 | | - const geometry = new RoundedBoxGeometry(0.125, 0.9, 0.9, 10, 0.02); |
166 | | - const position = |
167 | | - { |
168 | | - x: 0, |
169 | | - y: y - Finishes.length/2, |
170 | | - z: x - WoodGenuses.length/2 + 0.45 |
171 | | - }; |
172 | | - |
173 | | - const cube = new THREE.Mesh(geometry, GenerateWoodMaterial(GetWoodPreset(WoodGenuses[x], Finishes[y]))); |
174 | | - cube.position.set(position.x, position.y, position.z); |
175 | | - base.add(cube); |
176 | | - |
177 | | - } |
178 | | - |
179 | | - await new Promise(resolve => setTimeout(resolve, 10)); |
| 212 | + x: 0, |
| 213 | + y: y - Finishes.length/2, |
| 214 | + z: x - WoodGenuses.length/2 + 0.45 |
| 215 | + }; |
180 | 216 |
|
| 217 | + const cube = new THREE.Mesh(geometry, GenerateWoodMaterial(GetWoodPreset(WoodGenuses[x], Finishes[y]))); |
| 218 | + cube.position.set(position.x, position.y, position.z); |
| 219 | + |
| 220 | + return cube; |
181 | 221 | } |
182 | 222 | </script> |
183 | 223 | </body> |
|
0 commit comments