这是一个 HLSL 问题,尽管如果您想在答案中引用该框架,我正在使用 XNA。
在 XNA 4.0 中,我们不再能够访问 DX9 的 AlphaTest 功能。
我想要:
- 将纹理渲染到后缓冲区,仅绘制纹理的不透明像素。
- 渲染一个纹理,它的纹素只在步骤 1 中没有绘制不透明像素的地方绘制。
我怎样才能做到这一点?如果我需要在 HLSL 中使用 clip(),如何从我的 HLSL 代码中检查在步骤 1 中绘制的模板缓冲区?
到目前为止,我已经完成了以下工作:
_sparkStencil = new DepthStencilState
{
StencilEnable = true,
StencilFunction = CompareFunction.GreaterEqual,
ReferenceStencil = 254,
DepthBufferEnable = true
};
DepthStencilState old = gd.DepthStencilState;
gd.DepthStencilState = _sparkStencil;
// Only opaque texels should be drawn.
DrawTexture1();
gd.DepthStencilState = old;
// Texels that were rendered from texture1 should
// prevent texels in texture 2 from appearing.
DrawTexture2();