Deferred shading w/ fbo_multisample


I want to use framebuffer_multisample and framebuffer_blit for AA with deferred shading. The idea is to render all the g-buffer contents (normals, eye-space positions, material indices etc.) into FBO render buffers, and downsample them & copy them with framebuffer_blit to textures for further processing.

However, I noticed one thing: if I use multisampled FBOs, I essentially multisample the g-buffer, and not the end result, while regular AA in forward renderers does. Edge detection/blur algorithms for deferred shading also operate on the result. But is the difference visible? Does it matter in practice for the image quality that the multisampling happens on the g-buffer?

You’ll have a hard time with this approach. At edges, the downsampled buffer will contain positions, that don’t fit any object you rendered, normals that point into wrong directions and material indices that don’t match any of your materials (i.e. (mat1+mat20+mat22+mat50)/4 = mat23.25 huh?).
This “broken” data will corrupt the lighting (done with the downsampled gbuffer) and this will in turn further introduce more aliasing due to unintended lighting “sparkles”.

Try to do lighting at the samples, before downsampling. ARB_texture_multisample (and maybe ARB_sample_shading) might help you here.

Well, certain channels do fit somewhat for multisampling. Linear Z for example, or albedo. Position fits as well, if the positions lie in view space (because then, X and Y are always aligned to the screen). Normals MAY fit, even though the lerp ignores the angular momentum of the normals. As for the index, since I access material BRDF data in a 3D texture, fractionals aren’t that bad, and I can always truncate the number.

The thing is, I end up putting parts of the G-buffer channels in multisampled textures/renderbuffers anyway, otherwise the source data for the lighting would be aliased already. Without multisample textures, the lighting pass would downsample the G-buffer channels immediately, e.g. all of the lighting calculations would happen in non-multisampled space. Not sure how much of a visual impact this has.