Here's the things, I am trying to do deferred shading with multisample texture. To create the GBuffer, I create a framebuffer with mutlisample texture attachments to draw on and a framebuffer with normal texture attachments for copying result. (Since I can't directly read multisample texture).
After lighting pass, I discoverd edges are not properly anti-aliased, see the picture below.
(you can see the jig-saw between the light and shadow)
So I look into the gbuffer content, and it appears that Position
buffer which use float
texture format are NOT anti-aliased. But Albedo
buffer which use unsigned byte
texture format looks good.
Here're how those buffer looks, the upper one is the Position
buffer and the bottom one is the Albedo
buffer
Can somebody explain this? Am I doing something wrong?
I create a framebuffer with mutlisample texture attachments to draw on and a framebuffer with normal texture attachments for copying result.
There's your problem; that's not going to actually work.
Doing a multisample resolve before your lighting passes makes no sense. You're effectively blending between two positions on different objects. That's not going to produce a meaningful result.
If you're going to do multisampling in deferred rendering, you have to use per-sample shading in the fragment shader and read each sample (with texelFetch
on sampler2DMS
) to do your lighting passes. You would also be writing to a multisample image.
Only that last image is the one that gets the multisample resolve operation done on it.