Skip to main content
GameDev.net gamedev.net
🔒 Locked

water clip plane?

Started by ggp83 Nov 30, 2007 at 8:09 AM 3 replies 1.4k views
Original Post
ggp83
ggp83
I've got some piece of code which makes and renders water on a plane, and everything works great. Except when I don't want the water plane at y=0. I've tried everything(well almost), searched the forums etc.. But I can't figure out how to make the reflection texture when it's at a different y than 0. Here's the code I use:

glViewport(0, 0, textureSize, textureSize);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glLoadMatrix(camera.getModelViewMatrix());
glScalef(1.0f, -1.0f, 1.0f);
		
double[] clip = { 0.0, 1.0, 0.0, 0.0 };
glClipPlane(GL_CLIP_PLANE0, clip);
glEnable(GL_CLIP_PLANE0);

renderScene();
		
glDisable(GL_CLIP_PLANE0);
glPopMatrix();

// copy whatever in viewport to reflection texture
// etc...


The above code works great as long as the water plane is at y=0, but how do I make it work for any y?
FlyingIsFun1217
FlyingIsFun1217
Well, not that I have ever even touched glClipPlane();, but I would think that you would need to pass different Y values over to double[] clip.

Might want to wait for some other responses ;)

FlyingIsFun1217
Typh
Typh
if water is a single surface (unique) you can use a variable that is updated according to the loaded scene-map.

then as has said FlyingIsFun1217, you can do this way:
...
double waterlevel = surface.vertex[any].y;
...
...
clip[1] = waterlevel;

ff8
ff8

Hello,

not sure but i think u need to multiply ur clip plan w/ ur current matrix cause of
doing the scaling .

take care.
ggp83
ggp83
Ahh, I finally solved it :D

I simply translated the scene by (2 * waterplane.y) and then set the clip plane equation to [0.0, 1.0, 0.0, -waterplane.y].

So the resulting code would look like this:
glViewport(0, 0, textureSize, textureSize);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glPushMatrix();glLoadMatrix(camera.getModelViewMatrix());glTranslatef(0.0f, getPosition().y*2.0f, 0.0f);glScalef(1.0f, -1.0f, 1.0f);	double[] clip = { 0.0, 1.0, 0.0, -getPosition().y };glEnable(GL_CLIP_PLANE0);glClipPlane(GL_CLIP_PLANE0, clip);renderScene();		glDisable(GL_CLIP_PLANE0);glPopMatrix();


thanks for helping out :D

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.