attributes of graphics primitives sang il park sejong university

57
Attributes of Graphics Primitives Sang Il Park Sejong University

Upload: roger-hill

Post on 25-Dec-2015

219 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Attributes of Graphics Primitives Sang Il Park Sejong University

Attributes of Graphics Primitives

Sang Il Park

Sejong University

Page 2: Attributes of Graphics Primitives Sang Il Park Sejong University

OpenGL State variables:

• Color• Point attributes• Line attributes• Fill-Area attributes

Page 3: Attributes of Graphics Primitives Sang Il Park Sejong University

• Color buffer Setting:

• Setting the color value:

Ex)

Color in OpenGL

glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB)glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB)

GLUT_RGBA GLUT_RGB GLUT_INDEX GLUT_SINGLEGLUT_DOUBLE

GLUT_RGBA GLUT_RGB GLUT_INDEX GLUT_SINGLEGLUT_DOUBLE

glColor* (values);glColor* (values);

glColor3f (0.0, 1.0, 0.5);glColor3i ( 0, 255, 128);glColor3f (0.0, 1.0, 0.5);glColor3i ( 0, 255, 128);

Page 4: Attributes of Graphics Primitives Sang Il Park Sejong University

• Size:

• Color :

Point Attributes in OpenGL

glPointSize ( size );glPointSize ( size );

glColor* (values);glColor* (values);

Page 5: Attributes of Graphics Primitives Sang Il Park Sejong University

• Width:

• Line-Style :

ex)

• Line-Style On/Off:

Line Attributes in OpenGL

glLineWidth ( width );glLineWidth ( width );

glLineStipple (repeatFactor, pattern); glLineStipple (repeatFactor, pattern);

glLineStipple (1, 0x00FF);glLineStipple (1, 0x0101);glLineStipple (1, 0x00FF);glLineStipple (1, 0x0101);

glEnable (GL_LINE_STIPPLE);glDisable (GL_LINE_STIPPLE);glEnable (GL_LINE_STIPPLE);glDisable (GL_LINE_STIPPLE);

Page 6: Attributes of Graphics Primitives Sang Il Park Sejong University

• Line Caps:

• Connecting:

Other Line Attributes Not in OpenGL

Butt cap Round cap Projecting square cap

Miter join Round join Bevel join

Page 7: Attributes of Graphics Primitives Sang Il Park Sejong University

• Pen and Brush Options:

Other Line Attributes Not in OpenGL

Page 8: Attributes of Graphics Primitives Sang Il Park Sejong University

• Color buffer Setting:

• Setting the color value:

Ex)

Color in OpenGL

glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB)glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB)

GLUT_RGBA GLUT_RGB GLUT_INDEX GLUT_SINGLEGLUT_DOUBLE

GLUT_RGBA GLUT_RGB GLUT_INDEX GLUT_SINGLEGLUT_DOUBLE

glColor* (values);glColor* (values);

glColor3f (0.0, 1.0, 0.5);glColor3i ( 0, 255, 128);glColor3f (0.0, 1.0, 0.5);glColor3i ( 0, 255, 128);

Page 9: Attributes of Graphics Primitives Sang Il Park Sejong University

Area Filling

• Scan line approach• Seed Fill Algorithm

Page 10: Attributes of Graphics Primitives Sang Il Park Sejong University

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

Page 11: Attributes of Graphics Primitives Sang Il Park Sejong University

Area Filling (Scan line Approach)

• Take advantage of– Edge coherence: edges intersected by

scan line i are also intersected by scan line i+1

Page 12: Attributes of Graphics Primitives Sang Il Park Sejong University

Area Filling (Scan line method)

Page 13: Attributes of Graphics Primitives Sang Il Park Sejong University

basic idea− Start at a pixel interior to a polygon

− Fill the others using connectivity

Area Filling (Seed Fill Algorithm)

seed

Page 14: Attributes of Graphics Primitives Sang Il Park Sejong University

4-connected 8-connected

Need a stack.

Why?

Seed Fill Algorithm (Cont’)

Page 15: Attributes of Graphics Primitives Sang Il Park Sejong University

start position

Seed Fill Algorithm (Cont’)

Page 16: Attributes of Graphics Primitives Sang Il Park Sejong University

Seed Fill Algorithm (Cont’)

interior-defined boundary-defined

flood fill algorithm boundary fill algorithm

8

6

4

2

0 2 4 6 8 10 0 2 4 6 8 10

8

6

4

2

Page 17: Attributes of Graphics Primitives Sang Il Park Sejong University

Seed Fill Algorithm (Cont’)

0 1 2 3 4 5 6 7 8 91

2

3

4

5

6

7

0 1 2 3 4 5 6 7 8 9

1

2

3

4

5

6

7

hole

boundary pixel interior pixel seed pixel

The stack may contain duplicated or unnecessary information !!!

Page 18: Attributes of Graphics Primitives Sang Il Park Sejong University

Boundary Filling

Page 19: Attributes of Graphics Primitives Sang Il Park Sejong University

Flood Filling

: Start a point inside the figure, replace a specified interior color only.

Page 20: Attributes of Graphics Primitives Sang Il Park Sejong University

Shani, U., “Filling Regions in Binary Raster Images:A Graph-Theoretic Approach”, Computer Graphics,14, (1981), 321-327

scan lineconversion

seedfilling

+

Scan Line Seed Fill

Page 21: Attributes of Graphics Primitives Sang Il Park Sejong University

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

Page 22: Attributes of Graphics Primitives Sang Il Park Sejong University

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

