The Computer Graphics Pipeline - University of California...

26
The Computer Graphics Pipeline 1 ECS 175 Chapter 2: The Computer Graphics Pipeline - Review Vertex Processor Clipper and Assembler Rasterizer Fragment Processor Programmable vs. Fixed Function Pipeline • SIMD vertices pixels

Transcript of The Computer Graphics Pipeline - University of California...

The Computer Graphics Pipeline

1 ECS 175 Chapter 2: The Computer Graphics Pipeline - Review

Vertex Processor

Clipper and Assembler Rasterizer Fragment

Processor

•  Programmable vs. Fixed Function Pipeline •  SIMD

vertices pixels

Chapter 3

1.  Introduction 2.  The Computer Graphics Pipeline 3.  Object Representation 4.  Object Transformation 5.  3D – Projections, Camera, and Lighting 6.  Scene Representation and Interaction 7.  Advanced Texturing and Shading

2

Input - From Objects to Images

• How do we represent objects on the computer?

•  Fulfill a number of requirements •  Low memory consumption •  Easy application of transformation operations (translate, clip,…) •  Closed representation (Object + Operation = Object) •  Easy to render

• Answer: Compose object of simpler base elements •  Vertices, Lines, Polygons (Triangles, Quads, …) •  Object represented as mesh/tessellation •  Additional optical properties (color)

3 ECS 175 Chapter 3: Object Representation

Input - Basic Elements

• Vertex, Line, Triangle

4 ECS 175 Chapter 3: Object Representation

Drawing in OpenGL (fixed function - not using VBO): glBegin(GL_POINTS); glBegin(GL_LINES); glBegin(GL_TRIANGLES) glVertex2f(x,y); glVertex2f(x1,y1); glVertex2f(x1,y1); glEnd(); glVertex2f(x2,y2); glVertex2f(x2,y2);

glEnd(); glVertex2f(x3,y3); glEnd();

Input - Basic Elements

5 ECS 175 Chapter 3: Object Representation

Chrschn – Wikimedia Commons

Remember the Graphics Pipeline

6 ECS 175 Chapter 3: Object Representation

3D Triangles

Clipped Triangles

2D Triangles Fragments

•  This chapter assumes a static 2D world •  After transformations and clipping

•  What does our input look like? •  How do we show it on screen?

Vertex Processor

Clipper and Assembler Rasterizer Fragment

Processor vertices pixels

Rasterization

• Rasterization of 2D lines and triangles

• At this stage vertices are given in screen coordinates (2D) • Attributes (color, depth, etc.) given per vertex

7 ECS 175 Chapter 3: Object Representation

Rasterization

• Create fragments (potential pixels) •  Interpolate attributes (color, depth, etc.) from vertices •  Identify target pixels

•  Integer grid – centered at 0 or 0.5 (OpenGL) •  Here: pixels are squares

8 ECS 175 Chapter 3: Object Representation

Rasterization

• DDA algorithm (digital differential analyzer) for lines

9 ECS 175 Chapter 3: Object Representation

∆y

∆x=

y2 − y1x2 − x1

= m 0 ≤ m ≤ 1 ∆y = m∆x

float y = y1; for(int x = x1;x <= x2;++x, y+=m) setPixel(x,round(y));

Rasterization

• DDA algorithm •  Find best y for each x •  Slope condition is important (cover symmetric cases)

10 ECS 175 Chapter 3: Object Representation

0 ≤ m ≤ 1

float y = y1; for(int x = x1;x <= x2;++x, y+=m) setPixel(x,round(y));

Rasterization

• Bresenham’s algorithm avoids floating point operations

11 ECS 175 Chapter 3: Object Representation

decide between yi and yi+1

y =∆y

∆xx+ b

decision based on sign of

f(x, y) = x∆y + b∆x− y∆x = 0

f(x+ 1, y + 0.5)

0 ≤ m ≤ 1

Rasterization

12 ECS 175 Chapter 3: Object Representation

f(x, y) = x∆y + b∆x− y∆x = 0

incremental decision variable

D0 = ∆y − 1

2∆x

D0 = f(x0 + 1, y0 + 0.5)− f(x0, y0)

multiply D by 2 to ensure integers

if D >= 0 pick upper candidate

Dk+1 = Dk +

�∆y if Dk < 0

∆y −∆x else

Rasterization

13 ECS 175 Chapter 3: Object Representation

• Some examples

Rasterization

14 ECS 175 Chapter 3: Object Representation

• Anti-aliasing (AA)

• Super sampling AA (SSAA) • Multisample AA (MSAA) • …

Rasterization

• Rasterization of polygons

•  Fill inside of polygon • What is “inside”? • Orientation: Clockwise, Counterclockwise

15 ECS 175 Chapter 3: Object Representation

not convex not simple

Rasterization

• What fragment positions are “inside”?

16 ECS 175 Chapter 3: Object Representation

odd-even test

winding number

Rasterization

• Scanline algorithm

•  Flood fill, … • Rasterizer interpolates attributes from vertices to fragments

17 ECS 175 Chapter 3: Object Representation

What about colors?

• Colors (and other attributes) are specified at vertices • How do we find values inside of polygons?

18 ECS 175 Chapter 3: Object Representation

Interpolation

•  Interpolation constructs “new” data within the range of known data points

• Construct a function with continuous domain from discrete data

19 ECS 175 Chapter 3: Object Representation

linear quadratic

Interpolation

• Mathematical formulation:

Given (“positions” and “values”) Find function defined on such that

20 ECS 175 Chapter 3: Object Representation

(xi, fi)

f

f(xi) = fi

[x0, xn]

Interpolation

• We have already seen that there can be multiple solutions • How do we pick the “right” function?

21 ECS 175 Chapter 3: Object Representation

Answer: Introduce constraints and/or make use of knowledge about data

Interpolation: Side Note

• Related concepts:

22 ECS 175 Chapter 3: Object Representation

Approximation Extrapolation

Interpolation: Linear

•  Linear interpolation

23 ECS 175 Chapter 3: Object Representation

f(x) = a+mx

Interpolation conditions

Linear interpolation

Solution

Alternative form

f(x0 = 0) = f0

f(x1 = 1) = f1

f(x) = f0 + (f1 − f0)x

f(u) = (1− u)f0 + uf1

Interpolation: Linear

•  Linear interpolation

24 ECS 175 Chapter 3: Object Representation

Alternative form

Values between x0 and x1 are “mixtures” of f0 and f1

f(u) = (1− u)f0 + uf1

u = 0.2 → 80%f0 + 20%f1

Interpolation: Linear

• Basis functions/Blending functions

25 ECS 175 Chapter 3: Object Representation

control point contributions are blended together

partition of unity (1− u) + u = 1

f(u) =�

i

bi(u) · fi

f(u) = (1− u)f0 + uf1

f(u) = b0(u) · f0 + b1(u) · f1

What about colors?

•  Linear interpolation (component-wise)

26 ECS 175 Chapter 3: Object Representation

fRGB(t) = (fR(t), fG(t), fB(t))