candy
04-10-2004, 06:32 AM
Hi all, I would like to ask how to create a world with a lake that can have reflection on the water whenever some moving object is on the top of the water?
I have read a reference saying that it involves two-pass technique using the stencil buffer. The procedure for the first pass:
1. Initialize the modelview and projection matrices to the identity (glLoadIdentity).
2. Set up a projection matrix using the glFrustum command.
3. Set up the “real” eye point at the desired position using a gluLookAt command (or something
similar).
4. Reflect the viewing frustum (or the scene) through the plane containing the reflector by computing a reflection matrix and combining it with the current modelview or projectionmatrices
using the glMultMatrix command.
5. Draw the scene.
6. Move the eye point back to its “real” position.
The procedure regarding the second part:
Clear the stencil and depth buffers (glClear(GL COLOR BUFFER BIT |
GL DEPTH BUFFER BIT)).
2. Configure the stencil buffer such that a 1 will be stored at each pixel touched by a polygon:
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
glStencilFunc(GL_ALWAYS, 1, 1);
glEnable(GL_STENCIL_TEST);
3. Disable drawing into the color buffers (glColorMask(0, 0, 0, 0)).
4. Draw the mirror polygon.
5. Reconfigure the stencil test:
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glStencilFunc(GL_NOTEQUAL);
6. Draw the scene.
7. Disable the stencil test (glDisable(GL STENCIL TEST)).
I have read a reference saying that it involves two-pass technique using the stencil buffer. The procedure for the first pass:
1. Initialize the modelview and projection matrices to the identity (glLoadIdentity).
2. Set up a projection matrix using the glFrustum command.
3. Set up the “real” eye point at the desired position using a gluLookAt command (or something
similar).
4. Reflect the viewing frustum (or the scene) through the plane containing the reflector by computing a reflection matrix and combining it with the current modelview or projectionmatrices
using the glMultMatrix command.
5. Draw the scene.
6. Move the eye point back to its “real” position.
The procedure regarding the second part:
Clear the stencil and depth buffers (glClear(GL COLOR BUFFER BIT |
GL DEPTH BUFFER BIT)).
2. Configure the stencil buffer such that a 1 will be stored at each pixel touched by a polygon:
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
glStencilFunc(GL_ALWAYS, 1, 1);
glEnable(GL_STENCIL_TEST);
3. Disable drawing into the color buffers (glColorMask(0, 0, 0, 0)).
4. Draw the mirror polygon.
5. Reconfigure the stencil test:
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glStencilFunc(GL_NOTEQUAL);
6. Draw the scene.
7. Disable the stencil test (glDisable(GL STENCIL TEST)).