diff --git a/index.html b/index.html index 567fe1e9cb09db47ca83a4772a89e54023a27f52..bf4df9322df09098e2cd6582f8be115cceb9eb9f 100644 --- a/index.html +++ b/index.html @@ -75,7 +75,7 @@ float w = texture2D(u_velocity, (fragCoord+vec2(-1.0, 0.0))/u_textureSize).x; float div = u_const*(e-w + n-s); - gl_FragColor = vec4(div, div, 0, 0); + gl_FragColor = vec4(div, 0, 0, 0); } </script> diff --git a/main.js b/main.js index 4a8a2e5658c9666395c03023eefaba1bc8786cee..24f3bd3e31e6d3f5425941c3c5bfa8d25ee36db6 100755 --- a/main.js +++ b/main.js @@ -75,24 +75,21 @@ function render(){ if (!paused) { - // Apply the first 3 operators in Equation 12. - // u = advect(u); - // u = diffuse(u); - // u = addForces(u); - // // Now apply the projection operator to the result. - // p = computePressure(u); - // u = subtractPressureGradient(u, p); - - GPU.step("advect", ["velocity", "velocity"], "nextVelocity");//advect velocity + //advect velocity + GPU.step("advect", ["velocity", "velocity"], "nextVelocity"); GPU.swapTextures("velocity", "nextVelocity"); + + //diffuse velocity GPU.setProgram("jacobi"); var alpha = dx*dx/(nu*dt); GPU.setUniformForProgram("jacobi", "u_alpha", alpha, "1f"); GPU.setUniformForProgram("jacobi", "u_reciprocalBeta", 1/(4+alpha), "1f"); for (var i=0;i<3;i++){ - GPU.step("jacobi", ["velocity", "velocity"], "nextVelocity");//diffuse velocity - GPU.step("jacobi", ["nextVelocity", "nextVelocity"], "velocity");//diffuse velocity + GPU.step("jacobi", ["velocity", "velocity"], "nextVelocity"); + GPU.step("jacobi", ["nextVelocity", "nextVelocity"], "velocity"); } + + //apply force GPU.setProgram("force"); if (mouseEnable){ GPU.setUniformForProgram("force", "u_mouseEnable", 1.0, "1f");