Live data from Hacker News

Web GL Ocean Simulation

david.li

111–120 of 138 posts

Re: Web GL Ocean Simulation

#111
post #75
post #73

Earlier quoted context omitted.

this 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…

Most people wouldn't have thought of using graphics hardware to do physical simulation, especially of fluids.

simulation of fluids is huge in computer graphics and the GPU is completely necessary for anything close to real time. Physics engines are built to process on the GPU.

I was at one point perusing a PhD in Computer Graphics and I studied many papers ranging from haptic devices w/ liquid simulations (great paper on making pancakes which change properties as they cook [1]) to research from our lab on volume rendered simulations to prevent temperature shock in introducing cool water (relatively) to prevent a meltdown of a nuclear power plant.

[1]http://www.gmrv.es/Publications/2013/CMOL13/haptic_multistat...)

Re: Web GL Ocean Simulation

#112
post #107
post #75

Earlier quoted context omitted.

Most people wouldn't have thought of using graphics hardware to do physical simulation, especially of fluids.

1999 navier stokes solver on GPU: http://www.cs.unm.edu/~mskarim/fluid_smoke_gpu.htm I was doing this in college 10 years ago. Cmon now.

It won't impress anyone on the internet until you port it to WebGL.

Re: Web GL Ocean Simulation

#113

Reminds me of this shader toy shader. https://www.shadertoy.com/view/XdsGDB

Yeah, love that one too. Insanely great. But it's raytracing the sphere and raymarching the water distance-fields per fragment, right? Not gonna fly realtime any longer (or at all) if you ever wanted to use it with additional polygonal art. ;)

Re: Web GL Ocean Simulation

#114

> Your browser does not appear to support the required technologies. It would've been nice to have an 'I don't care, proceed anyway' button. The check excludes Safari 7, which runs the demo just as well as Chrome. http://jsfiddle.net/bYHfh ^ removes the hasWebGLSupport() invocation. Very nice demo, though!

[deleted]

Re: Web GL Ocean Simulation

#115
post #35

Earlier quoted context omitted.

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 directl…

>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.

> >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.

Re: Web GL Ocean Simulation

#116

The code is quite cool to look at. Love seeing the extensive use of matrices and mathematics to create such a beautiful and mesmerizing display. If anyone is interested in playing around with it, I threw it up at JSFiddle here: http://jsfiddle.net/zyAzg/ Excellent demo.

I wonder if it was all handwritten. Esp. functions like invertMatrix or premultiplyMatrix. Or what he used to generate the code. I once used WolframAlpha to get me some complicated formulas and wrote a custom WA-plaintext-output-to-C translator for that output to use it in my code. Here is the script: https://github.com/albertz/helpers/blob/master/wolframalpha_... Example input: http://www.wolframalpha.com/input/?i=s…

> I wonder if it was all handwritten. Esp. functions like invertMatrix or premultiplyMatrix. Or what he used to generate the code.

Yes, it probably is hand written. Or more likely, copied from some well known resource such as MESA.

Computer graphics deals extensively with 4x4 matrices, so there are hand written implementations of elementary operations such as matrix inverse, all unrolled and precomputed so that there's no loops or anything. (NOTE: this isn't really basic loop unrolling, these are not simple loops to begin with).

http://stackoverflow.com/questions/1148309/inverting-a-4x4-m... http://stackoverflow.com/questions/2624422/efficient-4x4-mat...

Re: Web GL Ocean Simulation

#117
post #33

Earlier quoted context omitted.

I wonder if it was all handwritten. Esp. functions like invertMatrix or premultiplyMatrix. Or what he used to generate the code. I once used WolframAlpha to get me some complicated formulas and wrote a custom WA-plaintext-output-to-C translator for that output to use it in my code. Here is the script: https://github.com/albertz/helpers/blob/master/wolframalpha_... Example input: http://www.wolframalpha.com/input/?i=s…

It's worth pointing out that you should rarely, if ever, use exact formulas since there are a lot of problems with numerical stability amongst other things. Often it is faster to just numerically solve the system. For example, in your case you are solving Ax=b which you can easily solve by a simple LU decomposition. Plus if your A changes, your exact formula is wrong, so using an LU decomposition just makes sense. Pl…

The conventional wisdom (in scientific computing) that you seldom need to compute an inverse of a matrix does not apply to computer graphics. 4x4 matrix inverse is one of the most useful functions in computer graphics and is used a lot.

It is most often used as a hand rolled 4x4 matrix inversion function, not a generic NxN matrix inversion.

Re: Web GL Ocean Simulation

#118
post #35

Earlier quoted context omitted.

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 directl…

>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.

I know I have seen such a project on github once, but for the life of me I can't find it right now.

Re: Web GL Ocean Simulation

#120
post #20

Where would one start if they wanted to learn the math needed to achieve something like this?

I'd suggest a good book over Wikipedia articles, most math articles are particularly useless for learning stuff IMO.

I learned quite a lot from "Mathematics and Physics for Programmers", although I wouldn't call it perfect. I'm also quite interested in "Essential Mathematics for Games and Interactive Applications".

It's true, once you've got linear algebra figured out you can do a whole lot in the simulation/games space, but it helped me to learn the more advanced stuff in terms of games and simulations.

Post reply on HN