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
Page «Previous 1 2 3 4 5 Last »
#1
05/29/2009 (11:38 am)
hell, I've been wishing for something like that for ages.
#2
05/29/2009 (11:43 am)
T3D isn't far from that is it? Really, we've got the light rays, we'eve got the surface, all you need now is a shader for the terrain under the water, depending on distance from surface, and you're done. Or am I over-simplifying this?

You wouldn't even have to make it actually compute anything special, just have it based off some turbidity value, ideally directly from the water block, and use that for the animation.
#3
05/29/2009 (12:03 pm)
The wavy effect is not diffucult to do using a fullscreen shader.
We only need to pass the screen coord,then a simple post process pixel shader will do the turbulence.
#4
05/29/2009 (12:44 pm)
Looks like the only things that are missing right now are 1) a more robust/different method for the light ray effect so that you get rays when the sun is off screen, and 2) the caustics texture rendered to the terrain (tricky).
#5
05/29/2009 (1:00 pm)
Well with caustics ... you cannot just render them to the terrain. They should be rendered over all objects that are underwater. And they should only be rendered over half of the objects as its an effect of the water surface projected along the light direction.

I think the best way to do caustics for T3D is to only do it for Advanced Lighting mode. You make a new PostEffect that rebuilds the 3d position per pixel and fetches its normal. You then decide if that point is under water and faces the sun... you then lookup the animated caustic texture samples and apply it.

So anyone willing to take a shot at it?
#6
05/29/2009 (1:09 pm)
Yeah, when I saw the post I thought about PostEffect. Someone tell how to fetch normals from the #prepass and I might take a look at doing caustics.
#7
05/29/2009 (2:11 pm)
First, #include this file in your shader:
#include "shadergen:/autogenConditioners.h"
This file is automatically created and maintained by the Torque ShaderGen system. It will let you read data from buffers which can use different formatting methods. To read from the named buffer "#prepass" you do the following:
float4 prepassSample = prepassUncondition(tex2D(prePassSampler, IN.uv0));
float3 normal = prepassSample.rgb;
float depth = prepassSample.a;

The formatting functions for all buffers is: 'buffernameUncondition' and 'buffernameCondition'. 'Uncondition' takes formatted data and changes it into data you can use easily; 'Condition' takes the data you want to output, and formats it appropriately for the target it is being stored in.
#8
05/29/2009 (2:43 pm)
Ah, so that's what the condition/uncondition stuff does. Having access to normals in the postEffects fills my mind with possibilities. I also loved the "shadergen:/" bit. Is filesystem mounting new to T3D, or did TGEA 1.8 already have this?
#9
05/29/2009 (3:19 pm)
The mounting file system is new for Torque 3D.

Also look at the water and other post effect shaders for examples of how to use the unconditioners.
#10
05/29/2009 (5:13 pm)
Working on it right now. Just found how to reconstruct the 3D position using IN.wsEyeRay (very nice indeed!). The fog was a nice example, since it works based on world position.
#11
05/29/2009 (5:54 pm)
Progress report:

Got the the point where I have the world-coordinate UVs I'll use to sample the caustics texture.
i44.tinypic.com/2rruq9v.png

Saving the shader and seeing the results right away is lotsa fun.
#12
05/29/2009 (6:02 pm)
Does the shoreline effect use a depth buffer?
#13
05/29/2009 (6:04 pm)
Is there a built-in time constant or something else I can use to animate the caustics?

- EDIT -
Ah, I think a found it. PostEffect seems to call the script method setShaderConsts() on itself before each render, is that right? I can se my own custom constants in there?

Wait, what? $matPrevScreenToWorld? Camera motion blur!
#14
05/29/2009 (6:05 pm)
Talking with Pat he suggested that this might work more correctly if the caustics were written into the #lightinfo buffer which is then used in the forward pass to light the scene. This would ensure that the caustic properly masks specularity.

Funny enough you could easily do that by adding a post effect after the AdvancedLightBinManager and writing to the #lightinfo target. PostEffects are cool.

Also another thought... should caustic occur on surfaces within a shadow from the sunlight?
#15
05/29/2009 (6:14 pm)
PostEffects can output to the light accumulation buffer? Nice. And yeah, I think they should be shadowed... can I use the #lightinfo as an input? Are shadows applied into it or elsewhere? If #lightinfo is shadowed, I could simply modulate the caustics with it into another target then render it back to #lightinfo.

Thinking again, I don't think I need to write it to the lightinfo... caustics are projected lighting, not reflected like specular. Adding them to the scene should suffice (but modulating them with the shadows would be ideal).
#16
05/29/2009 (6:27 pm)
@Manoel, there's an elapsed time (since the last frame) const that the PostEffect class sets, I believe. Though you can always set up the script constants if you need something more specific (plenty of examples, it's fairly straightforward, just look at any of the current PostEffects).
#17
05/29/2009 (6:27 pm)
Haha, love these "unwanted consequences": i42.tinypic.com/2vnf6g7.jpg
#18
05/29/2009 (6:29 pm)
@Ross: couldn't find it in the source code. I'm on beta 1, is it beta 2-only? Dang, haven't downloaded it yet here at home.
#19
05/29/2009 (6:35 pm)
Hrm, disregard, you'll probably just have to set something up via the script shader consts.
#20
05/29/2009 (6:45 pm)
Quote:Does the shoreline effect use a depth buffer?
Yes it does. The water surface shader reads the scene depth from the #prepass buffer. It then compares it to the water surface to calculate how much of the refraction texture and shore foam to blend in.
Page «Previous 1 2 3 4 5 Last »