430 likes | 518 Views
Pre-Filter Antialiasing. Kurt Akeley CS248 Lecture 4 4 October 2007 http://graphics.stanford.edu/courses/cs248-07/. Review. Aliasing. Aliases are low frequencies in a rendered image that are due to higher frequencies in the original image. Jaggies. Original:. Rendered:.
E N D
Pre-Filter Antialiasing Kurt Akeley CS248 Lecture 4 4 October 2007 http://graphics.stanford.edu/courses/cs248-07/
Aliasing Aliases are low frequencies in a rendered image that are due to higher frequencies in the original image.
Jaggies Original: Rendered:
Convolution theorem Let fand g be the transforms of f and g. Then Something difficult to do in one domain (e.g., convolution) may be easy to do in the other (e.g., multiplication)
Aliased sampling of a point (or line) * x = = f(x) F(s)
Aliased reconstruction of a point (or line) * x sinc(x) = = f(x) F(s)
Reconstruction error (actually none!) Original Signal Phase matters! AliasedReconstruction
Sampling theory Fourier theory explains jaggies as aliasing. For correct reconstruction: • Signal must be band-limited • Sampling must be at or above Nyquist rate • Reconstruction must be done with a sinc function All of these are difficult or impossible in the general case. Let’s see why …
Why band-limiting is difficult Band-limiting primitives prior to rendering compromises image assembly in the framebuffer • Band-limiting changes (spreads) geometry • Finite spectrum infinite spatial extent • Interferes with occlusion calculations • Leaves visible seams between adjacent triangles Can’t band-limit the final (framebuffer) image • There is no final image, there are only samples • If the sampling is aliased, there is no recovery Nyquist-rate sampling requires band-limiting
Why ideal reconstruction is difficult In theory: • Required sinc function has • Negative lobes (displays can’t produce negative light) • Infinite extent (cannot be implemented) In practice: • Reconstruction is done by a combination of • Physical display characteristics (CRT, LCD, …) • The optics of the human eye • Mathematical reconstruction (as is done, for example, in high-end audio equipment) is not practical at video rates.
Two antialiasing approaches are practiced Pre-filtering (this lecture) • Band-limit primitives prior to sampling • OpenGL ‘smooth’ antialiasing Increased sample rate (future lecture) • Multisampling, super-sampling • OpenGL ‘multisample’ antialiasing
* x = = f(x) F(s) Ideal point (or line cross section) sinc(x) sinc(x)
* x = = f(x) F(s) Band-limited unit disk sinc(x) sinc(x)
* x = = f(x) F(s) Almost-band-limited unit disk sinc(x) sinc2(x) sinc3(x) Finite extent!
Equivalences These are equivalent: • Low-pass filtering • Band-limiting • (Ideal) reconstruction These are equivalent: • Point sampling of band-limited geometry • Weighted area sampling (FvD 3.17.3) of full-spectrum geometry
Pre-filter pros and cons Pros • Almost eliminates aliasing due to undersampling • Allows pre-computation of expensive filters • Great image quality (with important caveats!) Cons • Can’t handle interactions of primitives with area • Reconstruction is still a problem
Pre-filtering in the vertex pipeline Application struct { float x,y,z,w; float r,g,b,a;} vertex; Vertex assembly Vertex operations struct { vertex v0,v1,v2 } triangle; Primitive assembly Primitive operations Point sampling of pre-filtered primitives sets fragment alpha value struct { short int x,y; float depth; float r,g,b,a;} fragment; Rasterization Fragment operations Fragments are blended into the frame buffer struct { int depth; byte r,g,b,a;} pixel; Framebuffer Display
Pre-filter point rasterization point being sampled at the center of this pixel alpha
Pre-filter line rasterization line being sampled at the center of this pixel alpha
Point size Xscreen frac bits Yscreen frac bits Pixel index 3 4 4 4 Pre-filtered primitive stored in table Supports pre-computation Simplifies distance calculation (square root in table) Can compensate for reconstruction errors • Sampling and reconstruction go hand-in-hand Fragment Alpha 32K x 8 8
Line slope Xscreen frac bits Yscreen frac bits Pixel index Line width 5 4 4 4 3 Line tables get big! Fragment Alpha 1M x 8 8
Triangle pre-filtering is difficult Three arbitrary vertex locations define a huge parameter space • Resulting table is too large to implement Edges can be treated independently • But this is a poor approximation near vertexes, where two or three edges affect the filtering • And triangles can be arbitrarily small
Pre-filtering in the vertex pipeline Application struct { float x,y,z,w; float r,g,b,a;} vertex; Vertex assembly Vertex operations struct { vertex v0,v1,v2 } triangle; Primitive assembly Primitive operations Point sampling of pre-filtered primitives sets fragment alpha value struct { short int x,y; float depth; float r,g,b,a;} fragment; Rasterization Fragment operations Fragments are blended into the frame buffer struct { int depth; byte r,g,b,a;} pixel; Framebuffer Display
Ideal pre-filtered image assembly Impulse-defined points and lines have no area So they don’t occlude each other So fragments should be summed into pixels C’pixel = Cpixel + Afrag Cfrag
Practical pre-filtered image assembly Frame buffers have limited numeric range So summation causes overflow or clamping ‘Uncorrelated’ clamped blend yields good results • But clamping R, G, and B independently causes color shift ‘Anti-correlated’ clamped blend is an alternative • Best for rendering pre-filtered triangles • sorted front-to-back • But requires frame buffer to store alpha values C’pixel = (1-Afrag)Cpixel + Afrag Cfrag
Anti-correlated blend function i = min(Afrag, (1-Apixel)) A’pixel = Apixel + I C’pixel = Cpixel + i Cfrag
OpenGL API glEnable(GL_POINT_SMOOTH); glEnable(GL_LINE_SMOOTH); glEnable(GL_POLYGON_SMOOTH); glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); // sum glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // blend glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE); // saturate
Resolution of the human eye Eye’s resolution is not evenly distributed Foveal resolution is ~20x peripheral Systems can track direction of view, draw high-resolution inset Flicker sensitivity is higher in periphery One eye can compensate for the other Research at NASA suggests high-resolution dominant display Human visual system is well engineered …
Imperfect optics - linespread Ideal Actual
* x = = f(x) F(s) Filtering
* * = = f(x) f(x) Frequencies are selectively attenuated
Selective attenuation (cont.) * * = = f(x) f(x)
Optical “imperfections” improve acuity Image is pre-filtered Cutoff is approximately 60 cpd Cutoff is gradual – no ringing Aliasing is avoided Foveal cone density is 120 / degree Cutoff matches retinal Nyquist limit Vernier acuity is improved Foveal resolution is 30 arcsec Vernier acuity is 5-10 arcsec Linespread blur includes more sensors
Summary Two approaches to antialiasing are practiced • Pre-filtering (this lecture) • Increased sample rate Pre-filter antialiasing • Works well for non-area primitives (points, lines) • Works poorly for area primitives (triangles, especially in 3-D) The human eye is well adapted • Sampling theory helps us here too
Assignments Before Thursday’s class, read • FvD 3.1 through 3.14, Rasterization Project 1: • Continue work • Demos Wednesday 10 October