Fluid dynamics demo

289 views
Skip to first unread message

Evgeny

unread,
Aug 15, 2011, 9:04:00 AM8/15/11
to WebGL Dev List
Real time the Navier-Stokes equations simulations at
http://www.ibiblio.org/e-notes/webgl/gpu/contents.htm
available in Chrome stable and in Firefox 6 (stable in a few days :)

Evgeny

Kenneth Russell

unread,
Aug 15, 2011, 1:10:06 PM8/15/11
to webgl-d...@googlegroups.com

Very cool. Any chance of incorporating mouse interaction to stir the fluid? :)

-Ken

Stephen Bannasch

unread,
Aug 15, 2011, 2:22:03 PM8/15/11
to webgl-d...@googlegroups.com
>Real time the Navier-Stokes equations simulations at
>http://www.ibiblio.org/e-notes/webgl/gpu/contents.htm
>available in Chrome stable and in Firefox 6 (stable in a few days :)

Evgeny that's a very interesting demo!

I'd like to extend my work on Energy2D-JS (https://github.com/concord-consortium/energy2d-js) to use calculations on the GPU (right now the calculations are all in JavaScript) and your example makes it easier to understand how this can be done.

Are the result arrays for temperature and velocity stored in the textures?

Is it possible to get these data out of the WebGL context and into JavaScript?

FYI: your links to Jos Stam's work don't work properly because of the extra text in the href attributes:

<a href="Url: http://www.dgp.toronto.edu/people/stam/reality/index.html">Real-Time
Fluid Dynamics for Games</a> and
<a href="Url: http://www.dgp.toronto.edu/people/stam/reality/index.html">Stable
Fluids</a>


Jos Stam's papers on computer graphics: http://www.dgp.toronto.edu/people/stam/reality/Research/pub.html

Real-Time Fluid Dynamics for Games
http://www.dgp.toronto.edu/people/stam/reality/Research/pdf/GDC03.pdf

Stable Fluids
http://www.dgp.toronto.edu/people/stam/reality/Research/pdf/ns.pdf

----

What license are you releasing your fluid-dynamics scripts under?

I see on this page: http://www.ibiblio.org/e-notes/webgl/webgl.htm the statement:

"All scripts are free for any use."

Does this statement cover the code on this page?

http://www.ibiblio.org/e-notes/webgl/gpu/fluid.htm

Would you be willing to release your work under an existing open-source license?

MIT: http://www.opensource.org/licenses/mit-license.php
Simplified BSD: http://www.opensource.org/licenses/BSD-2-Clause

Is your work saved in a source code repository like git?

I would be interested in following your work as you make changes and improvements.

Having your scripts in a git repository would make it easy to see and understand improvements you are making.

Evgeny Demidov

unread,
Aug 16, 2011, 12:07:56 AM8/16/11
to webgl-d...@googlegroups.com
On 15.08.2011 22:22, Stephen Bannasch wrote:
>> Real time the Navier-Stokes equations simulations at
>> http://www.ibiblio.org/e-notes/webgl/gpu/contents.htm
>> available in Chrome stable and in Firefox 6 (stable in a few days :)
> Are the result arrays for temperature and velocity stored in the textures?
(ux , uy , T, p ) are stored in RGBA textures with periodic boundaries

> Is it possible to get these data out of the WebGL context and into JavaScript?
as far as I know in WebCL only yet

> FYI: your links to Jos Stam's work don't work properly
thank you. I've fixed them

> What license are you releasing your fluid-dynamics scripts under?
> Would you be willing to release your work under an existing open-source license?
>
> MIT: http://www.opensource.org/licenses/mit-license.php
> Simplified BSD: http://www.opensource.org/licenses/BSD-2-Clause
I'd prefer "public domain" (and don't like to add license text to every
file). Shall I write it explicitly in my pages?
But of cause I can add any free license (you like) to this simple
script. (And... I only "stand on giants shoulders" :)

> Is your work saved in a source code repository like git?
> I would be interested in following your work as you make changes and improvements.
> Having your scripts in a git repository would make it easy to see and understand improvements you are making.
Sorry, couldn't you make that yourself?

To Ken: I'll try to make interactive 2d ink droplet simulations.

To make an accurate (and realistic) simulation one should add:
1. control of iterations convergence
2. diffusion
3. 3D textures for 3D simulations
it is more suitable for WebCL (sorry... but we need WebGL for
visualisation :)

This script just shows that real time simulations on 512x512 grid
(without diffusion) are fast (~20fps) even on a (beginning level) E-350
netbook. So 128x128x128 (/4 due to symmetry) 3d droplet simulations are
possible too. But rather complicated in WebGl without 3D textures.

