Jump to content
  • Advertisement
Sign in to follow this  

rendering reflection problem

This topic is 3713 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok, im currently making a terrain generator and am wanting to redflect the terrain onto some water (this is my 1st terrain generator thing i have tried :) ) and i am having some problems. i have a large multi textured set of triangles for the water, which is placed 0.8 units above the 0 value of the terrain. i am rendering the reflection of the terrain onto the water using the stencil buffer etc as described in the NeHe tutorials for reflections and this sort of works. as in, when i dont render the 'seabed' as in any triangles of the terrain under the water then it reflect fine (but looks a bit odd because the terrain looks like it is floating - but that is expected) picture: http://img440.imageshack.us/my.php?image=reflectionmp7.jpg but when i tell it to render the triangles under the water too, the reflection dissapears as shown here. picture: http://img187.imageshack.us/my.php?image=noreflectionez2.jpg what i am wanting is the reflection on the water and to render the terrain under the water. i have tried playing with the setting s a wee bit but it usually makes it look a bit strange :(. here is the main bit of my render loop:

double eqr[] = {0.0f,-8.0f, 0.0f, 0.0f};				// Plane Equation To Use For The Reflected Objects

	glEnable(GL_STENCIL_TEST);						// Enable Stencil Buffer For "marking" The Floor
	glStencilFunc(GL_ALWAYS, 1, 1);						// Always Passes, 1 Bit Plane, 1 As Mask
	glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);				// We Set The Stencil Buffer To 1 Where We Draw Any Polygon
										// Keep If Test Fails, Keep If Test Passes But Buffer Test Fails
										// Replace If Test Passes
	glDisable(GL_DEPTH_TEST);						// Disable Depth Testing


glEnable(GL_DEPTH_TEST);						// Enable Depth Testing
	glColorMask(1,1,1,1);							// Set Color Mask to TRUE, TRUE, TRUE, TRUE
	glStencilFunc(GL_EQUAL, 1, 1);						// We Draw Only Where The Stencil Is 1
										// (I.E. Where The Floor Was Drawn)
	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);					// Don't Change The Stencil Buffer
glEnable(GL_CLIP_PLANE0);						// Enable Clip Plane For Removing Artifacts
										// (When The Object Crosses The Floor)
	glClipPlane(GL_CLIP_PLANE0, eqr);					// Equation For Reflected Objects
	glPushMatrix();								// Push The Matrix Onto The Stack
		glScalef(1.0f, -1.0f, 1.0f);					// Mirror Y Axis


		glPopMatrix();								// Pop The Matrix Off The Stack
	glDisable(GL_CLIP_PLANE0);						// Disable Clip Plane For Drawing The Floor
	glDisable(GL_STENCIL_TEST);						// We Don't Need The Stencil Buffer Any More (Disable)


sorry if my explanation is a bit obscure :P cheers for any feedback

Share this post

Link to post
Share on other sites
Are you enabling blending operations when rendering the seabed floor after you render the reflected image? If you were to blend the back buffer with the seabed floor this may result in both showing up as expected depending on the blend operation being used. If this does not resolve the issue you may be experiencing some z-buffer fighting particularly if the terrain is being rendered at the same z-depth as the seabed floor is but your clip plane may be taking care of that.

I would recommend the blending option first to see if this yields the expected results though you may need to tweak your blending inputs until you end up with the image you expect. If this does not resolve the issue, you could try offsetting the depth buffer by 1 when rendering the reflection then reset to default and render your seabed floor but I really don't think this should be totally necessary.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!