Game Development Community

Water not rendered in mirrors

by Ryan Nunn · in Torque Game Engine · 10/11/2005 (6:16 am) · 2 replies

I noticed a bug where water wasn't being rendered in mirrors. I've tracked it down to 2 problems.
1) SceneState::mFlipCull is being ignored by the fluid code so glCullFace() calls are wrong and clip planes are not being flipped
2) The near clipping plane is being incorrectly generated

Here are a list of changes to fix the problem:

Change the method
void fluid::Render ( bool& EyeSubmerged )
to
void fluid::Render ( bool& EyeSubmerged, bool FlipCull )

Then in fluid::Render() change the two glCullFace() calls to
// MM: Set culling mode.
glCullFace(EyeSubmerged^FlipCull?GL_BACK:GL_FRONT);
and
// MM: Restore culling mode.
glCullFace(FlipCull?GL_FRONT:GL_BACK);

Then in WaterBlock::renderObject() change the call
mFluid.Render( CameraSubmergedFlag );
to
mFluid.Render( CameraSubmergedFlag, state->mFlipCull );

Also in WaterBlock::renderObject(), change the following to fix the clipping plane problems
// near plane is needed as well...
PlaneF p(0, 1, 0, -frustumParam[4]);
mTransformPlane(L2Cm, Point3F(1,1,1), p, &mClipPlane[0]);
mFluid.SetFrustrumPlanes( (F32*)mClipPlane );
to
// near plane is needed as well...
PlaneF p(0, 1, 0, -frustumParam[1]);
mTransformPlane(L2Cm, Point3F(1,1,1), p, &mClipPlane[0]);

// ensure clipping planes are flipped where required
if (state->mFlipCull) {
	mClipPlane[2].neg();
	mClipPlane[3].neg();
	mClipPlane[4].neg();
	mClipPlane[5].neg();
}

mFluid.SetFrustrumPlanes( (F32*)mClipPlane );

About the author

Recent Threads


#1
10/11/2005 (7:04 am)
Cool... You should submit it as a resource. (or add it to TDN)
#2
10/15/2005 (5:45 am)
Better yet, submit it to Ben as a bug fix so it goes into 1.4