Evgeny

Gregg Tavares (wrk)

unread,
Aug 16, 2011, 4:29:14 AM8/16/11
to webgl-d...@googlegroups.com

I don't know if it will work for your needs but you can simulate 3d
textures with 2d textures.
There's a sample copied from
http://code.google.com/p/webglsamples/source/browse/color-adjust/color-adjust.html

vec4 sampleAs3DTexture(sampler2D tex, vec3 texCoord, float size) {
   float sliceSize = 1.0 / size;                         // space of 1 slice
   float slicePixelSize = sliceSize / size;              // space of 1 pixel
   float sliceInnerSize = slicePixelSize * (size - 1.0); // space of size pixels
   float zSlice0 = min(floor(texCoord.z * size), size - 1.0);
   float zSlice1 = min(zSlice0 + 1.0, size - 1.0);
   float xOffset = slicePixelSize * 0.5 + texCoord.x * sliceInnerSize;
   float s0 = xOffset + (zSlice0 * sliceSize);
   float s1 = xOffset + (zSlice1 * sliceSize);
   vec4 slice0Color = texture2D(tex, vec2(s0, texCoord.y));
   vec4 slice1Color = texture2D(tex, vec2(s1, texCoord.y));
   float zOffset = mod(texCoord.z * size, 1.0);
   return mix(slice0Color, slice1Color, zOffset);
}

Evgeny Demidov

unread,
Aug 16, 2011, 5:01:51 AM8/16/11
to webgl-d...@googlegroups.com
On 16.08.2011 12:29, Gregg Tavares (wrk) wrote:
> I don't know if it will work for your needs but you can simulate 3d
> textures with 2d textures.
> There's a sample copied from
> http://code.google.com/p/webglsamples/source/browse/color-adjust/color-adjust.html
I used 3d atlases in WebGl twice (for 3d game of life and excitable medium).
It is easy to pack ("linear") 64x64xZ or 64x128xZ textures in 8192xZ
one. But 128x128 > 8192 and one should pack data in two rows. Next you
should provide boundary conditions. All this is possible (with a big bit
of patience) but IMHO it is easier to test simulations in WebCL at first.

Evgeny Demidov

unread,
Aug 16, 2011, 5:48:00 AM8/16/11
to webgl-d...@googlegroups.com
sorry
It seems that in Chrome 15.0.849.0 dev-m "Reset" button doesn't work in
applications on the page
http://www.ibiblio.org/e-notes/webgl/gpu/contents.htm
is it my "buggy" WinXP fault? (I've got a few unreproducible features)
Reset should update initial data in two textures
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, n, n, 0,
gl.RGBA, gl.FLOAT, new Float32Array(pixels));
...
it works under Firefox 6 (3 times slower)
and Win7 + Chrome stable

Kenneth Russell

unread,
Aug 16, 2011, 6:21:33 PM8/16/11
to webgl-d...@googlegroups.com
Thanks for raising this issue. It's a recent regression; I've filed
http://code.google.com/p/chromium/issues/detail?id=93150 to track it.
Still investigating.

-Ken

Evgeny Demidov

unread,
Aug 17, 2011, 6:15:04 AM8/17/11
to webgl-d...@googlegroups.com
On 17.08.2011 2:21, Kenneth Russell wrote:
Thanks for raising this issue. It's a recent regression; I've filed
http://code.google.com/p/chromium/issues/detail?id=93150 to track it.
Still investigating.

-Ken
by the way
now VTL works fine in ANGLE with LUMINANCE_ALPHA and LUMINANCE float textures but
these textures failed in flat_wave1.html and flat_wave2.html scripts at
http://www.ibiblio.org/e-notes/webgl/test/
(flat_wave3.html with RGB textures works fine).
These scripts don't work with OpenGL drivers too (but they work in Firefox 6).
It is not very urgent.

Evgeny

Kenneth Russell

unread,
Aug 17, 2011, 3:01:26 PM8/17/11
to webgl-d...@googlegroups.com
This regression has been fixed per
http://codereview.chromium.org/7670033/ and will show up in the Canary
and Dev Channel builds soon. Thanks for pointing it out.

-Ken

Kenneth Russell

unread,
Aug 17, 2011, 3:13:53 PM8/17/11
to webgl-d...@googlegroups.com

As far as I can tell these tests are running identically in Chrome and
Firefox on Windows, as well as in Chrome on the Mac.

If there is some problem, please file a bug at http://crbug.com ,
provide clear reproduction steps, and email me the bug ID once you've
filed it. Thanks.

-Ken

Reply all
Reply to author
Forward
0 new messages