|
@@ -23,10 +23,13 @@
|
|
|
|
|
|
import * as THREE from 'three';
|
|
|
|
|
|
+ import { GUI } from './jsm/libs/dat.gui.module.js';
|
|
|
+
|
|
|
import WebGPURenderer from './jsm/renderers/webgpu/WebGPURenderer.js';
|
|
|
import WebGPU from './jsm/renderers/webgpu/WebGPU.js';
|
|
|
|
|
|
import WebGPUStorageBuffer from './jsm/renderers/webgpu/WebGPUStorageBuffer.js';
|
|
|
+ import WebGPUUniformBuffer from './jsm/renderers/webgpu/WebGPUUniformBuffer.js';
|
|
|
import WebGPUUniformsGroup from './jsm/renderers/webgpu/WebGPUUniformsGroup.js';
|
|
|
import { Vector2Uniform } from './jsm/renderers/webgpu/WebGPUUniform.js';
|
|
|
|
|
@@ -36,6 +39,8 @@
|
|
|
|
|
|
let camera, scene, renderer;
|
|
|
let pointer;
|
|
|
+ let scaleUniformBuffer;
|
|
|
+ let scaleVector = new THREE.Vector3( 1, 1, 1 );
|
|
|
|
|
|
const computeParams = [];
|
|
|
|
|
@@ -57,7 +62,7 @@
|
|
|
scene = new THREE.Scene();
|
|
|
scene.background = new THREE.Color( 0x000000 );
|
|
|
|
|
|
- const particleNum = 50000; // 16-bit limit
|
|
|
+ const particleNum = 65000; // 16-bit limit
|
|
|
const particleSize = 3;
|
|
|
|
|
|
const particleArray = new Float32Array( particleNum * particleSize );
|
|
@@ -75,15 +80,20 @@
|
|
|
const particleBuffer = new WebGPUStorageBuffer( 'particle', new THREE.BufferAttribute( particleArray, 3 ) );
|
|
|
const velocityBuffer = new WebGPUStorageBuffer( 'velocity', new THREE.BufferAttribute( velocityArray, 3 ) );
|
|
|
|
|
|
+ scaleUniformBuffer = new WebGPUUniformBuffer( 'scaleUniform', new Float32Array( 3 ) ); // single vector3
|
|
|
+
|
|
|
pointer = new THREE.Vector2( - 10.0, - 10.0 ); // Out of bounds first
|
|
|
|
|
|
const pointerGroup = new WebGPUUniformsGroup( 'mouseUniforms' ).addUniform(
|
|
|
new Vector2Uniform( 'pointer', pointer )
|
|
|
);
|
|
|
|
|
|
+ // Object keys need follow the binding shader sequence
|
|
|
+
|
|
|
const computeBindings = [
|
|
|
particleBuffer,
|
|
|
velocityBuffer,
|
|
|
+ scaleUniformBuffer,
|
|
|
pointerGroup
|
|
|
];
|
|
|
|
|
@@ -103,7 +113,11 @@
|
|
|
float velocity[ PARTICLE_NUM * PARTICLE_SIZE ];
|
|
|
} velocity;
|
|
|
|
|
|
- layout(set = 0, binding = 2) uniform MouseUniforms {
|
|
|
+ layout(set = 0, binding = 2) uniform Scale {
|
|
|
+ vec3 value;
|
|
|
+ } scaleUniform;
|
|
|
+
|
|
|
+ layout(set = 0, binding = 3) uniform MouseUniforms {
|
|
|
vec2 pointer;
|
|
|
} mouseUniforms;
|
|
|
|
|
@@ -147,9 +161,10 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- particle.particle[ index * 3 + 0 ] = position.x;
|
|
|
- particle.particle[ index * 3 + 1 ] = position.y;
|
|
|
- particle.particle[ index * 3 + 2 ] = position.z;
|
|
|
+ particle.particle[ index * 3 + 0 ] = position.x * scaleUniform.value.x;
|
|
|
+ particle.particle[ index * 3 + 1 ] = position.y * scaleUniform.value.y;
|
|
|
+ particle.particle[ index * 3 + 2 ] = position.z * scaleUniform.value.z;
|
|
|
+
|
|
|
}
|
|
|
`;
|
|
|
|
|
@@ -179,6 +194,14 @@
|
|
|
window.addEventListener( 'resize', onWindowResize );
|
|
|
window.addEventListener( 'mousemove', onMouseMove );
|
|
|
|
|
|
+ // gui
|
|
|
+
|
|
|
+ const gui = new GUI();
|
|
|
+
|
|
|
+ gui.add( scaleVector, 'x', 0.9, 1.1, 0.01 );
|
|
|
+ gui.add( scaleVector, 'y', 0.9, 1.1, 0.01 );
|
|
|
+ gui.add( scaleVector, 'z', 0.9, 1.1, 0.01 );
|
|
|
+
|
|
|
return renderer.init();
|
|
|
|
|
|
}
|
|
@@ -213,6 +236,8 @@
|
|
|
renderer.compute( computeParams );
|
|
|
renderer.render( scene, camera );
|
|
|
|
|
|
+ scaleVector.toArray( scaleUniformBuffer.buffer, 0 );
|
|
|
+
|
|
|
}
|
|
|
|
|
|
function error( error ) {
|