MSAA的抗锯齿问题,使用深度和FBO绘制CSG [英] Anti-Aliasing issue with MSAA, drawing CSG with depth and FBO

查看:193
本文介绍了MSAA的抗锯齿问题,使用深度和FBO绘制CSG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于现代OpenGL版本,我已经重新实现了 OpenCSG .

I have reimplemented OpenCSG for modern OpenGL version.

PixelFormatAttributes:

PixelFormatAttributes:

NSOpenGLPFAColorSize    , 24 ,
NSOpenGLPFAAlphaSize    , 8  ,
NSOpenGLPFADepthSize    , 32 ,
NSOpenGLPFAStencilSize  , 8  ,
NSOpenGLPFAAccelerated  ,
NSOpenGLPFADoubleBuffer ,
NSOpenGLPFASupersample  ,
NSOpenGLPFASampleBuffers, 1  ,
NSOpenGLPFASamples      , 4  ,

FBO规格:(尝试使用多样本渲染到FBO,但线条变得更清晰可见,请看底部的屏幕截图)
-创建的纹理具有2的功效,GL_RGBA(尝试GL_RGBA8和GL_RGBA32F)
-GL_DEPTH24_STENCIL8(尝试GL_DEPTH32_STENCIL8,无结果)

FBO specs: (tried render to FBO with multisample, but lines getting more strong and visible, look on screenshot at bottom)
- created texture with power of 2, GL_RGBA (tried GL_RGBA8 and GL_RGBA32F)
- GL_DEPTH24_STENCIL8 (tried GL_DEPTH32_STENCIL8, no result)


简单的算法Goldfeather:


Simply algorithm Goldfeather:

while (i < depth complexity) {
    take channel for render
       merge layers if no free channel 
    render each layer with stencil func, mask and depth params to channel (FBO)
}
merge layers (taking texture from FBO and render objects again with applying shader below)


在着色器中,我具有用于合并的代码(来自FBO的结果纹理在用于测试的渲染之上重叠,位于是OpenCSG,它是setupProjectiveTexture ):


In shader I have code for merging (result texture from FBO overlaps on top of rendering for testing, in OpenCSG it's setupProjectiveTexture):

     vec2 ndcPos = gl_FragCoord.xy / sizetexture.xy;
     vec4 maskColor = texture2D(maskTexture, ndcPos.xy);
     if (maskColor[channel] < 0.5) {
        discard;
     }

看上去像是在FBO上没有足够清晰的纹理或尺寸不正确之后.

Looks like after FBO getting not enough clear texture or not right size.

编辑:
这些线仅出现在减去网格的重叠位置.


Those lines appears only in overlapping places of subtracting mesh.


修复了渲染到非MSAA FBO并在结果上应用FXAA的问题.

EDIT 2:
Fixed with rendering to non MSAA FBO and applying FXAA on result.

推荐答案

不确定我的解释正确吗.您要从着色器中采样哪种纹理?

Not sure I got your explanations right. What kind of texture are you sampling from in the shader?

我不知道您要实现的算法的细节,但是如果该纹理包含已经完成多样本采集的一些先前计算的结果,我真的不确定您是否可以将该结果用于整个片段(及其所有样本).遮罩的边缘会褪色,这似乎是问题所在.

I don't know the specifics of the algorithm you're implementing but if that texture contains the results of some previous calculations with multisample gathering already done, I'm really not sure you can use that result for a whole fragment (and all of its samples). The mask is going to fade at edges, which seems to be the problem here.

也许您应该手动"进行样品采集,例如使用sampler2DMS并在着色器中使用texelFetch读取单个样本.

Maybe you should do sample gathering "by hand", e.g. use a sampler2DMS and read individual samples with texelFetch in the shader.

另一种解决方案可能是在第一遍中将gl_SampleMask设置为全1,以防止边界褪色.

Another solution might be to set gl_SampleMask to all 1's in the first pass to prevent the fading at borders.

这篇关于MSAA的抗锯齿问题,使用深度和FBO绘制CSG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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