Download presentation
Presentation is loading. Please wait.
1
Pre-Filter Antialiasing Kurt Akeley CS248 Lecture 4 4 October 2007 http://graphics.stanford.edu/courses/cs248-07/
2
CS248 Lecture 4Kurt Akeley, Fall 2007 Review
3
CS248 Lecture 4Kurt Akeley, Fall 2007 Aliasing Aliases are low frequencies in a rendered image that are due to higher frequencies in the original image.
4
CS248 Lecture 4Kurt Akeley, Fall 2007 Jaggies Original: Rendered:
5
CS248 Lecture 4Kurt Akeley, Fall 2007 Convolution theorem Let f and 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)
6
CS248 Lecture 4Kurt Akeley, Fall 2007 Aliased sampling of a point (or line) x = * = F(s)f(x)
7
CS248 Lecture 4Kurt Akeley, Fall 2007 Aliased reconstruction of a point (or line) x = * = F(s)f(x) sinc(x)
8
CS248 Lecture 4Kurt Akeley, Fall 2007 Reconstruction error (actually none!) Original Signal Aliased Reconstruction Phase matters!
9
CS248 Lecture 4Kurt Akeley, Fall 2007 Sampling theory Fourier theory explains jaggies as aliasing. For correct reconstruction: n Signal must be band-limited n Sampling must be at or above Nyquist rate n Reconstruction must be done with a sinc function All of these are difficult or impossible in the general case. Let’s see why …
10
CS248 Lecture 4Kurt Akeley, Fall 2007 Why band-limiting is difficult Band-limiting primitives prior to rendering compromises image assembly in the framebuffer n Band-limiting changes (spreads) geometry n Finite spectrum infinite spatial extent n Interferes with occlusion calculations n Leaves visible seams between adjacent triangles Can’t band-limit the final (framebuffer) image n There is no final image, there are only samples n If the sampling is aliased, there is no recovery Nyquist-rate sampling requires band-limiting
11
CS248 Lecture 4Kurt Akeley, Fall 2007 Why ideal reconstruction is difficult In theory: n Required sinc function has n Negative lobes (displays can’t produce negative light) n Infinite extent (cannot be implemented) In practice: n Reconstruction is done by a combination of n Physical display characteristics (CRT, LCD, …) n The optics of the human eye n Mathematical reconstruction (as is done, for example, in high-end audio equipment) is not practical at video rates.
12
CS248 Lecture 4Kurt Akeley, Fall 2007 Two antialiasing approaches are practiced Pre-filtering (this lecture) n Band-limit primitives prior to sampling n OpenGL ‘smooth’ antialiasing Increased sample rate (future lecture) n Multisampling, super-sampling n OpenGL ‘multisample’ antialiasing
13
CS248 Lecture 4Kurt Akeley, Fall 2007 Pre-Filter Antialiasing
14
CS248 Lecture 4Kurt Akeley, Fall 2007 Ideal point (or line cross section) x = * = F(s)f(x) sinc(x)
15
CS248 Lecture 4Kurt Akeley, Fall 2007 Band-limited unit disk x = * = F(s)f(x) sinc(x)
16
CS248 Lecture 4Kurt Akeley, Fall 2007 Almost-band-limited unit disk x = * = F(s)f(x) sinc(x) sinc 2 (x) Finite extent! sinc 3 (x)
17
CS248 Lecture 4Kurt Akeley, Fall 2007 Equivalences These are equivalent: n Low-pass filtering n Band-limiting n (Ideal) reconstruction These are equivalent: n Point sampling of band-limited geometry n Weighted area sampling (FvD 3.17.3) of full-spectrum geometry
18
CS248 Lecture 4Kurt Akeley, Fall 2007 Pre-filter pros and cons Pros n Almost eliminates aliasing due to undersampling n Allows pre-computation of expensive filters n Great image quality (with important caveats!) Cons n Can’t handle interactions of primitives with area n Reconstruction is still a problem
19
CS248 Lecture 4Kurt Akeley, Fall 2007 Pre-filtering in the vertex pipeline Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations struct { float x,y,z,w; float r,g,b,a; } vertex; struct { vertex v0,v1,v2 } triangle; struct { short int x,y; float depth; float r,g,b,a; } fragment; struct { int depth; byte r,g,b,a; } pixel; Framebuffer Point sampling of pre- filtered primitives sets fragment alpha value Fragments are blended into the frame buffer
20
CS248 Lecture 4Kurt Akeley, Fall 2007 Pre-filter point rasterization alpha point being sampled at the center of this pixel
21
CS248 Lecture 4Kurt Akeley, Fall 2007 Pre-filter line rasterization line being sampled at the center of this pixel alpha
22
CS248 Lecture 4Kurt Akeley, Fall 2007 Pre-filtered primitive stored in table Supports pre-computation Simplifies distance calculation (square root in table) Can compensate for reconstruction errors n Sampling and reconstruction go hand-in-hand 3 Point size 4 X screen frac bits 4 Y screen frac bits 4 Pixel index 8 Fragment Alpha 32K x 8
23
CS248 Lecture 4Kurt Akeley, Fall 2007 Line tables get big! 5 Line slope 4 X screen frac bits 4 Y screen frac bits 4 Pixel index 8 1M x 8 3 Line width Fragment Alpha
24
CS248 Lecture 4Kurt Akeley, Fall 2007 Triangle pre-filtering is difficult Three arbitrary vertex locations define a huge parameter space n Resulting table is too large to implement Edges can be treated independently n But this is a poor approximation near vertexes, where two or three edges affect the filtering n And triangles can be arbitrarily small
25
CS248 Lecture 4Kurt Akeley, Fall 2007 Pre-filtering in the vertex pipeline Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations struct { float x,y,z,w; float r,g,b,a; } vertex; struct { vertex v0,v1,v2 } triangle; struct { short int x,y; float depth; float r,g,b,a; } fragment; struct { int depth; byte r,g,b,a; } pixel; Framebuffer Point sampling of pre- filtered primitives sets fragment alpha value Fragments are blended into the frame buffer
26
CS248 Lecture 4Kurt Akeley, Fall 2007 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 = C pixel + A frag C frag
27
CS248 Lecture 4Kurt Akeley, Fall 2007 Practical pre-filtered image assembly Frame buffers have limited numeric range So summation causes overflow or clamping ‘Uncorrelated’ clamped blend yields good results n But clamping R, G, and B independently causes color shift ‘Anti-correlated’ clamped blend is an alternative n Best for rendering pre-filtered triangles n sorted front-to-back n But requires frame buffer to store alpha values C’ pixel = (1-A frag )C pixel + A frag C frag
28
CS248 Lecture 4Kurt Akeley, Fall 2007 Anti-correlated blend function i = min(A frag, (1-A pixel )) A’ pixel = A pixel + I C’ pixel = C pixel + i C frag
29
CS248 Lecture 4Kurt Akeley, Fall 2007 Demo
30
CS248 Lecture 4Kurt Akeley, Fall 2007 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
31
CS248 Lecture 4Kurt Akeley, Fall 2007 Filtering and Human Perception
32
CS248 Lecture 4Kurt Akeley, Fall 2007 Resolution of the human eye Eye’s resolution is not evenly distributed n Foveal resolution is ~20x peripheral n Systems can track direction of view, draw high- resolution inset n Flicker sensitivity is higher in periphery One eye can compensate for the other n Research at NASA suggests high-resolution dominant display Human visual system is well engineered …
33
CS248 Lecture 4Kurt Akeley, Fall 2007 Imperfect optics - linespread IdealActual
34
CS248 Lecture 4Kurt Akeley, Fall 2007 Linespread function
35
CS248 Lecture 4Kurt Akeley, Fall 2007 Filtering x = * = F(s)f(x)
36
CS248 Lecture 4Kurt Akeley, Fall 2007 Frequencies are selectively attenuated = * = f(x) *
37
CS248 Lecture 4Kurt Akeley, Fall 2007 Selective attenuation (cont.) = * = f(x) *
38
CS248 Lecture 4Kurt Akeley, Fall 2007 Modulation transfer function (MTF)
39
CS248 Lecture 4Kurt Akeley, Fall 2007 Optical “imperfections” improve acuity Image is pre-filtered n Cutoff is approximately 60 cpd n Cutoff is gradual – no ringing Aliasing is avoided n Foveal cone density is 120 / degree n Cutoff matches retinal Nyquist limit Vernier acuity is improved n Foveal resolution is 30 arcsec n Vernier acuity is 5-10 arcsec n Linespread blur includes more sensors
40
CS248 Lecture 4Kurt Akeley, Fall 2007 Summary Two approaches to antialiasing are practiced n Pre-filtering (this lecture) n Increased sample rate Pre-filter antialiasing n Works well for non-area primitives (points, lines) n Works poorly for area primitives (triangles, especially in 3-D) The human eye is well adapted n Sampling theory helps us here too
41
CS248 Lecture 4Kurt Akeley, Fall 2007 Assignments Before Thursday’s class, read n FvD 3.1 through 3.14, Rasterization Project 1: n Continue work n Demos Wednesday 10 October
42
CS248 Lecture 4Kurt Akeley, Fall 2007 End
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.