Sampling Location of MSAA

one sampling per pixel

When MSAA uses nn subsamples per pixel, the number of covered subsamples among the total nn subsamples determines how much the pixel color contributes to the framebuffer. However, it does not imply that the fragment shader should run nn times per pixel for shading. In fact, MSAA computes the surface’s shade once per pixel and shares this result among the subsamples. Pixels have nn sample locations per fragment, each with their own color and z-depth, but the fragment shader is evaluated only once for each object fragment applied to the pixel.

sampling outside of the primitive


With single sampling, fragments are only generated if the pixel center is covered. Sampling happens at the pixel center, and interpolation and shading only occur within the primitive. However, in multisampling, fragments are generated if any of the subsamples is in the primitive. If all MSAA positional subsamples are covered by the fragment, the shading sample is evaluated at the center of the pixel. Instead, if the fragment covers fewer positional subsamples, the sampling location could be the pixel center, one of the sample locations within the pixel, or an arbitrary location. Most importantly of all, this subsample may lie outside of the actual primitive being rendered, so that it is extrapolated, not interpolated. This may cause a problem like when using a square root function only defined for positive numbers since the extrapolation might generate a negative number.



The centroid qualifier is used to prevent the extrapolation problem. OpenGL allows the sampling to choose the ideal centroid or any location that is inside the intersection of the pixel square and the primitive, such as a sample point or a pixel center. So, this qualifier ensures that all sampling uses interpolation, never extrapolation. The reason why this qualifier is not default, however, is that it is more expensive than evaluating at the center, and the derivatives like dFdx or dFdy are less accurate since they have irregular spacing between evaluations.

Separately, the sample qualifier forces OpenGL to interpolate to the location of the particular sample for each generated fragment. This is only useful with per-sample shading.


[1] Tomas Akenine-Mller, Eric Haines, and Naty Hoffman. 2018. Real-Time Rendering, Fourth Edition (4th. ed.). A. K. Peters, Ltd., USA.

[2] Anti Aliasing

[3] GLSL: Center or Centroid? (Or When Shaders Attack!)

© 2024. All rights reserved.