4 ms·
Just to clarify - the bulk of the work here is done in GLSL shaders on the GPU, not with matrices in JavaScript. All that matrix code you see in the source her
by bd 13y ago
Just to clarify - the bulk of the work here is done in GLSL shaders on the GPU, not with matrices in JavaScript.
All that matrix code you see in the source here is basically just the minimum prerequisite for doing 3D graphics, it would be the same if you just wanted to get a spinning cube with some camera control.
The real magic happens in the shaders which compute water mesh displacement, normals and shading directly on the GPU (21 simulation passes + 1 rendering pass + 1 initialization pass, using several floating point textures, seems like stateful simulation with ping-ponging, basically using graphics rendering pipeline to do GPGPU without a need for OpenCL / CUDA).
- mistercow 13y ago>basically using graphics rendering pipeline to do GPGPU without need for OpenCL / CUDA It would be really cool to see a project that would make that easier to do in JS more generally. Basically a similar idea to Parakeet or Numba, but with GLSL as a target.
- mcpherrinm 13y agoI think the closest you'll get right now is something like THREE.js that builds shaders for you out of a high level graphics API.
- mistercow 13y agoThat seems to me actually further than just writing the GLSL shaders yourself. I suppose the MVP would be a library that simply eases getting data in and out of webgl.
- exDM69 13y ago> >basically using graphics rendering pipeline to do GPGPU without need for OpenCL / CUDA > It would be really cool to see a project that would make that easier to do in JS more generally. Basically a similar idea to Parakeet or Numba, but with GLSL as a target. The problem with doing this on WebGL (which is essentially GLES2) is that the internal precision of the pipeline is not required to be a full 32 bit float. There are 10 bit integers and 20 bit floating point numbers and all sorts of funny number formats in the hardware. When most scientific/numeric computation is done in 64 bit double precision, going to less than 32 bits is a problem. Of course it still could be done in WebGL, the problem is that running it on different hardware would yield different results. If this is acceptable (e.g. image processing where bit-accurate results are not required), then why not.
- dagw 13y agoI know I have seen such a project on github once, but for the life of me I can't find it right now.
- vilya 13y agoHow about WebCL? http://www.khronos.org/webcl/ http://www.khronos.org/webcl/
- MBCook 13y ago> ust to clarify - the bulk of the work here is done in GLSL shaders on the GPU, not with matrices in JavaScript. I noticed that, which I thought was pretty cool. I was playing with it in Chrome on OS X when I realized that it wasn't doing too much to my CPU, even when I cranked the simulation up to max.
- jheriko 13y agothis is magic? isn't this precisely what the hardware was designed for? i wouldn't call this GPGPU personally - this is very much graphics. GPGPU is more about e.g. doing multi-precision integer arithmetic on the GPU - where the processors are used for something which doesn't fit the 'streaming processor being fed vectors' pattern which the architecture was made for (of which this demo is a very good example) - quite literally 'general purpose'.
- sp332 13y agoMost people wouldn't have thought of using graphics hardware to do physical simulation, especially of fluids.
- jheriko 13y agoi'm not sure where to start here... actually this is exactly what everyone thought when this hardware was new 10 years ago... and even before that we were thinking about it. look at rendering demos from that time that leveraged the shader - this was the dumbass obvious thing that almost everyone did. this is not physical simulation - not even close. the navier-stokes equations are still really quite difficult to do anything real-time with unless you make some serious compromises. i will conceded that this is very loosely based on physical reality. but actually, you can do a lot, /lot/ better with clever hacks. as an example of one of the much, much better solutions which approximate reality than this - the old school 2d 'water' effect created from feedback and a clever 3x3 convolution filter shaped as a ring with a hole in the middle, for instance is visually much more impressive and computationally simpler - and it actually is a solution to a discretised wave equation. render this old effect as greyscale into a buffer than use it as a height/displacement-map style texture - with this solution implementing real-time ripples and fluid like response to objects entering the liquid comes down to rendering the outline into that buffer and these kinds of waves simply fall out rather than requiring maintenance or trig calls...
- garethadams 13y agoCool, that sounds pretty awesome. Do you have it on a webpage I can run?