protected virtual void SetShadowVolumeStencilState( bool secondPass, bool zfail, bool twoSided )
{
// First pass, do front faces if zpass
// Second pass, do back faces if zpass
// Invert if zfail
// this is to ensure we always increment before decrement
if ( ( secondPass ^ zfail ) )
{
this.targetRenderSystem.CullingMode = twoSided ? CullingMode.None : CullingMode.CounterClockwise;
this.targetRenderSystem.SetStencilBufferParams(
CompareFunction.AlwaysPass,
// always pass stencil check
0,
// no ref value (no compare)
unchecked( (int)0xffffffff ),
// no mask
StencilOperation.Keep,
// stencil test will never fail
zfail
? ( twoSided ? StencilOperation.IncrementWrap : StencilOperation.Increment )
: StencilOperation.Keep,
// back face depth fail
zfail
? StencilOperation.Keep
: ( twoSided ? StencilOperation.DecrementWrap : StencilOperation.Decrement ),
// back face pass
twoSided );
}
else
{
this.targetRenderSystem.CullingMode = twoSided ? CullingMode.None : CullingMode.Clockwise;
this.targetRenderSystem.SetStencilBufferParams(
CompareFunction.AlwaysPass,
// always pass stencil check
0,
// no ref value (no compare)
unchecked( (int)0xffffffff ),
// no mask
StencilOperation.Keep,
// stencil test will never fail
zfail
? ( twoSided ? StencilOperation.DecrementWrap : StencilOperation.Decrement )
: StencilOperation.Keep,
// front face depth fail
zfail
? StencilOperation.Keep
: ( twoSided ? StencilOperation.IncrementWrap : StencilOperation.Increment ),
// front face pass
twoSided );
}
}