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
#61
06/03/2009 (5:31 am)
ok, answered my own question.
renderTime = "PFXAfterBin";
should be
renderTime = "PFXAfterDiffuse";
and
renderPriority = 0.1;
#62
06/05/2009 (6:00 pm)
Great resources everyone. That's the best thing about T3D, you don't have to code your own posfx layer :). Anyway on the topic of underwater effects, we've actually recreated all of them for our upcoming game (that was started in TGEA). On a side not the "underwater turbidity" effect can be optimized a bit if coordinate perturbations are stored in a texture (in fact I've found that normal maps in object space are easiest to edit), that way you avoid those expensive sin() calls (unless you're stretching the texture units to the limit already, which is highly unlikely) on the plus sde it gives more breathing space for the artists. Secondly god rays are very tricky to do completely as a postfx shader; we achieved the best results with geometry extrusion, with minimal hits.
Kudos to the OP for the caustics shader. On a side note for best looking caustics I found out that you have to keep two things in mind: light dissipates differently with depth (very rough approximation of the falloff function would be exp(sqrt(x)) therefore forming very distinctive patterns at differing depths; second caustics have about 20-30% less penetration than blue wavelengths, so for clear tropical seas we're looking at about max cca. 30m/100ft.
#63
06/06/2009 (12:26 am)
There's a bug with the Turbulence effect. If I awitch between first and third person, the screen becomes blurry.

And Afan is right, you don't have caustics at high depths. Still, good work guys! :)
#64
06/27/2009 (3:20 am)
the caustics is broken in beta3,
anyone know what the fix is??
#65
08/17/2009 (6:02 am)
we are at beta 5,
no one got this working in beta 5?
anyone?
same for the turbulence shader
#66
08/17/2009 (7:26 am)
I haven't looked at post effects lately, but at least for custom material they ripped out some of the scenegraph data access (backbuffer, refractmap).

I'd be surprised if you couldn't access the backbuffer in post effect, but I'm rambling so that might not even be the problem as I haven't tried these postfx since beta ... 3 ?

check this thread and this thread for tidbits on plans for custom material. I know we are talking about post effects so it may or may not be relevant.
#67
08/17/2009 (4:50 pm)
Joushua is rambling :)

PostEffect can access the back buffer like always.

CustomMaterial is a whole different beast.

@deepscratch - I'm sure a little debugging work would resolve it. Like are you getting shader errors when you enabled it?
#68
08/18/2009 (7:42 am)
hi Tom,
no shader errors at all, they both activate, but dont animate, ie: the caustic shader just lays the textures on everything it should, but doesnt animate, and the turbulence shader shows the screen distorted as hell, but doesnt animate the distortion,
I'm really clueless with shaders, and wouldnt know where to start debugging them.
#69
08/18/2009 (8:11 am)
@deepscratch

did you define the shader constant functions for elapsed time in your .cs file?

#  function TurbolenceFx::addShaderConsts(%this)  
# {  
#    %this.timeConst = %this.addShaderConst("$elapsedTime", 0.0);  
#    %this.timeStart = $Sim::time;  
# }  
#   
# function TurbolenceFx::setShaderConsts(%this)  
# {  
#    %this.setShaderConst(%this.timeConst, $Sim::time - %this.timeStart);   
# }
#70
08/18/2009 (8:36 am)
@Joshua,
I had them both working fine till beta 5, now they both wont work.
yes, I defined the constant.
do you have them (these two shaders, caustics and turbulence) working in beta 5?
if so would you mind sending me or posting what you did to get them working in 5?
#71
08/18/2009 (8:58 am)
I think I read something in the beta5 changelog about the way constants are set (seems addShaderConst doesn't exist anymore), but haven't looked into it yet. Check the beta 5 post effects to see how they are doing it.

Also, postEffects have a built-in time elapsed constant (I think it's called "accumTime" - the DOF probably uses it, check that out), there's no need to add one yourself anymore.
#72
08/18/2009 (1:21 pm)
Note: DOF actually doesn't use it, but otherwise Manoel is correct.

The way it works now, there is no need to add your shaderConsts and save an index to use when setting them later. Instead you just use the string-name when setting them.
#73
08/18/2009 (8:58 pm)
@james

Could you provide an example? I have no idea what you are saying there.
Just use a string-name when setting them?

Soo... $elapsedTime = 0.0; in script?
#74
08/18/2009 (9:45 pm)
The easiest thing is to look at how the PostEffects already written are doing it.
#75
08/19/2009 (1:25 am)
which ones use elapsed time?
I couldnt find any....
#76
08/19/2009 (7:31 am)
Exactly my point. You go through the trouble of saying roughly how to do it but leave the job of spinning our wheels trying to find an exact example (RAWR). That's how I feel the documentation is for the entire engine. This was an attempt at constructive criticism.

Find in files here I come again.

Edit-

uniform float accumTime : register(PC_ACCUM_TIME)

I assume this is it? Am I correct in guessing the engine constantly updates this value with an ever increasing time? If I want to measure time differentials I guess I have to set a 2nd uniform and then compute the difference between that and the accumtime?
#77
08/19/2009 (1:07 pm)
If you put this in your PostEffect's shader, the total elasped time will be sent to it automatically.

uniform float accumTime; // (register etc is not required)

Yes, if you want a time difference you'll need to pass in the "reference" time yourself. Which you could, for example, do like this...

// Will be called every time MyPFX is processed prior to rendering.
function MyPFX::setShaderConsts( %this )
{
   %this.setShaderConst( "$refTime", $MyPFX::refTime );
}

// At some point elsewhere... initialize refTime with whatever is appropriate.
$MyPFX::refTime = Sim::getCurrentTime();

#78
08/19/2009 (1:45 pm)
That's a great example. Thank you for the explanation.
#79
08/20/2009 (4:01 pm)
@James,
thanks, that was a good push in the right direction,
I changed all instances of elapsedTime to accumTime,
and now the caustics and turbulence shaders are working again.
btw, $MyPFX::refTime = Sim::getCurrentTime(); returns a script error,
"unknown command getCurrentTime"
but they dont need it anyway.
#80
08/20/2009 (5:28 pm)
Sounds cool.

Oh right, Sim::getCurrentTime is C++, its getSimTime() in script I believe.