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
http://www.youtube.com/watch?v=cJM48NBQ3pw
About the author
http://www.visitorsthegame.com
#62
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.
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
And Afan is right, you don't have caustics at high depths. Still, good work guys! :)
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! :)
#65
no one got this working in beta 5?
anyone?
same for the turbulence shader
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
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.
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
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?
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
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.
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
did you define the shader constant functions for elapsed time in your .cs file?
08/18/2009 (8:11 am)
@deepscratchdid 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
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?
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
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.
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
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.
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
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?
08/18/2009 (8:58 pm)
@jamesCould 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.
#76
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?
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
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...
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
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.
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
Oh right, Sim::getCurrentTime is C++, its getSimTime() in script I believe.
08/20/2009 (5:28 pm)
Sounds cool. Oh right, Sim::getCurrentTime is C++, its getSimTime() in script I believe.
Torque Owner deepscratch
DeepScratchStudios
renderTime = "PFXAfterBin";
should be
renderTime = "PFXAfterDiffuse";
and
renderPriority = 0.1;