Multisample Antialiasing

Document Sample
Multisample Antialiasing Powered By Docstoc
					Multisample Antialiasing
Kurt Akeley CS248 Lecture 6 11 October 2007
http://graphics.stanford.edu/courses/cs248-07/

Overview
Two approaches to antialiasing
 

Pre-filter Over-sample: increase sample rate Works well for points and lines, not for triangles
 

Pre-filter


Can’t reasonably represent pre-filtered triangles Can’t handle occlusion



Can effectively eliminate aliasing with a moderately-large filter window Works well for all primitives


Over-sample


Though less well than pre-filtering for points and lines Let’s see why …
Kurt Akeley, Fall 2007



Cannot eliminate aliasing!


CS248 Lecture 6

Aliasing of fundamentals and harmonics
Imperfect analogy, but useful pedagogical tool:
 

Fundamental: spatial density of edges Harmonics: spectrum introduced by a single edge

Over-sampling cannot overcome increased fundamental frequency


Demo

But over-sampling, followed by a resampling at a lower rate, can overcome harmonics due to a single edge

CS248 Lecture 6

Kurt Akeley, Fall 2007

Practical solution
Over-sample to reduce jaggies due to edges


Optimize for the case of a single edge Band-limit fundamental geometric frequencies


Use other approaches to limit edge rates


E.g., level-of-detail (LOD) model selection



Band-limit image fundamentals and harmonics


E.g., texture MIPmapping

CS248 Lecture 6

Kurt Akeley, Fall 2007

LOD model selection

Low LOD

Medium LOD

High LOD

Demo
CS248 Lecture 6 Kurt Akeley, Fall 2007

Supersampling

CS248 Lecture 6

Kurt Akeley, Fall 2007

Supersampling
Supersampling algorithm:
1. 2. 3. 4. 5.

Over-sample, e.g., at 4x the pixel rate Reconstruct at the over-sampled rate Band-limit to match the pixel rate Resample at the pixel rate to yield pixel values Reconstruct to display

CS248 Lecture 6

Kurt Akeley, Fall 2007

Sample at 4x pixel rate
Pixel-rate fundamental

x

* =

=

f(x)
CS248 Lecture 6

F(s)
Kurt Akeley, Fall 2007

Reconstruct 4x samples

* =

x

Cutoff at ½ the over-sample rate

=

Aliased !

f(x)
CS248 Lecture 6

F(s)
Kurt Akeley, Fall 2007

Band-limit 4x reconstruction to pixel-rate

* =

x

=

f(x)
CS248 Lecture 6

F(s)
Kurt Akeley, Fall 2007

Resample at pixel rate

x

* =

=

f(x)
CS248 Lecture 6

F(s)
Kurt Akeley, Fall 2007

Reconstruct pixel samples

* =

Rect filter approximates LCD display

x

=

f(x)
CS248 Lecture 6

F(s)
Kurt Akeley, Fall 2007

Optimizations
The over-sample reconstruction convolution and the band-limiting convolution steps can be combined:


Convolution is associative


(f * g) * h = f * (g * h)



And g and h are constant


f * (g * h) = f * filter

The filter convolution can be reduced to a simple weighted sum of sample values:
  

The result is sampled at pixel rate So only values at pixel centers are needed These are weighted sums of the 4x samples
Kurt Akeley, Fall 2007

CS248 Lecture 6

Optimized supersampling
Do once
1.

Compute filter by convolving the over-sample reconstruction and band-limiting filters

2.

Compute filter weights for a single pixel sample by sampling the filter waveform
Over-sample Filter to compute pixel values from sample values using the filter weights Reconstruct
Kurt Akeley, Fall 2007

During rendering:
1. 2.

During display
1.

CS248 Lecture 6

Sample Patterns

CS248 Lecture 6

Kurt Akeley, Fall 2007

Sample patterns
Pattern categories  Regular grid  Sparse regular grid  Pseudo-random (stochastic) Filter extent (filter combines reconstruction and band-limiting)  Within the unit square of a pixel  Beyond the unit square Pattern variation  Temporal  Spatial Shading rate vs. geometric sampling rate  Same  Different

