PDA

View Full Version : Terrain reflections problem.



MrShoe
07-15-2002, 12:12 AM
I have a problem, i want to implement water reflections in my terrain engine.
I basially at the moment have the terrain mesh ad one large water quad stretching over
at a certain height over the entire mesh.
Anyway, usully what you do:
Draw the terrain mesh
label all water quad pixels as 1 in teh stencil buffer.
Draw the height mesh again with negative heights this time. (if the water quad is
at 0 height) but only over the water quad pixels.
Then you would draw the water uad with alpha blending on.

Anyway, you cant do this with a terrain engine. This isbecaus the original mesh
will cover over the reflection mesh, this is because the original mesh goes continues
under the water as well.

Anyway, the closest i have come to a solution is to simpy say only draw thos parts of
the terrain mesh which are above the water quad, and not those below. Then it kinda works
but rather obviously it aint pretty :-) because this will produce jagged polygon cutoffs
in the terrain mesh.
Anyway, does anyone know how to solve this dilema?

Spartacus
07-15-2002, 03:20 AM
You could use clipping plane to clip off parts of terrain that are under water, when rendering reflection. Not very fast but works.



[This message has been edited by Spartacus (edited 07-15-2002).]

Jeffry J Brickley
07-15-2002, 09:08 AM
depends on if you want mixed caustics (appearance of objects under water) along with reflections. Just reflections, I would use an extra clipping plane to cut off at the water level (or at the elevation of your lowest wave if you have them). This avoids your polygon "jaggies" cutting off at the vertex.

MrShoe
07-15-2002, 03:14 PM
Relatively stupid question, but i never used clipping planes before. I know what they are kinda, but could someone give me and example of how to do this?

Spartacus
07-16-2002, 06:32 AM
Use of clipping planes is very simple, just call glClippingPlane(GL_CLIP_PLANEi, clip_plane) and then enable it.




void RenderReflection()
{
double clip[4] = {0,1,0,0};//assumes water plane y=0
glPushMatrix();
glScalef(1,-1,1);
glClipPlane(GL_CLIP_PLANE0, clip);
glEnable(GL_CLIP_PLANE0);
RenderScene();
glDisable(GL_CLIP_PLANE0);
glPopMatrix();
}


Hope this helps.

Jambolo
07-16-2002, 12:48 PM
How about you clearing the Z buffer after drawing the terrain? Also, make sure you reverse the winding order when you draw the reflection.

Spartacus
07-17-2002, 01:30 AM
Originally posted by Jambolo:
How about you clearing the Z buffer after drawing the terrain? Also, make sure you reverse the winding order when you draw the reflection.

Doh! I knew I forgot something... Thanks Jambolo for correcting!

MrShoe
07-17-2002, 02:04 AM
SLight problem... when i use the clip plane it interferes with my volumetric fog, since this fog is per vertex, and some verteces are cut off my the clip plane, i get fog artefacts near teh water...

JimmyT
07-19-2002, 02:55 AM
Have you tried searching the advanced forums? I seem to remember reading several threads about reflections in the past.

Good luck.