早期模版剔除 [英] Early stencil culling

查看:130
本文介绍了早期模版剔除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于模版测试,我正在努力使早期的碎片剔除工作. 我的场景如下:我有一个片段着色器,可以完成很多工作,但是在渲染场景时只需要在很少的片段上运行.这些碎片几乎可以放在屏幕上的任何位置(我不能用剪刀快速过滤掉这些碎片).

I'm trying to get early fragment culling to work, based on the stencil test. My scenario is the following: I have a fragment shader that does a lot of work, but needs to be run only on very few fragments when I render my scene. These fragments can be located pretty much anywhere on the screen (I can't use a scissor to quickly filter out these fragments).

在渲染过程1中,我生成了一个带有两个可能值的模板缓冲区.值对于传递2具有以下含义:

In rendering pass 1, I generate a stencil buffer with two possible values. Values will have the following meaning for pass 2:

  • 0:什么都不做
  • 1:可以继续(例如,输入片段着色器并进行渲染)

第2遍使场景正确说话.模板缓冲区的配置方式如下:

Pass 2 renders the scene properly speaking. The stencil buffer is configured this way:

glStencilMask(1);
glStencilFunc(GL_EQUAL, 1, 1); // if the value is NOT 1, please early cull!
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // never write to stencil buffer

现在,我运行我的应用程序.根据模板值更改所选像素的颜色,这意味着模板测试可以正常工作.

Now I run my app. The color of selected pixels is altered based on the stencil value, which means the stencil test works fine.

但是,通过早期的模板剔除,我应该会看到巨大的,惊人的性能提升……但是什么也没发生.我的猜测是模板测试要么在深度测试之后发生,要么甚至在片段着色器被调用之后发生.为什么?

However, I should see a huge, spectacular performance boost with early stencil culling... but nothing happens. My guess is that the stencil test either happens after the depth test, or even after the fragment shader has been called. Why?

nVidia显然具有早期模版剔除的专利: http://www.freepatentsonline.com/7184040.html 是立即启用它吗?

nVidia apparently has a patent on early stencil culling: http://www.freepatentsonline.com/7184040.html Is this the right away for having it enabled?

我正在使用nVidia GeForce GTS 450图形卡. 早期的模板剔除是否可以与此卡一起使用? 使用最新的驱动程序运行Windows 7.

I'm using an nVidia GeForce GTS 450 graphics card. Is early stencil culling supposed to work with this card? Running Windows 7 with latest drivers.

推荐答案

就像早期的Z一样,早期的模具通常使用分层的模具缓冲来完成.

Like early Z, early stencil is often done using hierarchical stencil buffering.

有许多因素可能会阻止分层拼贴正常工作,包括在较旧的硬件上渲染为FBO.但是,在您的示例中进行早期模板测试的最大障碍是在第二遍中为1/(8)位启用了模板写入功能.

There are a number of factors that can prevent hierarchical tiling from working properly, including rendering into an FBO on older hardware. However, the biggest obstacle to getting early stencil testing working in your example is that you've left stencil writes enabled for 1/(8) bits in the second pass.

我建议在第二遍开始时使用glStencilMask (0x00)让GPU知道您不会向模板缓冲区写入任何内容.

I would suggest using glStencilMask (0x00) at the beginning of the second pass to let the GPU know you are not going to write anything to the stencil buffer.

关于早期片段测试的有趣读物,因为它是在当前的硬件中实现的

There is an interesting read on early fragment testing as it is implemented in current generation hardware here. That entire blog is well worth reading if you have the time.

这篇关于早期模版剔除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