Scan Conversion Sang Il Park Sejong University. Line Attributes Butt cap Round cap Projecting square...

download Scan Conversion Sang Il Park Sejong University. Line Attributes Butt cap Round cap Projecting square cap Miter join Round Join Bevel join.

If you can't read please download the document

Transcript of Scan Conversion Sang Il Park Sejong University. Line Attributes Butt cap Round cap Projecting square...

  • Slide 1

Scan Conversion Sang Il Park Sejong University Slide 2 Line Attributes Butt cap Round cap Projecting square cap Miter join Round Join Bevel join Slide 3 Area Filling How can we generate a solid color/patterned polygon area? Slide 4 How to decide interior -Parity Fill Approach For each pixel determine if it is inside or outside of a given polygon. Approach from the point being tested cast a ray in an arbitrary direction if the number of crossings is odd then the point is inside if the number of crossings is even then the point is outside Slide 5 How to decide interior -Parity Fill Approach Very fragile algorithm Ray crosses a vertex Ray is coincident with an edge Commonly used in CAD Suitable for H/W Slide 6 A winding number is an attribute of a point with respect to a polygon that tells us how many times the polygon encloses (or wraps around) the point. It is an integer, greater than or equal to 0. Regions of winding number 0 (unenclosed) are obviously outside the polygon, and regions of winding number 1 (simply enclosed) are obviously inside the polygon. Initially 0 +1: edge crossing the line from right to left -1: left to right use cross product of line and edge vectors No cross vertices How to decide interior -Winding Number Slide 7 Area Filling (Scan line Approach) Take advantage of Span coherence: all pixels on a span are set to the same value Scan-line coherence: consecutive scan lines are identical Edge coherence: edges intersected by scan line i are also intersected by scan line i+1 Slide 8 Area Filling (Scan line Approach) For each scan line (1) Find intersections (the extrema of spans) Use Bresenham's line-scan algorithm (2) Sort intersections (increasing x order) (3) Fill in between pair of intersections Slide 9 Area Filling (Scan line method) Slide 10 basic idea Start at a pixel interior to a polygon Fill the others using connectivity Area Filling (Seed Fill Algorithm) seed Slide 11 4-connected8-connected Need a stack. Why? Seed Fill Algorithm (Cont) Slide 12 start position Seed Fill Algorithm (Cont) Slide 13 interior-defined boundary-defined flood fill algorithmboundary fill algorithm 8 6 4 2 0 2 4 6 8 10 8 6 4 2 Slide 14 Seed Fill Algorithm (Cont) 0 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 1 2 3 4 5 6 7 hole boundary pixelinterior pixelseed pixel The stack may contain duplicated or unnecessary information !!! Slide 15 Boundary Filling Slide 16 Shani, U., Filling Regions in Binary Raster Images: A Graph-Theoretic Approach, Computer Graphics, 14, (1981), 321-327 scan line conversion seed filling + Scan Line Seed Fill Slide 17 Boundary Filling Efficiency in space! finish the scan line containing the starting position process all lines below the start line process all lines above the start line Slide 18 Flood Filling : Start a point inside the figure, replace a specified interior color only. Slide 19 Problems of Filling Algorithm What happens if a vertex is shared by more than one polygon, e.g. three triangles? What happens if the polygon intersects itself? What happens for a sliver? Solutions? Redefine what it means to be inside of a triangle Different routines for nasty little triangles Slide 20 Aliasing in CG Which is the better? Slide 21 Aliasing in CG Digital technology can only approximate analog signals through a process known as sampling The distortion of information due to low-frequency sampling (undersampling) Choosing an appropriate sampling rate depends on data size restraints, need for accuracy, the cost per sample Errors caused by aliasing are called artefacts. Common aliasing artefacts in computer graphics include jagged profiles, disappearing or improperly rendered fine detail, and disintegrating textures. Slide 22 The Nyquist Theorem the sampling rate must be at least twice the frequency of the signal or aliasing occurs Slide 23 Aliasing Effects Slide 24 Artifacts - Jagged profiles Jagged silhouettes are probably the most familiar effect caused by aliasing. Jaggies are especially noticeable where there is a high contrast between the interior and the exterior of the silhouette Slide 25 Artefacts - Improperly rendered detail Slide 26 Artefacts - Disintegrating textures The checkers should become smaller as the distance from the viewer increases. Slide 27 Antialiasing Antialiasing methods were developed to combat the effects of aliasing. The two major categories of antialiasing techniques are prefiltering and postfiltering. Slide 28 28 Prefiltering Eliminate high frequencies before sampling (Foley & van Dam p. 630) Convert I(x) to F(u) Apply a low-pass filter A low-pass filter allows low frequencies through, but attenuates (or reduces) high frequencies Then sample. Result: no aliasing! Slide 29 High Frequency Slide 30 30 Prefiltering Slide 31 31 Prefiltering Slide 32 Basis for Prefiltering Algorithms Slide 33 Catmulls Algorithm ABAB A1A1 A2A2 A3A3 Find fragment areas Multiply by fragment colors Sum for final pixel color Slide 34 Prefiltering Example Slide 35 35 Prefiltering So whats the problem? Problem: most rendering algorithms generate sampled function directly e.g., Z-buffer, ray tracing Slide 36 36 Supersampling The simplest way to reduce aliasing artifacts is supersampling Increase the resolution of the samples Average the results down Or sometimes, it is called Postfiltering. Slide 37 37 Supersampling The process: 1.Create virtual image at higher resolution than the final image 2.Apply a low-pass filter 3.Resample filtered image Slide 38 38 Supersampling: Limitations Q: What practical consideration hampers super- sampling? A: Storage goes up quadratically Q: What theoretical problem does supersampling suffer? A: Doesnt eliminate aliasing! Supersampling simply shifts the Nyquist limit higher Slide 39 39 Supersampling: Worst Case Q: Give a simple scene containing infinite frequencies A: A checkered ground plane receding into infinity See next slide Slide 40 40 Slide 41 41 Supersampling Despite these limitations, people still use super- sampling (why?) So how can we best perform it? Slide 42 Sampling in the Postfiltering method Supersampling from a 4*3 image. Sampling can be done randomly or regularly. The method of perturbing the sample positions is known as "jittering." Slide 43 43 Stochastic Sampling Stochastic: involving or containing a random variable Sampling theory tells us that with a regular sampling grid, frequencies higher than the Nyquist limit will alias Q: What about irregular sampling? A: High frequencies appear as noise, not aliases This turns out to bother our visual system less! Slide 44 44 Stochastic Sampling An intuitive argument: In stochastic sampling, every region of the image has a finite probability of being sampled Thus small features that fall between uniform sample points tend to be detected by non-uniform samples Slide 45 45 Stochastic Sampling Integrating with different renderers: Ray tracing: It is just as easy to fire a ray one direction as another Z-buffer: hard, but possible Notable example: REYES system (?) Using image jittering is easier (more later) A-buffer: nope Totally built around square pixel filter and primitive- to-sample coherence Slide 46 46 Stochastic Sampling Idea: randomizing distribution of samples scatters aliases into noise Problem: what type of random distribution to adopt? Reason: type of randomness used affects spectral characteristics of noise into which high frequencies are converted Slide 47 47 Stochastic Sampling Problem: given a pixel, how to distribute points (samples) within it? Grid Random Poisson Disc Jitter Slide 48 48 Stochastic Sampling Poisson distribution: Completely random Add points at random until area is full. Uniform distribution: some neighboring samples close together, some distant Slide 49 49 Stochastic Sampling Poisson disc distribution: Poisson distribution, with minimum- distance constraint between samples Add points at random, removing again if they are too close to any previous points Very even-looking distribution Slide 50 50 Stochastic Sampling Jittered distribution Start with regular grid of samples Perturb each sample slightly in a random direction More clumpy or granular in appearance Slide 51 Nonuniform Supersampling Adaptive Sampling Slide 52 Final Samples Problem: Many more blue samples than white samples But final pixel actually more white than purple! Simple filtering will not handle this correctly Slide 53 Filters Slide 54 Antialiasing http://www.siggraph.org/education/materials/HyperGraph/aliasing