OpenGL的模板缓存或操作? [英] OpenGL stencil buffer OR operation?

查看:366
本文介绍了OpenGL的模板缓存或操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这是可以做到的,但它是值得一试。我使用的模板缓存使用该算法减少了延迟渲染光量透支(当相机外卷):

I'm not sure if this is possible to do, but it's worth a shot. I'm using the stencil buffer to reduce overdraw for light volumes in a deferred renderer using this algorithm (when the camera is outside the volume):


  1. 使用廉价的着色器,退与深度测试设置为LEQUAL的面孔,在模板缓存标记它们。

  2. 使用昂贵的灯光渲染,绘制设置为GEQUAL深度测试前脸。

这将导致只在像素被遮蔽的光量。绘制多个灯时,这个问题就来了。首先,由于状态的改变是昂贵的,它可能不是对每个光便宜和昂贵的着色器之间反复开关最好的主意。理想情况下,我想通过渲染8卷光用廉价的着色后8昂贵的着色光量取印模缓冲区的8位的优势。但是,出现问题时,光重叠,因为没有办法知道哪些像素属于哪个灯。

This will cause only pixels within the light volume to be shaded. The problem with this comes when drawing multiple lights. First, since state changes are expensive, it's probably not the best idea to repeatedly switch between the cheap and expensive shader for each light. Ideally I'd like to take advantage of all 8 bits of the stencil buffer by rendering 8 light volumes with the cheap shader followed by 8 light volumes with the expensive shader. However, issues arise when lights overlap, as there's no way to tell which pixels belong to which lights.

,想到解决的办法是使用1位每光模板缓冲区。因此,对于光 N 标记名词个在廉价通模板缓冲一下,然后只呈现与昂贵的通期间位像素。

The solution that comes to mind would be to use 1 bit in the stencil buffer per light. So, for light n, mark the nth bit in the stencil buffer in the cheap pass, then only render pixels with that bit on during the expensive pass.

我以前没有使用模板缓冲,但是从我读什么这似乎并不可能。对于这个工作,我不得不用位或和模板函数都必须按位与设置模板缓存。然而,在模板缓存我能看到的唯一操作是:KEEP,ZERO,更换,INCR,DECR,并颠倒,唯一的功能是:从不,始终,小于,等于,LEQUAL,GEQUAL,更大,NOTEQUAL。

I haven't used the stencil buffer before, but from what I'm reading this doesn't seem possible. For this to work I'd have to set the stencil buffer using bitwise OR and the stencil function would have to be bitwise AND. However, the only operations on the stencil buffer I can see are: KEEP, ZERO, REPLACE, INCR, DECR, and INVERT, and the only functions are: NEVER, ALWAYS, LESS, EQUAL, LEQUAL, GEQUAL, GREATER, and NOTEQUAL.

有没有办法以某种方式得到使用模板缓存此OR和AND运算的行为呢?如果没有,是否有其他的方法来有效地使光量?

Is there any way to somehow get this OR and ANDing behavior using the stencil buffer? And if not, is there an alternative approach to efficiently rendering light volumes?

推荐答案

要获取或运算更新行为,使用 glStencilMask 结合 GL_REPLACE 。为了让AND运算测试行为,使用 glStencilFunc 屏蔽参数结合 GL_EQUAL 。在这两种情况下,你需要在 REF 参数 glStencilFunc 0xFF的

To get ORing update behavior, use glStencilMask combined with GL_REPLACE. To get ANDing test behavior, use the glStencilFunc mask parameter combined with GL_EQUAL. In both cases, you'll want the ref parameter to glStencilFunc to be 0xff.

这篇关于OpenGL的模板缓存或操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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