CS248 Lecture 6

Kurt Akeley, Fall 2007

Regular-grid sample patterns
Implementation


Regular sample spacing simplifies attribute evaluation


Mask, color, and depth



Large sample count is expensive Poor, especially for screen-aligned edges Good for large numbers of samples

Edge optimization


Image quality


Single Pixel

CS248 Lecture 6

Kurt Akeley, Fall 2007

Sparse regular-grid sample patterns
Implementation


8-rooks pattern

Regular sample spacing simplifies attribute evaluation


Mask, color, and depth



Moderate sample count is cost-effective Good, especially for screen-aligned edges Good for moderate numbers of samples
8-queens pattern

Edge optimization


Image quality


Single Pixel
CS248 Lecture 6 Kurt Akeley, Fall 2007

NVIDIA Quincunx
Quincunx is a special example of a sparse regular grid  Only two samples per pixel (center and one corner)  Filter accesses five samples
 

Quincunx pattern

Center Four corners

Implementation  Regular sample spacing simplifies attribute evaluation


Mask, color, and depth

Single Pixel

Minimal sample count (2 per pixel) is very cost-effective Edge optimization  OK, though less optimal for screen-aligned edges Image quality  Better than without antialiasing

CS248 Lecture 6
This information is from memory, I did not confirm it with NVIDIA.

Kurt Akeley, Fall 2007

Stochastic sample patterns
Implementation


random pattern

Irregular sample spacing complicates attribute evaluation


Mask, color, and depth



Moderate sample count is cost-effective Good, though less optimal for screenaligned edges Excellent for moderate numbers of samples

Edge optimization


Single Pixel

Image quality


CS248 Lecture 6

Kurt Akeley, Fall 2007

Filter extent
Within pixel unit square  Near optimal for small sample counts (<=8)  Equal sample weighting is typical  Easily parallelizable  Simplifies immediate filtering Beyond the pixel unit square  Required for large sample counts (>=16)  Sinc/Gaussian sample weights  Implementation is more difficult  May filter only during display

Single Pixel

“The SAGE Graphics Architecture”, Michael Deering and David Naegle, Proceedings of SIGGRAPH 2002

CS248 Lecture 6

Kurt Akeley, Fall 2007

Variation in sample patterns
Vary patterns
 

Temporally: frame to frame Spatially: pixel to pixel

Improves image quality by replacing regular aliasing patterns with noise Complicates implementation

Interferes with repeatability
 

Violated for temporal variation Requires spatial pattern to be window-aligned
Kurt Akeley, Fall 2007

CS248 Lecture 6

The accumulation buffer
OpenGL mechanism to support supersampling Additional color buffer


Same spatial dimensions as the frame buffer



Greater color resolution and range (-1,1)

Used to accumulate (sum) the results of multiple rendering passes Many applications
   

Supersample antialiasing Motion blur Depth of field blur Combinations of these effects and more …
Kurt Akeley, Fall 2007

CS248 Lecture 6

Accumulation buffer supersampling
glutInitDisplay(… | GLUT_ACCUM); // setup desired rendering modes glAccum(GL_LOAD, 0.0); for (int i=0; i<n; ++i) { // jitter scene to sample location i

// render the entire scene
glAccum(GL_ACCUM, sampleweight[i]); } glAccum(GL_RETURN, 1.0);

CS248 Lecture 6

Kurt Akeley, Fall 2007

Supersampling features and limitations
Features
  

Unconstrained sample locations (stochastic) Unconstrained filter shapes and extents Adaptive quality / performance trade-off


Utilitizing glAccum(GL_MULT, factor);

Limitations



No per-pixel variation in sample pattern
Low performance

CS248 Lecture 6

Kurt Akeley, Fall 2007

Multisampling

CS248 Lecture 6

Kurt Akeley, Fall 2007

Shading rate (another pattern variation)
Shading - the computation of color for a fragment Supersampling  Shades each sample


E.g., accumulation buffer E.g., REYES



Or shades at an independently specified rate


