GLSL Ocean Shader

s.rozsa's picture

i was playing around with some GLSL shader stuff in QC. This is what i got after i have modifyed some frag and vert shaders from the Ogre3d distribution. It is not bad, but the coordinate system is not matching the desired directions (the movement of the waves and the displacement is done only in the x/y direction)...

If one could solve this issue, i think that we would have a nice GLSL ocean shader. Is there a way BTW to use a cubemap or an environment map (hdri) in QC?

Also - since it is somehow related, i would like to point your attention to this feature request: http://kineme.net/FeatureRequests/FluidSolverQC

PreviewAttachmentSize
ocean.zip2.79 MB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

franz's picture
Re: GLSL Ocean Shader

it doesn't work here. console says : QuartzComposer.editor[713]) Exited with exit code: 15 Cg compiler terminated due to fatal error

too baad

s.rozsa's picture
Re: GLSL Ocean Shader

hmmm... just tested the file again and throwed out the HDRI image i was using. Also i attached the displ.map file i am using. It works as initally described on my machine (MacPro, 8GB, 10.5.6, QC 3.1)... Could you try this v. again?

PreviewAttachmentSize
ocean.zip215.07 KB

psonice's picture
Re: GLSL Ocean Shader

It works fine here, I see a wavy plane with some sin waves giving it a rippling effect, and a bump map moving around on the surface.

Really, you have the basics working fine, it just needs some tweaking. Some hints for good looking water:

  • You need quite a few wavelengths to create realistic motion. I usually have at least 4 sin waves, 2 large (with slightly different wavelengths, and moving at an angle of say 15-30 degrees to each other - that gives a much better water effect) and 2 small (same setup, but much smaller wavelength and amplitude - this gives you the smaller surface details to make it look like a sea instead of big smooth hills).
  • The bump map you're using is OK, but it's static, so it's very obvious that it's a texture moving around. Try using 2 or more textures moving at different speeds, and blending them. That will give you an animated ripple. The texture is normally only for small details, the bigger waves should be handled by the vertex shader.
  • Lighting is super important.. the colours you use give an impression of what kind of sea it is (for big waves like this, a very dark blue/green will look more like big ocean waves). Look into fresnel techniques (water is transparent when looking at 90 degrees to it, and reflective when looking across it) and consider how the light works inside the water - the waves let a lot of light through near the top, and very little deep down, so the colour could perhaps get lighter with height.

franz's picture
Re: GLSL Ocean Shader

there's just a w_normalmap.jpg in your zip... no QTZ

s.rozsa's picture
Re: GLSL Ocean Shader

sorry Franz, my failure... Her's the file again... Hope it is working now also for you...

PreviewAttachmentSize
ocean.zip400.31 KB

slof's picture
Re: GLSL Ocean Shader

I tried to simulate some water-fx too using Kineme3D tools as well. Tried to figure out how to slow the waves but can't seem to find it. I've attached my composition for people to try out.

grtz, Slof

PreviewAttachmentSize
waterKineme3D.qtz6.72 KB

s.rozsa's picture
Re: GLSL Ocean Shader

Hey psonice, thanks for the tipps and the comments. Well the shader does not working as it should (imho). There should be more than what we can see and it is a bit more complex than it is looking at the first sight. Actually it is an implementation of the theory behind this article: http://http.developer.nvidia.com/GPUGems/gpugems_ch01.html and it was done for a water demo in Ogre3d. I just managed a manual input for the displacement texture and for the environment texture for the shader (though i am still not be able to use the environment in QC - same is also for reflection/refraction btw.)...

As you can notice the sine wave is done parallel to the surface - this is false it should be perpendicularly to the surface. Also there is no real displacement (bump) but it is supposed to be there. So i quess that ther's something strage in the coordinates i'm using in the shader...

Here is btw. another article about a similar implementation...

PreviewAttachmentSize
GPU_Gems2_ch18.pdf1.9 MB

gtoledo3's picture
Re: GLSL Ocean Shader

I think this was really clever.

The best you can do, I think, is to put the noise on no update, and try to slowly amp up the amount.

It's not REALLY the same as slowing the wave. I believe that the rate of noise is always the same, you can only vary the amount. Varying the amount slowly doesn't quite give the effect of slower waves, but it does infer it a bit.

