Commit 90c01d49 authored by amandaghassaei's avatar amandaghassaei

fixing up boundaries

parent 8d940ce3
......@@ -210,7 +210,7 @@
vec2 currentVelocity;
if (u_scale == 1.0) currentVelocity = 1.0/u_scale*texture2D(u_velocity, fragCoord/u_textureSize).xy;
else {
currentVelocity = 1.0/u_scale*bilinearInterp((fragCoord-pxCenter)*u_scale, u_velocity, u_textureSize*u_scale);
currentVelocity = 1.0/u_scale*bilinearInterp((fragCoord-pxCenter)*u_scale + 2.0*pxCenter, u_velocity, (u_textureSize-4.0*pxCenter)*u_scale);
}
//implicitly solve advection
......
......@@ -8,6 +8,7 @@ var scale = 1;
var lastMouseCoordinates = [0,0];
var mouseCoordinates = [0,0];
var mouseEnable = false;
var mouseout = false;
var paused = false;//while window is resizing
......@@ -31,9 +32,14 @@ function initGL() {
body = document.getElementsByTagName("body")[0];
canvas.onmousemove = onMouseMove;
canvas.onmousedown = onMouseDown;
canvas.onmouseup = onMouseUp;
// canvas.onmouseout = onMouseUp;
window.onmousedown = onMouseDown;
window.onmouseup = onMouseUp;
canvas.onmouseout = function (){
mouseout = true;
};
canvas.onmouseenter = function (){
mouseout = false;
};
window.onresize = onResize;
......@@ -94,17 +100,14 @@ function render(){
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<2;i++){
for (var i=0;i<3;i++){
GPU.step("jacobi", ["velocity", "velocity"], "nextVelocity");
GPU.step("jacobi", ["nextVelocity", "nextVelocity"], "velocity");
GPU.step("boundary", ["nextVelocity"], "velocity");
}
GPU.step("boundary", ["velocity"], "nextVelocity");
GPU.swapTextures("velocity", "nextVelocity");
//apply force
GPU.setProgram("force");
if (mouseEnable){
if (!mouseout && mouseEnable){
GPU.setUniformForProgram("force", "u_mouseEnable", 1.0, "1f");
GPU.setUniformForProgram("force", "u_mouseCoord", [mouseCoordinates[0]*scale, mouseCoordinates[1]*scale], "2f");
GPU.setUniformForProgram("force", "u_mouseDir", [3*(mouseCoordinates[0]-lastMouseCoordinates[0])*scale,
......@@ -117,22 +120,20 @@ function render(){
// GPU.swapTextures("velocity", "nextVelocity");
GPU.step("boundary", ["nextVelocity"], "velocity");
GPU.setProgram("boundary");
GPU.setUniformForProgram("boundary", "u_scale", 1, "1f");
// compute pressure
GPU.step("diverge", ["velocity"], "velocityDivergence");//calc velocity divergence
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++){
GPU.step("jacobi", ["velocityDivergence", "pressure"], "nextPressure");//diffuse velocity
GPU.step("jacobi", ["velocityDivergence", "nextPressure"], "pressure");//diffuse velocity
for (var i=0;i<30;i++){
GPU.step("jacobi", ["velocityDivergence", "pressure"], "nextPressure");
GPU.step("boundary", ["nextPressure"], "pressure");
}
GPU.setProgram("boundary");
GPU.setUniformForProgram("boundary", "u_scale", 1, "1f");
GPU.step("boundary", ["pressure"], "nextPressure");
// subtract pressure gradient
GPU.step("gradientSubtraction", ["velocity", "nextPressure"], "nextVelocity");
GPU.step("gradientSubtraction", ["velocity", "pressure"], "nextVelocity");
// GPU.swapTextures("velocity", "nextVelocity");
GPU.setProgram("boundary");
GPU.setUniformForProgram("boundary", "u_scale", -1, "1f");
......
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