如何在 glsl 中检测片段是否是多重采样的?
是否有任何快速(为了性能)方法可以在 glsl 中检测片段是否已被多重采样,但在第二(轻)通道中使用第一通道渲染的纹理。或者 opengl 如何存储有关多重采样的信息?
Is there any fast(for performance) way to detect in glsl if fragment has been multisampled, but in second(light) pass using textures where been 1st pass rendered. Or how is opengl storing informations about multisampling?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
他们有好几个。通常的方法是检查当前的坐标(gl_FragCoord)是否为(0.5,0.5)。如果是,则意味着您位于多边形的中间:仅采样一次。
它不是,它可能是 4 个(对于 4xMSAA)旋转方角之一:您处于边缘,并且 openGL 检测到仅一个样本是不够的。
另请参阅http://www.opengl.org/pipeline/article/vol003_6/
不过,为了在第二遍中获得此信息,您必须将其存储在 g 缓冲区中。
编辑:这是我刚刚完成的代码片段。在 gtx 470 上使用 1024x1024 4xMSAA 纹理进行测试。
顶点着色器:
片段着色器:
边缘为绿色,多边形中心为红色。
对于您原来的问题,我向您推荐这篇文章: http://www.gamasutra .com/view/feature/3591/resolve_your_resolves.php
They are several. The usual one is to check is the current's coordinates (gl_FragCoord) are (0.5, 0.5). If it is, it means that you're in the middle of a polygon : it's sampled only once.
It it's not, it's probably one of the 4 (for 4xMSAA) rotated-square-corners : You're on an edge, and openGL has detected that one sample only isn't enough.
See also http://www.opengl.org/pipeline/article/vol003_6/
In order to have this information in a second pass, you'll have to store it in a g-buffer, though.
EDIT : Here is a code snippet that I've just done. Tested on gtx 470 with a 1024x1024 4xMSAA texture.
Vertex shader :
Fragment shader :
Edges are green, center of polygon is red.
For your original question, I recommend you this article : http://www.gamasutra.com/view/feature/3591/resolve_your_resolves.php
选择像素格式时,多重采样会在上下文创建时激活。之后您将无法关闭或打开它。但是,当渲染到纹理时,无论上下文的设置是什么,OpenGL都不会使用多重采样。
http://www.opengl.org/wiki/Multisampling
Multisampling is activated at contex creation when choosing the pixel format. After that you can't turn it off or on. But when you render to a texture OpenGL will not use multisampling regardless what the setting for the contex is.
http://www.opengl.org/wiki/Multisampling