This project is read-only.

Small refraction issue

Feb 5, 2008 at 7:06 PM
Edited Feb 5, 2008 at 7:12 PM
Hey guys,

I've started building a ship game based on this QuickStart engine and I found a small issue with the refraction where it looked pretty weird with the masts of the ship when the whole ship shows .. I eventually tracked it down in :

http://www.codeplex.com/QuickStartEngine/SourceControl/FileView.aspx?itemId=179474&changeSetId=9387

that is :

framework / Template / QuickStart Engine / QuickStart Engine / Code / Components / Water / Water.cs

In the method (wish the source browser had line numbers) :

private void DrawRefractionMap(GameTime gameTime, ref Matrix ViewMatrix, ref Matrix ProjectionMatrix, Light SceneLight, Camera CurrentCam)

the line :

Vector4 planeCoefficients = new Vector4(ReflectNormalDirection, Elevation);

is supposed to use the RefractNormalDirection, no? The ReflectNormalDirection in the DrawRefractFromUnderwater() method works properly though (for some reason? O.o)

for completeness, here's before and after shots, notice in the first shot how the hull isn't even visible..

Before: http://www.dats.co.za/down/refractShip.JPG
After: http://www.dats.co.za/down/refractShipFixed.JPG

Edit: For these shots, I have removed the ship from the Reflected components list

anyhow - just my 2c..

Cheers,
- CmdrDats
Feb 5, 2008 at 7:45 PM
Edited Feb 5, 2008 at 7:45 PM
This is a known issue at the moment. The problem is that you want to reflect and refract things that are "behind" the water. Things like terrain completely obstruct water behind it for the most part, so this looks fine, but when you get things like models where water can get behind it, or above it (on the screen), then things can start to look strange. I still haven't found a fix for this. I'd like to get this fixed for v0.20 or v0.21.

Thank you for your feedback.
Feb 5, 2008 at 8:21 PM
Umm, sorry, but doesn't switching the ReflectNormalDirection in DrawRefractionMap() to RefractNormalDirection fix it? It works for me?
Feb 5, 2008 at 10:58 PM
I'll have to test it out, I know I've switched the direction before. Are your reflections working right when you're underwater still?

I know with some things I think they're fixed but other things end up broken.

When you create a reflection from above water you take a snapshot (from that same elevation, except underwater), at the opposite vertical angle. So if I am looking down 15 degrees into the water, at 20 units above the water, the position of my camera for the reflection snapshot will be the same in the X, Y, and 20 units below the water, at an angle of 15 degrees up into the water's surface.

The major things is that when doing a reflection from above the water, only models whose positions are above the water plane will get a reflection, everything underwater gets culled from rendering to improve performance. Besides, nothing above water should get reflected right? Well the problem is that sometimes a models "position" is underwater, but the model is large enough to still be above the water.

The water code was still in alpha stage for v0.182. If I'd had time I might've checked the min. corner of the bounding box against the water instead of the position. That might fix the issue of knowing what to cull. But it might re-surface your problem if they're related.
Feb 6, 2008 at 5:13 AM
Well, afaict (and forgive me, I'm no expert when it comes to this stuff :P ), there are two parts to the water effect :

Reflection

The part that reflects like a mirror, This works nicely from above water, but my model isn't complex enough from underwater to tell if the reflections work properly there - i suspect it also needs to switch the culling plane normal from underwater since you want to reflect the bottom of the model from underwater? not sure...

Refraction

The part that distorts what you see through the water...

I had a problem with the Refraction from above water. Afaics, what you're doing is simply chopping the model in half by the water plane, which makes sense, but then you're passing the normal for the refraction pointing up instead of down, which would take the snapshot of the upper part of the model instead of the lower... this works fine for the DrawRefractFromUnderwater() method, since you want to see the top part of the model when looking through the water from underwater, but from above the water, you want to see the bottom half of the model, which needs the opposite normal when culling the model..

I noticed there's a commented out SaveToJPG (or something like that, don't have VS open right now) for the refraction backbuffer - take a look at what that produces for the refraction above water :)
Feb 6, 2008 at 4:17 PM
I'd have to take a bigger look at it, unfortunately I've been very busy with work and the newer versions of the engine, which do not have water yet.

I remember that the culling planes were cutting through the models, which was intended, but it was causing issues because the models did used backface culling, so the reflection and refraction of a model cut in half looked strange in many situations.

Its been quite awhile since I looked at the code so I don't remember my exact method and reasoning for choosing which entities to draw.