Attaching the noise to external time, or putting everything into a macro and controlling with external timebase doesn't slow the rate of noise.

Kudos on that man. You can get some great hair textures with the noise patch and certain settings as well.

PreviewAttachmentSize
water ripple no update.qtz5.08 KB

gtoledo3's picture
Re: GLSL Ocean Shader

I changed the color of the clear, and changed the alpha value of the plane to get some blue-ish look going on.

I think that using the plane like that with some transparency, and maybe putting a sprite behind it with some generative texturing could be a rich visual look.

The GLSL patch that's been on this thread isn't doing so hot however. It looks very promising though. Very "unsmooth". I tried this same GLSL technique about 8~9 months ago and got about to the same place and said screw it. I think I'm going to mess with it for a bit now...

My fav water emu for situations like this is just to use CI Glass distortion, and feed an appropriate displacement texture.

franz's picture
Re: GLSL Ocean Shader

not working either.... it even crashes finder and quicklook. Also crashes Quartz Composer. strange. i'm on a MBP 2.5 / 4gB RAM / GeForce 8600 512Meg 10.5.6 QC 3.1

gtoledo3's picture
Re: GLSL Ocean Shader

It works on my end (GMA X3100), it's just horribly slow, and not too good looking (the GLSL shader). It's running at in between 1~2fps.

jersmi's picture
Re: GLSL Ocean Shader

Great post, informative re: shaders, etc.

I was really wishing this weekend the 3D Object Noise patch could be smoothed in relation to a timebase. Thought maybe it could be done with the Queue and Object Blend, but closest i could get was something that looks more like low fps. Maybe this could be done by sorting the structure and using a Smooth to blend normals/vertices? Or maybe this is a feature request for a Object Smooth patch with a timebase?

gtoledo3's picture
Re: GLSL Ocean Shader

"Rate of noise" on the noise patch, is probably the best way to express the desired feature I think, or perhaps having rate of noise be able to be controlled via external time base; it doesn't have anything to do with the smooth patch, besides the fact that the smooth gives smooth normals to the object you are generating with the plane/noise combo. It's all about the noise patch :o)

Sorting structure/queue aren't applicable to this scenario unless I'm missing something (and could be!). You can't sort structure on a kineme plane that's being deformed with noise... there isn't any structure to sort!

The blend concept is interesting, but from some previous experiences, I think it would highly resemble the look of adding less noise, and you would end up with the same "rate/speed" just less of it. Never hurts to try though.

jersmi's picture
rate of noise

there's "rate of noise" then there's objects transitioning between deformations-- it's the latter i wonder about. any clues?

Re: sorting structure/queue, what gets captured to the queue, then? I set up a kind of sample and hold with the queue, feeding it the deformed object and filling the queue with pulses (with the watcher), like a freeze frame. this works.

With the blend setup, i have 2 queues capturing at different intervals with the, delaying one by half the interval and blending the two with Object Blend. not good results, but it brings up these other questions... and i think i see what you mean about resembling the look of less noise...

gtoledo3's picture
Re: rate of noise

I misunderstood what you were meaning sorry. Yeah, if you are recording it into the queue and taking little "snap shots".... yeah, that creates a structure. It's static "snapshots" of kineme3d objects that are being recorded, not the same as if the object itself had multiple structure elements. The semantics confused me. How does that work on your end of things? Does it run ok, or does that queue get expensive?

Hmm, I'm not going to theorize, I'm going to spend some time actually messing with this instead (when I get some time).

My observation about the blending was informed from blending two deformed objects on previous occasions, and finding that it was just creating more work for myself and making things convoluted.... in every case it seemed like I could get the same result from tweaking the deformer differently. There could be an upside to it though, never know. (To digress, it could be used to blend between different deformer effects which could be cool...)

jersmi's picture
Re: rate of noise

Sorry for the semantics...

The queue setup runs pretty good over here, have to look again for specific fps, but no problems to speak of. Only need to capture one state at a time in the queue...

Just to restate the issue: using the 3D Object Noise patch, I'd like to be able to slow down the rate and have each deformed state morph to the next.