Skip to content

Commit 1139719

Browse files
authored
Examples: Improve performance - Compute Snow and Backdrop Water (#27404)
* less particles for better performance * cleanup * 60fps on M1
1 parent b806995 commit 1139719

4 files changed

+17
-7
lines changed
-1.76 KB
Loading
Loading

examples/webgpu_backdrop_water.html

+13-4
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@
3838

3939
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
4040

41+
import Stats from 'three/addons/libs/stats.module.js';
42+
4143
let camera, scene, renderer;
4244
let mixer, objects, clock;
4345
let model, floor, floorPosition;
46+
let stats;
4447

4548
init();
4649

@@ -150,9 +153,8 @@
150153

151154
const waterLayer0 = mx_worley_noise_float( floorUV.mul( 4 ).add( timer ) );
152155
const waterLayer1 = mx_worley_noise_float( floorUV.mul( 2 ).add( timer ) );
153-
const waterLayer2 = mx_worley_noise_float( floorUV.mul( 3 ).add( timer ) );
154156

155-
const waterIntensity = waterLayer0.mul( waterLayer1 ).mul( waterLayer2 ).mul( 5 );
157+
const waterIntensity = waterLayer0.mul( waterLayer1 ).mul( 1.4 );
156158
const waterColor = waterIntensity.mix( color( 0x0f5e9c ), color( 0x74ccf4 ) );
157159
const viewportTexture = viewportSharedTexture();
158160

@@ -179,8 +181,10 @@
179181
let transition = waterPosY.add( .1 ).saturate().oneMinus();
180182
transition = waterPosY.lessThan( 0 ).cond( transition, normalWorld.y.mix( transition, 0 ) ).toVar();
181183

182-
material.colorNode = transition.mix( material.colorNode, material.colorNode.add( waterLayer0 ) );
183-
floor.material.colorNode = material.colorNode;
184+
const colorNode = transition.mix( material.colorNode, material.colorNode.add( waterLayer0 ) );
185+
186+
//material.colorNode = colorNode;
187+
floor.material.colorNode = colorNode;
184188

185189
// renderer
186190

@@ -191,6 +195,9 @@
191195
renderer.setAnimationLoop( animate );
192196
document.body.appendChild( renderer.domElement );
193197

198+
stats = new Stats();
199+
document.body.appendChild( stats.dom );
200+
194201
const controls = new OrbitControls( camera, renderer.domElement );
195202
controls.minDistance = 1;
196203
controls.maxDistance = 10;
@@ -223,6 +230,8 @@
223230

224231
function animate() {
225232

233+
stats.update();
234+
226235
const delta = clock.getDelta();
227236

228237
floor.position.y = floorPosition.y - 5;

examples/webgpu_compute_particles_snow.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<body>
99

1010
<div id="info">
11-
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> WebGPU - GPU Compute Snow - 300.000 Particles
11+
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> WebGPU - GPU Compute Snow - 100.000 Particles
1212
</div>
1313

1414
<script type="importmap">
@@ -37,7 +37,7 @@
3737

3838
import Stats from 'three/addons/libs/stats.module.js';
3939

40-
const maxParticleCount = 300000;
40+
const maxParticleCount = 100000;
4141

4242
let camera, scene, renderer;
4343
let controls, stats;
@@ -126,7 +126,7 @@
126126
const randZ = instanceIndex.add( randUint() ).hash();
127127

128128
position.x = randX.mul( 100 ).add( - 50 );
129-
position.y = randY.mul( 1000 ).add( 3 );
129+
position.y = randY.mul( 500 ).add( 3 );
130130
position.z = randZ.mul( 100 ).add( - 50 );
131131

132132
scale.xyz = instanceIndex.add( Math.random() ).hash().mul( .8 ).add( .2 );
@@ -282,6 +282,7 @@
282282
renderer.setSize( window.innerWidth, window.innerHeight );
283283
renderer.setAnimationLoop( animate );
284284
document.body.appendChild( renderer.domElement );
285+
285286
stats = new Stats();
286287
document.body.appendChild( stats.dom );
287288

0 commit comments

Comments
 (0)