提交 96ec75e3 编写于 作者: M Mr.doob

Examples clean up.

上级 8c482dbc
...@@ -42,10 +42,6 @@ var files = { ...@@ -42,10 +42,6 @@ var files = {
"webgl_geometry_terrain_raycast", "webgl_geometry_terrain_raycast",
"webgl_geometry_text", "webgl_geometry_text",
"webgl_geometry_text_shapes", "webgl_geometry_text_shapes",
"webgl_gpgpu_birds",
"webgl_gpgpu_water",
"webgl_gpgpu_protoplanet",
"webgl_gpu_particle_system",
"webgl_hdr", "webgl_hdr",
"webgl_helpers", "webgl_helpers",
"webgl_interactive_buffergeometry", "webgl_interactive_buffergeometry",
...@@ -300,6 +296,10 @@ var files = { ...@@ -300,6 +296,10 @@ var files = {
"webgl_custom_attributes_points", "webgl_custom_attributes_points",
"webgl_custom_attributes_points2", "webgl_custom_attributes_points2",
"webgl_custom_attributes_points3", "webgl_custom_attributes_points3",
"webgl_gpgpu_birds",
"webgl_gpgpu_water",
"webgl_gpgpu_protoplanet",
"webgl_gpu_particle_system",
"webgl_materials_modified", "webgl_materials_modified",
"webgl_raymarching_reflect", "webgl_raymarching_reflect",
"webgl_shadowmap_pcss", "webgl_shadowmap_pcss",
......
...@@ -74,12 +74,14 @@ ...@@ -74,12 +74,14 @@
vec4 east = texture2D( heightmap, uv + vec2( cellSize.x, 0.0 ) ); vec4 east = texture2D( heightmap, uv + vec2( cellSize.x, 0.0 ) );
vec4 west = texture2D( heightmap, uv + vec2( - cellSize.x, 0.0 ) ); vec4 west = texture2D( heightmap, uv + vec2( - cellSize.x, 0.0 ) );
// https://web.archive.org/web/20080618181901/http://freespace.virgin.net/hugo.elias/graphics/x_water.htm
float newHeight = ( ( north.x + south.x + east.x + west.x ) * 0.5 - heightmapValue.y ) * viscosityConstant; float newHeight = ( ( north.x + south.x + east.x + west.x ) * 0.5 - heightmapValue.y ) * viscosityConstant;
// Mouse influence // Mouse influence
float mousePhase = clamp( length( ( uv - vec2( 0.5 ) ) * BOUNDS - vec2( mousePos.x, - mousePos.y ) ) * PI / mouseSize, 0.0, PI ); float mousePhase = clamp( length( ( uv - vec2( 0.5 ) ) * BOUNDS - vec2( mousePos.x, - mousePos.y ) ) * PI / mouseSize, 0.0, PI );
newHeight += ( cos( mousePhase ) + 1.0 ) * 0.28; newHeight += ( cos( mousePhase ) + 1.0 ) * 0.28;
heightmapValue.y = heightmapValue.x; heightmapValue.y = heightmapValue.x;
heightmapValue.x = newHeight; heightmapValue.x = newHeight;
...@@ -114,17 +116,17 @@ ...@@ -114,17 +116,17 @@
} }
</script> </script>
<!-- This is a 'compute shader' to read the current level and normal of water at a point --> <!-- This is a 'compute shader' to read the current level and normal of water at a point -->
<!-- It is used with a variable of size 1x1 --> <!-- It is used with a variable of size 1x1 -->
<script id="readWaterLevelFragmentShader" type="x-shader/x-fragment"> <script id="readWaterLevelFragmentShader" type="x-shader/x-fragment">
uniform vec2 point1; uniform vec2 point1;
uniform sampler2D texture; uniform sampler2D texture;
// Integer to float conversion from https://stackoverflow.com/questions/17981163/webgl-read-pixels-from-floating-point-render-target // Integer to float conversion from https://stackoverflow.com/questions/17981163/webgl-read-pixels-from-floating-point-render-target
float shift_right( float v, float amt ) { float shift_right( float v, float amt ) {
v = floor( v ) + 0.5; v = floor( v ) + 0.5;
...@@ -132,7 +134,7 @@ ...@@ -132,7 +134,7 @@
} }
float shift_left( float v, float amt ) { float shift_left( float v, float amt ) {
return floor( v * exp2( amt ) + 0.5 ); return floor( v * exp2( amt ) + 0.5 );
...@@ -181,19 +183,16 @@ ...@@ -181,19 +183,16 @@
if ( gl_FragCoord.x < 1.5 ) { if ( gl_FragCoord.x < 1.5 ) {
gl_FragColor = encode_float( waterLevel ); gl_FragColor = encode_float( waterLevel );
} } else if ( gl_FragCoord.x < 2.5 ) {
else if ( gl_FragCoord.x < 2.5 ) {
gl_FragColor = encode_float( normal.x ); gl_FragColor = encode_float( normal.x );
} } else if ( gl_FragCoord.x < 3.5 ) {
else if ( gl_FragCoord.x < 3.5 ) {
gl_FragColor = encode_float( normal.y ); gl_FragColor = encode_float( normal.y );
} } else {
else {
gl_FragColor = encode_float( 0.0 ); gl_FragColor = encode_float( 0.0 );
...@@ -314,7 +313,7 @@ ...@@ -314,7 +313,7 @@
var readWaterLevelRenderTarget; var readWaterLevelRenderTarget;
var readWaterLevelImage; var readWaterLevelImage;
var waterNormal = new THREE.Vector3(); var waterNormal = new THREE.Vector3();
var NUM_SPHERES = 5; var NUM_SPHERES = 5;
var spheres = []; var spheres = [];
var spheresEnabled = true; var spheresEnabled = true;
...@@ -424,7 +423,7 @@ ...@@ -424,7 +423,7 @@
initWater(); initWater();
createSpheres(); createSpheres();
valuesChanger(); valuesChanger();
...@@ -519,7 +518,7 @@ ...@@ -519,7 +518,7 @@
} ); } );
readWaterLevelShader.defines.WIDTH = WIDTH.toFixed( 1 ); readWaterLevelShader.defines.WIDTH = WIDTH.toFixed( 1 );
readWaterLevelShader.defines.BOUNDS = BOUNDS.toFixed( 1 ); readWaterLevelShader.defines.BOUNDS = BOUNDS.toFixed( 1 );
// Create a 4x1 pixel image and a render target (Uint8, 4 channels, 1 byte per channel) to read water height and orientation // Create a 4x1 pixel image and a render target (Uint8, 4 channels, 1 byte per channel) to read water height and orientation
readWaterLevelImage = new Uint8Array( 4 * 1 * 4 ); readWaterLevelImage = new Uint8Array( 4 * 1 * 4 );
...@@ -586,7 +585,7 @@ ...@@ -586,7 +585,7 @@
gpuCompute.doRenderTarget( smoothShader, currentRenderTarget ); gpuCompute.doRenderTarget( smoothShader, currentRenderTarget );
} }
} }
function createSpheres() { function createSpheres() {
...@@ -602,7 +601,7 @@ ...@@ -602,7 +601,7 @@
sphere.position.x = ( Math.random() - 0.5 ) * BOUNDS * 0.7; sphere.position.x = ( Math.random() - 0.5 ) * BOUNDS * 0.7;
sphere.position.z = ( Math.random() - 0.5 ) * BOUNDS * 0.7; sphere.position.z = ( Math.random() - 0.5 ) * BOUNDS * 0.7;
sphere.userData.velocity = new THREE.Vector3(); sphere.userData.velocity = new THREE.Vector3();
scene.add( sphere ); scene.add( sphere );
...@@ -623,7 +622,7 @@ ...@@ -623,7 +622,7 @@
for ( var i = 0; i < NUM_SPHERES; i++ ) { for ( var i = 0; i < NUM_SPHERES; i++ ) {
var sphere = spheres[ i ]; var sphere = spheres[ i ];
if ( sphere ) { if ( sphere ) {
// Read water level and orientation // Read water level and orientation
...@@ -633,21 +632,21 @@ ...@@ -633,21 +632,21 @@
gpuCompute.doRenderTarget( readWaterLevelShader, readWaterLevelRenderTarget ); gpuCompute.doRenderTarget( readWaterLevelShader, readWaterLevelRenderTarget );
gl.readPixels( 0, 0, 4, 1, gl.RGBA, gl.UNSIGNED_BYTE, readWaterLevelImage ); gl.readPixels( 0, 0, 4, 1, gl.RGBA, gl.UNSIGNED_BYTE, readWaterLevelImage );
var pixels = new Float32Array( readWaterLevelImage.buffer ); var pixels = new Float32Array( readWaterLevelImage.buffer );
// Get orientation // Get orientation
waterNormal.set( pixels[ 1 ], 0, - pixels[ 2 ] ); waterNormal.set( pixels[ 1 ], 0, - pixels[ 2 ] );
var pos = sphere.position; var pos = sphere.position;
// Set height // Set height
pos.y = pixels[ 0 ]; pos.y = pixels[ 0 ];
// Move sphere // Move sphere
waterNormal.multiplyScalar( 0.1 ); waterNormal.multiplyScalar( 0.1 );
sphere.userData.velocity.add( waterNormal ); sphere.userData.velocity.add( waterNormal );
sphere.userData.velocity.multiplyScalar( 0.998 ); sphere.userData.velocity.multiplyScalar( 0.998 );
pos.add( sphere.userData.velocity ); pos.add( sphere.userData.velocity );
if ( pos.x < - BOUNDS_HALF ) { if ( pos.x < - BOUNDS_HALF ) {
pos.x = - BOUNDS_HALF + 0.001; pos.x = - BOUNDS_HALF + 0.001;
sphere.userData.velocity.x *= - 0.3; sphere.userData.velocity.x *= - 0.3;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册