Commit 442b4dfd authored by amandaghassaei's avatar amandaghassaei

mouse position

parent b2fcb56f
......@@ -342,12 +342,12 @@
<div class="modal-content">
<div class="modal-body">
<b>Vortex Shedding Fluid Simulation</b><br/><br/>
This simulation solves the <a href="https://en.wikipedia.org/wiki/Navier%E2%80%93Stokes_equations" target="_blank">Navier-Stokes equations</a> for incompressible fluid flow past an obstacle.
At each step of the simulation, a discrete form of Navier-Stokes is solved in a GPU fragment shader.
This system exhibits a phenomenon called <a href="https://en.wikipedia.org/wiki/Vortex_shedding" target="_blank">vortex shedding</a>,
where vortices of alternating directions spontaneously emerge behind the obstacle.
To increase performance, I solved for the velocity of the fluid at a lower resolution than the position of material moving in the fluid (shown in black and white).
This simulation solves the <a href="https://en.wikipedia.org/wiki/Navier%E2%80%93Stokes_equations" target="_blank">Navier-Stokes equations</a> for incompressible fluid flow past an obstacle in a GPU fragment shader.
It exhibits a phenomenon called <a href="https://en.wikipedia.org/wiki/Vortex_shedding" target="_blank">vortex shedding</a>,
where vortices of alternating spin spontaneously emerge behind the obstacle.
To increase performance, I solved for the velocity vector field of the fluid at a lower resolution than I used to compute the distribution of material moving through the fluid (shown in black and white).
I used bilinear interpolation to smooth out any resulting artifacts from this speedup.
I ignored the viscous diffusion term from the Navier-Stokes formula to encourage better vortex formation (the implicit advection solving I'm using creates enough diffusion on its own for this system).
<br/><br/>
Click and drag to apply a force to the fluid.
<br/><br/>
......
......@@ -107,7 +107,7 @@ function render(){
GPU.setProgram("force");
if (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_mouseCoord", [mouseCoordinates[0]*width/actualWidth, mouseCoordinates[1]*height/actualHeight], "2f");
GPU.setUniformForProgram("force", "u_mouseDir", [2*(mouseCoordinates[0]-lastMouseCoordinates[0])/scale,
2*(mouseCoordinates[1]-lastMouseCoordinates[1])/scale], "2f");
} else {
......@@ -159,7 +159,7 @@ function resetWindow(){
actualHeight = body.clientHeight;
var maxDim = Math.max(actualHeight, actualWidth);
var scale = maxDim/300;
var scale = maxDim/200;
width = Math.floor(actualWidth/scale);
height = Math.floor(actualHeight/scale);
......@@ -192,8 +192,8 @@ function resetWindow(){
GPU.setUniformForProgram("render" ,"u_textureSize", [actualWidth, actualHeight], "2f");
GPU.setProgram("boundary");
GPU.setUniformForProgram("boundary" ,"u_textureSize", [width, height], "2f");
GPU.setUniformForProgram("boundary" ,"u_obstaclePosition", [obstaclePosition[0]/scale, obstaclePosition[1]/scale], "2f");
GPU.setUniformForProgram("boundary" ,"u_obstacleRad", obstacleRad/scale, "1f");
GPU.setUniformForProgram("boundary" ,"u_obstaclePosition", [obstaclePosition[0]*width/actualWidth, obstaclePosition[1]*height/actualHeight, "2f");
GPU.setUniformForProgram("boundary" ,"u_obstacleRad", obstacleRad*width/actualWidth, "1f");
var velocity = new Float32Array(width*height*4);
for (var i=0;i<height;i++){
......
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