Multisampling is an optimized form of supersampling  Optimized
 

To eliminate jaggies due to edge aliasing For efficiency and performance



Shades each fragment once (potentially huge savings!)
There are no geometric edges in a fragment  Use pre-filtering to eliminate edges in shading source data




Stores color with each sample


There may be edges within a pixel
Kurt Akeley, Fall 2007

CS248 Lecture 6

Multisample implementation (n samples)
struct { float x,y,z,w; float r,g,b,a; } vertex; struct { vertex v0,v1,v2 } triangle; struct { short x,y; bool mask[n]; float depth[n]; float r,g,b,a; } fragment; struct { short R,G,B; int depth[n]; byte r[n],g[n],b[n]; } pixel;
CS248 Lecture 6

Application
Vertex assembly Vertex operations Primitive assembly Primitive operations Rasterization Fragment operations
Point sampling at multisample locations sets mask and computes depths. Color is taken from center-most sample.

Frame buffer
Display

Fragment samples are depth-merged into the multisample buffer, then filtered to the color buffer.
Kurt Akeley, Fall 2007

Multisample rasterization operations
Fragment selection
 

Identify pixels for which fragments are to be generated New: generate fragment if any sample is within the primitive
 

Requires tiled sampling, rather than point sampling Generates more fragments

Attribute assignment
  

Assign attribute values to each fragment Sample color at the center of the pixel (as before) New: compute the Boolean per-sample coverage mask


True if-and-only-if the sample is within the primitive



New: compute depth values for each sample location
Kurt Akeley, Fall 2007

CS248 Lecture 6

Point-sampled fragment selection
Generate fragment if pixel center is inside triangle Implements point-sampled aliased rasterization

CS248 Lecture 6

9 fragments generated

Kurt Akeley, Fall 2007

Tiled fragment selection
Generate fragment if unit square intersects triangle Implements multisample rasterizations


4x4 sample pattern with unit-square filter extent

CS248 Lecture 6

21 fragments generated

Kurt Akeley, Fall 2007

Multisampling in OpenGL

“Multisampling is trivial to add to an application.”
― OpenGL Programming Guide

glutInitDisplay(… | GLUT_MULTISAMPLE); glEnable(GL_MULTISAMPLE); // render as usual, almost everything works

CS248 Lecture 6

Kurt Akeley, Fall 2007

Occlusion revisited
The conundrum:
  

Pre-filtering blurs geometry Accurate occlusion requires sampling of exact (sharply defined) geometry Can’t have both 

A partial solution:


Pre-filtered geometry cannot occlude accurately


occluded objects bleed through the seems



But pre-filtered geometry can be occluded by exact geometry

CS248 Lecture 6

Kurt Akeley, Fall 2007

Getting the best of both approaches
glutInitDisplay(…, GLUT_MULTISAMPLE); // setup occlusion modes (e.g. depth buffering) glEnable(GL_MULTISAMPLE); // render triangles (must happen first) glDisable(GL_MULTISAMPLE); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); // render lines and/or points (must happen last)

glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
CS248 Lecture 6 Kurt Akeley, Fall 2007

Summary
Supersampling does not eliminate aliasing  It can reduce jaggies  It must be used with other pre-filtering to eliminate aliasing Multisampling  Is supersampling with pixel-rate shading


Optimized for efficiency and performance Works for all rendering primitives Interacts well with other OpenGL mechanisms – Especially fragment/frame buffer operations Pre-filtering does not To optimize point and line quality



Is a full-scene antialiasing technique
 

 

Handles occlusions correctly


Can be used in conjunction with pre-filter antialiasing


CS248 Lecture 6

Kurt Akeley, Fall 2007

Assignments
Before next Tuesday’s class, read
 

FvD 5 OpenGL multisample specification(s)
 

http://www.opengl.org/registry/specs/SGIS/multisample.txt http://www.opengl.org/registry/specs/ARB/multisample.txt

Project 2:


Will be assigned next Tuesday

CS248 Lecture 6

Kurt Akeley, Fall 2007

End

CS248 Lecture 6

Kurt Akeley, Fall 2007