GL_NV_conservative_raster Pixel Coverage Explained

Conservative rasterization via the GL_NV_conservative_raster OpenGL extension alters the core rasterization pipeline by generating fragments for any pixel partially touched by a primitive, rather than requiring the primitive to intersect fixed sample points. This article explains how enabling this extension modifies pixel coverage logic, influences fragment shader execution in GLSL, affects built-in coverage masks like gl_SampleMaskIn, and guarantees continuous spatial evaluation for tasks such as voxelization and collision detection.

Standard Rasterization vs. Conservative Rasterization

In standard OpenGL rasterization, a fragment is generated only if the geometry covers the exact center of a pixel (in single-sample rendering) or designated sample points (in multisample anti-aliasing / MSAA). If a thin triangle or edge clips through a pixel without covering these discrete points, the GPU discards the pixel entirely. This leads to gaps, missed geometry, and aliasing artifacts when evaluating continuous spatial operations.

When GL_NV_conservative_raster is enabled via glEnable(GL_CONSERVATIVE_RASTERIZATION_NV), the hardware switches to an overestimating rasterization model. Under this rule, a fragment is produced if any part of the primitive intersects the square area representing the pixel footprint. Even sub-pixel triangles that touch only a tiny fraction of a pixel corner will reliably generate a fragment.

Changes to Pixel Coverage in GLSL

Enabling conservative rasterization directly impacts how fragments are evaluated inside the GLSL fragment stage:

  1. Fragment Generation Frequency: The fragment shader executes significantly more often along the silhouettes, sharp angles, and sub-pixel details of geometry. Pixels that would normally have a coverage of zero under standard sample-point testing are now considered valid fragment candidates.

  2. The Behavior of gl_SampleMaskIn: In standard MSAA, the input array gl_SampleMaskIn[] indicates which discrete sub-pixel samples were covered by the primitive. Under conservative rasterization, a fragment can be dispatched even when zero actual sample points are covered (for example, if geometry only touches the outer corner of a pixel). Consequently, gl_SampleMaskIn[0] may evaluate to 0 inside the GLSL fragment shader, indicating that while the pixel's bounding area intersected the primitive, none of the standard sample locations were covered.

  3. Interpolation and Pixel Coordinates: By default, inputs marked for interpolation and built-ins like gl_FragCoord retain pixel-center-based coordinates. Because fragments are generated for pixels where the triangle might not actually cover the pixel center, attributes interpolated at the pixel center can extrapolate outside the bounds of the primitive. If standard perspective-correct interpolation is relied upon without clamping or custom centroid evaluation, it can produce out-of-range values in the fragment shader.

  4. Coverage Mask Output (gl_SampleMask): If a GLSL shader outputs to gl_SampleMask[], developers must account for the fact that conservative rasterization only governs generation, not final frame-buffer sample writes. If sample coverage is not manually overridden or conservatively expanded to match the generated fragment, traditional depth and stencil buffers operating at multi-sample locations may discard writes where no physical sample points were intersected.

Key Use Cases in Shader Workflows

  • GPU Voxelization: Traditional rasterization leaves microscopic holes and cracks inside 3D volume grids. Conservative rasterization guarantees full 3D solid or shell continuity by generating voxel write fragments for every intersecting cell.
  • Conservative Depth and Shadow Mapping: Prevents self-shadowing light leaks (peter-panning) by guaranteeing that depth bounding boxes fully cover blocker boundaries.
  • Precise Collision Detection and Binning: Eliminates false negatives in screen-space or grid-based spatial acceleration structures.