提交 9d2cad3b 编写于 作者: A aardgoose

rename uniform texture

上级 0d760ea8
......@@ -62,7 +62,7 @@
<!-- This is just a smoothing 'compute shader' for using manually: -->
<script id="smoothFragmentShader" type="x-shader/x-fragment">
uniform sampler2D texture;
uniform sampler2D smoothTexture;
void main() {
......@@ -71,11 +71,11 @@
vec2 uv = gl_FragCoord.xy * cellSize;
// Computes the mean of texel and 4 neighbours
vec4 textureValue = texture2D( texture, uv );
textureValue += texture2D( texture, uv + vec2( 0.0, cellSize.y ) );
textureValue += texture2D( texture, uv + vec2( 0.0, - cellSize.y ) );
textureValue += texture2D( texture, uv + vec2( cellSize.x, 0.0 ) );
textureValue += texture2D( texture, uv + vec2( - cellSize.x, 0.0 ) );
vec4 textureValue = texture2D( smoothTexture, uv );
textureValue += texture2D( smoothTexture, uv + vec2( 0.0, cellSize.y ) );
textureValue += texture2D( smoothTexture, uv + vec2( 0.0, - cellSize.y ) );
textureValue += texture2D( smoothTexture, uv + vec2( cellSize.x, 0.0 ) );
textureValue += texture2D( smoothTexture, uv + vec2( - cellSize.x, 0.0 ) );
textureValue /= 5.0;
......@@ -91,7 +91,7 @@
uniform vec2 point1;
uniform sampler2D texture;
uniform sampler2D levelTexture;
// Integer to float conversion from https://stackoverflow.com/questions/17981163/webgl-read-pixels-from-floating-point-render-target
......@@ -142,11 +142,11 @@
vec2 cellSize = 1.0 / resolution.xy;
float waterLevel = texture2D( texture, point1 ).x;
float waterLevel = texture2D( levelTexture, point1 ).x;
vec2 normal = vec2(
( texture2D( texture, point1 + vec2( - cellSize.x, 0 ) ).x - texture2D( texture, point1 + vec2( cellSize.x, 0 ) ).x ) * WIDTH / BOUNDS,
( texture2D( texture, point1 + vec2( 0, - cellSize.y ) ).x - texture2D( texture, point1 + vec2( 0, cellSize.y ) ).x ) * WIDTH / BOUNDS );
( texture2D( levelTexture, point1 + vec2( - cellSize.x, 0 ) ).x - texture2D( levelTexture, point1 + vec2( cellSize.x, 0 ) ).x ) * WIDTH / BOUNDS,
( texture2D( levelTexture, point1 + vec2( 0, - cellSize.y ) ).x - texture2D( levelTexture, point1 + vec2( 0, cellSize.y ) ).x ) * WIDTH / BOUNDS );
if ( gl_FragCoord.x < 1.5 ) {
......@@ -486,12 +486,12 @@
}
// Create compute shader to smooth the water surface and velocity
smoothShader = gpuCompute.createShaderMaterial( document.getElementById( 'smoothFragmentShader' ).textContent, { texture: { value: null } } );
smoothShader = gpuCompute.createShaderMaterial( document.getElementById( 'smoothFragmentShader' ).textContent, { smoothTexture: { value: null } } );
// Create compute shader to read water level
readWaterLevelShader = gpuCompute.createShaderMaterial( document.getElementById( 'readWaterLevelFragmentShader' ).textContent, {
point1: { value: new Vector2() },
texture: { value: null }
levelTexture: { value: null }
} );
readWaterLevelShader.defines.WIDTH = WIDTH.toFixed( 1 );
readWaterLevelShader.defines.BOUNDS = BOUNDS.toFixed( 1 );
......@@ -562,10 +562,10 @@
for ( var i = 0; i < 10; i ++ ) {
smoothShader.uniforms[ "texture" ].value = currentRenderTarget.texture;
smoothShader.uniforms[ "smoothTexture" ].value = currentRenderTarget.texture;
gpuCompute.doRenderTarget( smoothShader, alternateRenderTarget );
smoothShader.uniforms[ "texture" ].value = alternateRenderTarget.texture;
smoothShader.uniforms[ "smoothTexture" ].value = alternateRenderTarget.texture;
gpuCompute.doRenderTarget( smoothShader, currentRenderTarget );
}
......@@ -602,7 +602,7 @@
var currentRenderTarget = gpuCompute.getCurrentRenderTarget( heightmapVariable );
readWaterLevelShader.uniforms[ "texture" ].value = currentRenderTarget.texture;
readWaterLevelShader.uniforms[ "levelTexture" ].value = currentRenderTarget.texture;
for ( var i = 0; i < NUM_SPHERES; i ++ ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册