Game Development Community

Underwater Effects, such as Caustics, Distorted/Wavy Screen, Rays, etc...

by Sorin Daraban · in Torque 3D Professional · 05/29/2009 (11:28 am) · 85 replies

Is something like Hydrax for Ogre3D on the horizon for T3D?

http://www.youtube.com/watch?v=cJM48NBQ3pw
#41
05/30/2009 (3:59 am)
@Picasso - You mean like making the screen all wavy when your underwater.... like this?
#42
05/30/2009 (6:09 am)
Yes.
I found a way to clean the edges and will share when finished.
I don't want to share unfinished work.
#43
05/30/2009 (6:44 am)
yay!
its been a productive day all round
#44
05/30/2009 (7:20 am)
Ok I found a Water Caustics you would be proud of Tom!

http://http.developer.nvidia.com/GPUGems/gpugems_ch02.html


So what do you think?
#45
05/30/2009 (7:54 am)
Manoel: Found a minor bug with the shader. When transitioning between above and below water, the effect activates regardless of where the sun is, and whether or not you're in shadow.

The effect is drawn across the whole surface of the water, as well as any part of your own model that is visible under the water.

This appears to happen at exactly the same position as the water plane. Perhaps the shader needs an offset?
#46
05/30/2009 (9:17 am)
Maybe the camera position Z is exactly at the water plane. Maybe getting the eye position and using it to offset if above/below the water could work.
#47
05/30/2009 (11:08 am)
I tried Manoel Neto's resource, but it doesn't work. :(
I see nothing. I just unzipped the zipped game folder over mine in the Genre Kits and enabled the PostFX in the Editor.
I tried to see the effect in the Warrior Camp level.
#48
05/30/2009 (11:12 am)
Manoel's code works flawlessly!

By the way the turbolence shader worked too.
Backbuffer Edging fixed!
Need a little testing and i'll share the code.
#50
05/30/2009 (12:51 pm)
ooohh, trippy!
but now how would one tie this into the caustics shader? or at least get it to render only under water?
#51
05/30/2009 (1:02 pm)
The same way as the waterDepth is calculated in the caustics one.
Anyway each PostEffect has isEnabled field,so it seems you have options...
#52
05/30/2009 (1:26 pm)
I'm late too the party.... that sure is awesome!
#53
05/30/2009 (2:26 pm)
@Picasso - That looks pretty good to me.

The water fog shader is toggled by the C++ code when you enter and exit the water. You could add the following to have other effects toggle when underwater...

function UnderwaterFogPostFx::onEnabled( %this )
{
   TurbolenceFx.enable();   
}

function UnderwaterFogPostFx::onDisabled( %this )
{
   TurbolenceFx.disable();   
}

Also for the turbulence shader you should also add the 'waterFogPlane' and 'eyePosWorld' constants to your shader and reduce the effect based on the distance between the eye position and the water surface plane. This would make the transition in and out of water look smoother.
#54
05/30/2009 (2:28 pm)
@JesseL - That effect seems to do CPU work to compute the caustic factor and store it into the mesh before rendering. IMO we should focus on a purely shader based effect here.

That said the paper does talk about the math behind caustics in good detail which would be helpful to anyone trying to develop something more accurate.
#55
05/30/2009 (3:11 pm)
Just in case someone has the same problem as me, the PostFX.zip file does not overwite the appropriate folders. The PostFX folder should extract in the \client\.. and not outside of it.
Something like this:
C:\Torque\Torque 3D 2009 Beta 2\Templates\Full\game\core\scripts\client\PostFX\ and not C:\Torque\Torque 3D 2009 Beta 2\Templates\Full\game\core\scripts\PostFx\
#56
05/30/2009 (4:13 pm)
@Sorin: Thanks for catching that! I was lazy and made the tree structure by hand, instead of doing it the "right way" via xcopy. I fixed the file, here's a new link (I also edited the original post): www.mediafire.com/download.php?wmmzmzojwwq
#57
06/01/2009 (11:25 pm)
Thank you Manoel for doing this.
Good job!!! :)

Now only if God Rays could be improved so Volumetric Lighting was possible. :p
#58
06/02/2009 (11:37 am)
just the tiniest little thing for the turbolenceP.hlsl file,
noticed how the distortion plays, comes to an end, then plays again?
change this line:
sin = clamp(sin, 0, 1);
to this:
sin = clamp(sin, 1, 1);
and it becomes a whole lot smoother all round
#59
06/02/2009 (12:07 pm)
sin = clamp(sin, 1, 1);

means sin=1;

A better decision is to disable the clamp:
//sin = clamp(sin, 0, 1);

By the way it is good to use a litle pause between each ripple,that simulates a surface ocean wave.
#60
06/03/2009 (5:24 am)
another thing I've noticed is that if the turbolece shader is enabled, and you are underwater looking up, the surface wave distortion effect is broken,
but I have no idea where to start looking to correct this.
anyone know?