Commit da4bf7a1 authored by amandaghassaei's avatar amandaghassaei

langrangian particles acan't leave boundary

parent 49ccc8b4
......@@ -300,6 +300,7 @@
uniform sampler2D u_velocity;
uniform vec2 u_textureSize;
uniform vec2 u_screenSize;
uniform vec2 u_velocityTextureSize;
uniform float u_dt;
......@@ -335,9 +336,14 @@
vec2 particleCoord = texture2D(u_particles, fragCoord/u_textureSize).xy;
vec2 currentVelocity = 1.0/u_scale*bilinearInterp(vec2(1.0, 1.0) + particleCoord*u_scale/u_velocityTextureSize*(u_velocityTextureSize-vec2(3.0, 3.0)), u_velocity, u_velocityTextureSize);
vec2 nextPosition = particleCoord+currentVelocity*u_dt;//explicitly solve advection
//explicitly solve advection
gl_FragColor = vec4(particleCoord+currentVelocity*u_dt, 0, 0);
if (nextPosition.x < 0.0) nextPosition.x = 0.0;
else if (nextPosition.x >= u_screenSize.x-3.0) nextPosition.x = u_screenSize.x-3.0;
if (nextPosition.y < 0.0) nextPosition.y = 0.0;
else if (nextPosition.y >= u_screenSize.y-3.0) nextPosition.y = u_screenSize.y-3.0;
gl_FragColor = vec4(nextPosition, 0, 0);
}
</script>
......
......@@ -176,7 +176,7 @@ function render(){
GPU.setProgram("jacobi");
GPU.setUniformForProgram("jacobi", "u_alpha", -dx*dx, "1f");
GPU.setUniformForProgram("jacobi", "u_reciprocalBeta", 1/4, "1f");
for (var i=0;i<20;i++){
for (var i=0;i<10;i++){
GPU.step("jacobi", ["velocityDivergence", "pressure"], "nextPressure");
GPU.step("jacobi", ["velocityDivergence", "nextPressure"], "pressure");
}
......@@ -245,8 +245,8 @@ function onResize(){
function resetWindow(){
actualWidth = body.clientWidth;
actualHeight = body.clientHeight;
actualWidth = Math.round(body.clientWidth);
actualHeight = Math.round(body.clientHeight);
var maxDim = Math.max(actualHeight, actualWidth);
var _scale = Math.ceil(maxDim/150);
......@@ -282,6 +282,7 @@ function resetWindow(){
GPU.setUniformForProgram("boundary" ,"u_textureSize", [width, height], "2f");
GPU.setProgram("moveParticles");
GPU.setUniformForProgram("moveParticles", "u_velocityTextureSize", [width, height], "2f");
GPU.setUniformForProgram("moveParticles", "u_screenSize", [actualWidth, actualHeight], "2f");
GPU.setUniformForProgram("moveParticles" ,"u_scale", scale, "1f");
var velocity = new Float32Array(width*height*4);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment