Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I never really fully understood this, or found an article which explained all the steps in a friendly way.

I'll start with what I do know already (which I hope do not contain misconceptions). I'm pretty sure allocating a multi-sampled frame buffer requires as many times the memory (of a regular buffer) as the number of samples (N). This makes sense because each pixel may be sampled up to N times.

During rasterization, the GPU generates a fragment for the MS frame buffer by testing if each sample is inside of the geometry being drawn. This is what provides edge anti-aliasing. Each sample produces a fragment.

I'm unsure about what occurs when all samples of a pixel are inside the geometry. How many fragments are generated? Is this configurable? What if I want to sample the "inside" pixels 4 times, and the edge pixels 16 times? This would require a 16x MS frame buffer.

Are there other differences? It seems like if the fragment shader is run once on each sample then we are left with something not much different from basic supersampling with the exception of jittered sample locations.

Actually, I'm also a bit unsure about what a frogment really is. It seems like a fragment shader gets (can get) executed more than once per pixel in a multi sampled scene, however this doesn't seem to necessarily mean that a fragment is more related to the sample than the pixel. Is a fragment best thought of as a sample, a pixel, or something else?

share|improve this question
    
I found an article written a few months after this question was written which goes in depth and was very helpful as well. –  Steven Lu Jul 8 at 8:59

1 Answer 1

Multisampling runs the pixel shader once per pixel, while visibility (geometry coverage, depth/stencil tests, etc.) are done per sample. The same color output from the pixel shader is replicated to all the samples that pass the visibility tests. The fact that the pixel shader is only run once per pixel is what makes MSAA faster than supersampling.

In fact, in D3D10-11 you can cause the pixel shader to run per-sample if you really want to, by using the SV_SampleIndex parameter, or by marking an interpolated parameter with the sample keyword; see the MSDN for more. The OpenGL equivalent is the ARB_sample_shading extension (also part of core OpenGL since 4.0). If you do this, then it would turn into just plain supersampling. This is not the normal use case, though.

There is currently not a way to do something like run the PS 4x per pixel while having MSAA at 16x. Your only choices are to run the PS per-pixel or per-sample. But you could achieve what you described by having a 4x larger buffer that is 4x multisampled, then resolving the MSAA and downsampling the extra 4x yourself before displaying.

You're right that a multi-sampled frame buffer takes as much memory as a super-sampled one - although GPUs often internally use some sort of compression to reduce the memory bandwidth required, they still have to allocate the full amount of memory as a fallback, in case of "bad" pixels that aren't amenable to compression.

A "fragment" means a sample-sized chunk of a triangle (or other primitive, technically). As Nicol Bolas says, "A fragment is the state generated by the rasterization process for a particular sample, which will be used in various processing", e.g. depth/stencil testing. So yes, when using multisampling multiple fragments may be generated for the same primitive in the same pixel. However, the fragment shader still normally runs once per pixel.

share|improve this answer
    
@NicolBolas OK, I stand corrected. Edited. –  Nathan Reed Jul 24 '12 at 23:22
    
Doesn't this mean that the OpenGL fragment shader is more of a pixel shader than a fragment shader, if it generally runs on a per-pixel basis rather than on a per-fragment basis? –  Steven Lu Jul 25 '12 at 16:38
1  
Hmm. I found this: "Note: Using the gl_SamplePosition variable in any way will cause the fragment shader to be evaluated per-sample. Since the whole point of multisampling is to avoid that, it's probably not a good idea to do so unless you really need it." from opengl.org/wiki/GLSL_Predefined_Variables –  Steven Lu Jul 25 '12 at 16:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.