I am attempting to write a shader that does the following (pseudocode):
if CurrentPixel passes stencil test
write CurrentPixel.depth to depth buffer
if CurrentPixel.alpha > AlphaClipValue
update stencil buffer
However, I haven't been able to figure out how to update the stencil buffer conditionally while still updating the depth buffer; it seems as if it is either both or neither. I tried the following HLSL shader, and it didn't work:
/*
HLSL Pixel Shader: Stencil test and stencil update are set by D3D calls
on the CPU, so this shader will only execute if the stencil test passes,
and will update the stencil buffer once it finishes execution.
*/
float ClipValue;
void Main(
VS_INPUT Input,
float InDepth : TEXCOORD7,
float4 OutColor : COLOR0,
float OutDepth : DEPTH
)
{
// Update the depth buffer
OutDepth = InDepth;
// If the alpha is clipped, cancel the shader before writing to the
// stencil buffer, but after writing to the depth buffer.
clip( CalculateAlpha(Input) - ClipValue );
OutColor = 0;
}
What am I doing wrong? Is it even possible to write to the depth buffer without updating the stencil buffer?
There are 10 types of people in the world: Those who know binary and those who don''t.