在 Direct3D 中使用模板缓冲区
我正在尝试使用 ID3D11Texture2D 上的模板缓冲区将一个纹理的一部分覆盖在另一个纹理上。我计划通过在模板缓冲区上绘制所需的形状然后复制纹理来实现此目的。请建议一些好的教程,其中包含 2D 纹理的示例代码,以学习模板缓冲区的使用。 (或者一些替代方法来做到这一点)
I'm trying to use stencil buffers on ID3D11Texture2D
to overlay a portion of one texture on another texture. I plan to do this by drawing the desired shape on the stencil buffer and then copying the texture. Please suggest some good tutorial with sample code for 2D Textures for learning the usage of stencil buffer. (or some alternate way of doing this)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Stencil mask 101:
*不遵循这些规则中的大多数通常会导致最坏情况的模板性能:您的像素着色器为每个执行像素,并且不对模板掩模像素执行早期拒绝。此外,在较旧的 Geforce 卡上,这还可能导致所有后续绘制调用的早期深度拒绝被破坏,直到下一帧或深度缓冲区和深度缓冲区才会修复。模板被清除。
模板蒙版实际上很容易生成:
绘制多边形。请注意,在着色器中使用“丢弃”将阻止模板更新,这就是将纹理加载到模板缓冲区中的方式(但仅作为二进制掩码)
禁用模板写入,启用模板测试
Stencil mask 101:
*Failure to follow most of these rules usually results in worst case stencil performance: Your pixel shader executing for every pixel, and not performing an early reject for the stencil masked pixels. In addition on older Geforce cards this can also result in the breaking of the early depth reject for all subsequent draw calls, which won't be fixed until the next frame or depth buffer & stencil is cleared.
Stencil masks are actually pretty easy to generate:
Draw a polygon. Note that using 'discard' in the shader will prevent the stencil from being updated, which is how you load a texture into the stencil buffer (but only as a binary mask)
Disable stencil writes, enable stencil test