Page 23: Attributes of Graphics Primitives Sang Il Park Sejong University

OpenGL Fill-Area Function

• Shade model:

• Wire-frame or point:

glShadeModel ( shadeModel );glShadeModel ( shadeModel );

GL_SMOOTHGL_FLATGL_SMOOTHGL_FLAT

glPolygonMode ( face, displayMode );glPolygonMode ( face, displayMode );

GL_FRONTGL_BACK

GL_FRONT_AND_BACK

GL_FRONTGL_BACK

GL_FRONT_AND_BACK

GL_LINEGL_POINTGL_FILL

GL_LINEGL_POINTGL_FILL

Page 24: Attributes of Graphics Primitives Sang Il Park Sejong University

Aliasing in CG

Wh

ich

is th

e

bette

r?

Page 25: Attributes of Graphics Primitives Sang Il Park Sejong University

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.

Page 26: Attributes of Graphics Primitives Sang Il Park Sejong University

The Nyquist Theorem

the sampling rate must be at least twice the frequency of the signal or aliasing occurs

Page 27: Attributes of Graphics Primitives Sang Il Park Sejong University

Aliasing Effects

Page 28: Attributes of Graphics Primitives Sang Il Park Sejong University

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

Page 29: Attributes of Graphics Primitives Sang Il Park Sejong University

Artefacts - Improperly rendered detail

Page 30: Attributes of Graphics Primitives Sang Il Park Sejong University

Artefacts - Disintegrating textures

• The checkers should become smaller as the distance from the viewer increases.

Page 31: Attributes of Graphics Primitives Sang Il Park Sejong University

Antialiasing

• Antialiasing methods were developed to combat the effects of aliasing. The two major categories of antialiasing techniques are prefiltering and postfiltering.

Page 32: Attributes of Graphics Primitives Sang Il Park Sejong University

32

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!

Page 33: Attributes of Graphics Primitives Sang Il Park Sejong University

High Frequency

Page 34: Attributes of Graphics Primitives Sang Il Park Sejong University

34

Prefiltering

Page 35: Attributes of Graphics Primitives Sang Il Park Sejong University

35

Prefiltering

Page 36: Attributes of Graphics Primitives Sang Il Park Sejong University

Basis for Prefiltering Algorithms

Page 37: Attributes of Graphics Primitives Sang Il Park Sejong University

Catmull’s Algorithm

AB

A1A2

A3

• Find fragment areas

• Multiply by fragment colors

• Sum for final pixel color

Page 38: Attributes of Graphics Primitives Sang Il Park Sejong University

Prefiltering Example

Page 39: Attributes of Graphics Primitives Sang Il Park Sejong University

39

Prefiltering

• So what’s the problem?• Problem: most rendering algorithms generate

sampled function directly– e.g., Z-buffer, ray tracing

Page 40: Attributes of Graphics Primitives Sang Il Park Sejong University

40

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”.

Page 41: Attributes of Graphics Primitives Sang Il Park Sejong University

41

Supersampling

• The process:1. Create virtual image at higher resolution than the

final image

2. Apply a low-pass filter

3. Resample filtered image

Page 42: Attributes of Graphics Primitives Sang Il Park Sejong University

42

Supersampling: Limitations

• Q: What practical consideration hampers super-sampling?

• A: Storage goes up quadratically• Q: What theoretical problem does

supersampling suffer?• A: Doesn’t eliminate aliasing! Supersampling

simply shifts the Nyquist limit higher

Page 43: Attributes of Graphics Primitives Sang Il Park Sejong University

43

Supersampling: Worst Case

• Q: Give a simple scene containing infinite frequencies

• A: A checkered ground plane receding into infinity

• See next slide…

Page 44: Attributes of Graphics Primitives Sang Il Park Sejong University

44

Page 45: Attributes of Graphics Primitives Sang Il Park Sejong University

45

Supersampling

• Despite these limitations, people still use super-sampling (why?)

• So how can we best perform it?

Page 46: Attributes of Graphics Primitives Sang Il Park Sejong University

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."

Page 47: Attributes of Graphics Primitives Sang Il Park Sejong University

47

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!

Page 48: Attributes of Graphics Primitives Sang Il Park Sejong University

48

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

Page 49: Attributes of Graphics Primitives Sang Il Park Sejong University

49

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

Page 50: Attributes of Graphics Primitives Sang Il Park Sejong University

50

Stochastic Sampling

• Problem: given a pixel, how to distribute points (samples) within it?

Grid Random Poisson Disc Jitter

Page 51: Attributes of Graphics Primitives Sang Il Park Sejong University

51

Stochastic Sampling

• Poisson distribution: – Completely random– Add points at random until area is full.– Uniform distribution: some neighboring

samples close together, some distant

Page 52: Attributes of Graphics Primitives Sang Il Park Sejong University

52

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

Page 53: Attributes of Graphics Primitives Sang Il Park Sejong University

53

Stochastic Sampling

• Jittered distribution– Start with regular grid of samples– Perturb each sample slightly in a

random direction– More “clumpy” or granular in appearance

Page 54: Attributes of Graphics Primitives Sang Il Park Sejong University

Nonuniform Supersampling

Adaptive Sampling

Page 55: Attributes of Graphics Primitives Sang Il Park Sejong University

Adaptive Sampling

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

Page 56: Attributes of Graphics Primitives Sang Il Park Sejong University

Filters

Page 57: Attributes of Graphics Primitives Sang Il Park Sejong University

Antialiasing

http://www.siggraph.org/education/materials/HyperGraph/aliasing