Commit 6665bfce authored by amandaghassaei's avatar amandaghassaei

boundary cond

parent 9cc33b08
......@@ -27,11 +27,17 @@
void main() {
vec2 fragCoord = gl_FragCoord.xy;
vec4 neighborVal;
if (fragCoord.x < 1.0){
neighborVal = texture2D(u_texture, (fragCoord + vec2(1.0, 0.0))/u_textureSize);
gl_FragColor = u_scale*neighborVal;
gl_FragColor = u_scale*texture2D(u_texture, (fragCoord + vec2(1.0, 0.0))/u_textureSize);
return;
} else if (fragCoord.x >= u_textureSize.x-1.0){
gl_FragColor = u_scale*texture2D(u_texture, (fragCoord + vec2(-1.0, 0.0))/u_textureSize);
return;
} else if (fragCoord.y < 1.0){
gl_FragColor = u_scale*texture2D(u_texture, (fragCoord + vec2(0.0, 1.0))/u_textureSize);
return;
} else if (fragCoord.y >= u_textureSize.y-1.0){
gl_FragColor = u_scale*texture2D(u_texture, (fragCoord + vec2(0.0, -1.0))/u_textureSize);
return;
}
......@@ -216,7 +222,7 @@
vec2 materialVal;
//empty boundary
if (pos.x < 0.0 || pos.x >= u_textureSize.x-1.0 || pos.y < 0.0 || pos.y >= u_textureSize.y-1.0) materialVal = vec2(0.0);
if (pos.x < 0.0 || pos.x >= u_textureSize.x || pos.y < 0.0 || pos.y >= u_textureSize.y) materialVal = vec2(0.0);
else materialVal = bilinearInterp(pos, u_material, u_textureSize);
gl_FragColor = vec4(materialVal, 0, 0);
......
......@@ -122,8 +122,8 @@ function initBoilerPlate(){
function loadVertexData(gl, program) {
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
var val = 0.9;
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ -val,-val, val,-val, -val, val, val, val, val, val, val, -val, -val, val, -val, -val]), gl.STATIC_DRAW);
var val = 1.0;
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ -val,-val, val,-val, -val, val, val, val]), gl.STATIC_DRAW);
// look up where the vertex data needs to go.
var positionLocation = gl.getAttribLocation(program, "a_position");
......
......@@ -84,9 +84,10 @@ function render(){
GPU.setUniformForProgram("advect" ,"u_scale", 1, "1f");
GPU.step("advect", ["velocity", "velocity"], "nextVelocity");
// GPU.setProgram("boundary");
// GPU.setUniformForProgram("boundary", "u_scale", -1, "1f");
// GPU.stepBoundary("boundary", ["nextVelocity"], "velocity");
GPU.setProgram("boundary");
GPU.setUniformForProgram("boundary", "u_scale", -1, "1f");
GPU.step("boundary", ["nextVelocity"], "velocity");
// GPU.swapTextures("velocity", "nextVelocity");
//diffuse velocity
GPU.setProgram("jacobi");
......@@ -98,6 +99,9 @@ function render(){
GPU.step("jacobi", ["nextVelocity", "nextVelocity"], "velocity");
}
GPU.step("boundary", ["velocity"], "nextVelocity");
GPU.swapTextures("velocity", "nextVelocity");
//apply force
GPU.setProgram("force");
if (mouseEnable){
......@@ -109,7 +113,9 @@ function render(){
GPU.setUniformForProgram("force", "u_mouseEnable", 0.0, "1f");
}
GPU.step("force", ["velocity"], "nextVelocity");
GPU.swapTextures("velocity", "nextVelocity");
// GPU.swapTextures("velocity", "nextVelocity");
GPU.step("boundary", ["nextVelocity"], "velocity");
// compute pressure
GPU.step("diverge", ["velocity"], "velocityDivergence");//calc velocity divergence
......@@ -121,9 +127,16 @@ function render(){
GPU.step("jacobi", ["velocityDivergence", "nextPressure"], "pressure");//diffuse velocity
}
GPU.setProgram("boundary");
GPU.setUniformForProgram("boundary", "u_scale", 1, "1f");
GPU.step("boundary", ["pressure"], "nextPressure");
// subtract pressure gradient
GPU.step("gradientSubtraction", ["velocity", "pressure"], "nextVelocity");
GPU.swapTextures("velocity", "nextVelocity");
GPU.step("gradientSubtraction", ["velocity", "nextPressure"], "nextVelocity");
// GPU.swapTextures("velocity", "nextVelocity");
GPU.setProgram("boundary");
GPU.setUniformForProgram("boundary", "u_scale", -1, "1f");
GPU.step("boundary", ["nextVelocity"], "velocity");
// move material
GPU.setSize(actualWidth, actualHeight);
......@@ -150,11 +163,13 @@ function resetWindow(){
var maxDim = Math.max(actualHeight, actualWidth);
var _scale = maxDim/150;
if (_scale < 1) _scale = 1;
width = Math.floor(actualWidth/_scale);
height = Math.floor(actualHeight/_scale);
scale = (width/actualWidth + height/actualHeight)/2;
console.log(scale);
canvas.width = actualWidth;
canvas.height = actualHeight;
......@@ -168,7 +183,7 @@ function resetWindow(){
GPU.setProgram("diverge");
GPU.setUniformForProgram("diverge" ,"u_textureSize", [width, height], "2f");
GPU.setProgram("force");
GPU.setUniformForProgram("force", "u_reciprocalRadius", 0.1/scale, "1f");
GPU.setUniformForProgram("force", "u_reciprocalRadius", 0.03/scale, "1f");
GPU.setUniformForProgram("force" ,"u_textureSize", [width, height], "2f");
GPU.setProgram("jacobi");
GPU.setUniformForProgram("jacobi" ,"u_textureSize", [width, height], "2f");
......
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