PDA

View Full Version : MSAA in OpenGL 4.0



SasMaster
07-29-2012, 01:54 AM
Hi All. I am trying to understand different methods of MSAA in GL 4.0 (CORE) I started with GL 3.3 and used the book "OpenGL Superbible 5" as a primary reference to modern pipeline.In the app I have been working on I needed to implement MSAA manuall because I use FBOs for offscreen rendering.The approach outlined in SB5 looks complex where the sample weights are calculated on CPU then passed to shaders and used by texelFetch . But then I took a look into GL 4.0 specs and found a new "Adaptive multisampling and per-sample processing" technique exposed via GL_ARB_sample_shading. It looks really simple to implement :Just enable multisampling , attach mulitsample texture to the FBO ,then in fragment shader
use interpolateAtSample + gl_sampleID . Apparently it looks like this approach does the job.But I would like to know if this is how the optimal MSAA should be done in GL 4.0 ?

Dark Photon
07-30-2012, 05:02 AM
If you really do want MSAA (Multisample Antialiasing), and "optimal" performance MSAA at that, with off-screen render targets, then:


Create multisample textures (or renderbuffers) as render targets (color, depth/stencil, etc.)
Attach to an FBO
Bind the FBO as the DRAW_FRAMEBUFFER
glEnable( GL_MULTISAMPLE )
Render to it
Use glBlitFramebuffer to downsample from multisample (per pixel) to single sample (per pixel)


That gets you standard MSAA rasterization and MSAA downsample filtering. This is very efficient because the fragment shader only runs once per pixel, but depth/stencil comparisons happen once per "sample" (i.e. several times per pixel), giving you nice antialiased geometry edges without a lot of extra expense.

Optimal performance generally would not include doing things like sample shading, which effectively allows you to run the fragment shader multiple times per pixel rather than once. This can get expensive very quickly.