Game Development Community

TGEA Water Shader artifacts, any suggestions to fix it?

by Stefan Lundmark · in Torque Game Engine Advanced · 03/18/2007 (10:59 am) · 10 replies

When you place an object infront of the water plane, the water will distort it around the edges. It looks like the object is reflected or below water, but it is not.

Here are two images. The first one is an example of the terrain edge from another view, just so you get a better picture of how it looks and where the water is.

www.innercircledev.net/garagegames/water01.jpg
And here is the same spot from a different angle:

www.innercircledev.net/garagegames/water02.jpg
I know the shader is to blame, but I can not really figure out what it is doing. Is that reflection or refraction? Shaders are all greek to me.

#1
03/18/2007 (11:15 am)
Thats the refraction which is rendered after the terrain is rendered and for some reason is not capable of only refracting the water or what is reflected in the water, it even does refract stuff that is not reflected at all.

If you place the space ork in front of the water, it will look like he has an evil aura or something.

So far I've not been able to find a usefull solution to the problem.
Its kind of disturbing that such a flaw, which definitely must have been noticable during development, wasn't fixed for release ...
#2
03/18/2007 (11:46 am)
The Modernization Kit faced a similar problem during early development. I used the generic refraction technique described in chapter 19 of GPU Gems 2 to resolve it. Basically, what the MK does is ensure that the alpha buffer is set to 1 at the beginning of the frame, and then the water renders 0 to the alpha buffer in a first pass. In the second pass, the shader checks the value of the alpha buffer. If it is 0, we render the refracted image, otherwise we render the unrefracted image. This has the opposite effect of the TGEA shader: instead of refracting objects above water we don't refract certain areas below water, but it's far less noticeable.

It probably wouldn't be too difficult to implement a similar solution in TGEA.
#3
03/18/2007 (12:04 pm)
You need to post your hardware with a question like this. You running SM 2.0 water?

I delete all my 1.x because I don't have time for transitional (to say it nicely) hardware.. let TGE 1.5 worry about that. That's just a personal preference but still curious on your GPU.
#4
03/18/2007 (12:13 pm)
Thanks guys.

@Alex: Did it introduce any flickering in your modernization kit?
#5
03/18/2007 (12:13 pm)
7600Go (7300GT) with SM3 support etc etc

Normally you do not notice it, with flat terrain at the water edge for example.
But if an object is blocking your view, the effect will become very visible. The "thiner" the object, the better you see it.
#6
03/19/2007 (4:06 am)
Hmm, must admit, never saw that. Interesting.
#7
03/19/2007 (8:09 am)
Yeah I can see how this would be missed during development. Unless I'm wrong, this would only happen when an object is in the foreground, water is the background, and your view puts the object below the horizon. I'm sure now that its known it can be fixed.
#8
03/28/2007 (3:41 pm)
Ping Pong Brian, any thoughts? I guess I could purchase that book, but I would rather not if someone else knows of any papers about this on the net. I looked but could not find anything.
#9
03/28/2007 (3:54 pm)
You could do the technique that Alex is referring to. It does have the downside of being multi-pass.

Another thing you can do is adjust the amount of distortion that is being used on the refraction. You could even do this based on distance so that if you are far away from the water, it does little or no distortion. It's pretty easy to do if you are familiar with HLSL. In the water shader, the refraction texture lookup is distorted the same as the reflection lookup (simpler code). It just needs to be separated out and adjusted as you see fit. Not as efficient, but it gives you more control and will probably look better.
#10
04/06/2007 (10:35 pm)
This kind of stuff would be so easy to resolve if we had a reliable, widely-supported (I'm looking at you, ATI/AMD!) way to copy the depth buffer into a texture... you'd just need to look it up and ignore distorted samples with depth closer than the water surface.