rendering approachesshinar/courses/cs230-winter-2016/lecture...v5 vertices v0 v1 v2 v3 v4 v5...

56
Rendering approaches 1.image-oriented foreach pixel ... 2.object-oriented foreach object ... geometry image 3D rendering pipeline

Upload: others

Post on 07-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Rendering approaches

1.image-oriented foreach pixel ...

2.object-oriented

foreach object ... geometry image3D rendering

pipeline

Page 2: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

3D graphics pipeline

Vertex processing: coordinate transformations and color

Clipping and primitive assembly: output is a set of primitives

Rasterization: output is a set of fragments for each primitive

Fragment processing: update pixels in the frame buffer

Vertex processor

Clipper and primitive assembler

RasterizerFragment processorVertices Pixels

Page 3: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Graphics Pipeline (slides courtesy K. Fatahalian)

Page 4: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Vertex processing

v0

v1

v2

v3

v4

v5

Vertices

Vertices are transformed into “screen space”

Vertex processor

Clipper and primitive assembler

Rasterizer Fragment processor

Vertices Pixels

Page 5: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Vertex processing

v0

v1

v2

v3

v4

v5

Vertices

Vertices are transformed into “screen space”

EACH VERTEX IS TRANSFORMED

INDEPENDENTLY

Vertex processor

Clipper and primitive assembler

Rasterizer Fragment processor

Vertices Pixels

Page 6: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Primitive processing

v0

v1

v2

v3

v4

v5

Vertices

v0

v1

v2

v3

v4

v5

Primitives (triangles)

Then organized into primitives that are clipped and culled…

Vertex processor

Clipper and primitive assembler

Rasterizer Fragment processor

Vertices Pixels

Page 7: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Rasterization

Primitives are rasterized into “pixel fragments”

Fragments

Vertex processor

Clipper and primitive assembler

Rasterizer Fragment processor

Vertices Pixels

Page 8: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Rasterization

Primitives are rasterized into “pixel fragments”

EACH PRIMITIVE IS RASTERIZED INDEPENDENTLY

Vertex processor

Clipper and primitive assembler

Rasterizer Fragment processor

Vertices Pixels

Page 9: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Fragment processing

Shaded fragments

Fragments are shaded to compute a color at each pixel

Vertex processor

Clipper and primitive assembler

Rasterizer Fragment processor

Vertices Pixels

Page 10: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Fragment processing

EACH FRAGMENT IS PROCESSED INDEPENDENTLY

Fragments are shaded to compute a color at each pixel

Vertex processor

Clipper and primitive assembler

Rasterizer Fragment processor

Vertices Pixels

Page 11: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Pixel operations

Pixels

Fragments are blended into the frame buffer at their pixel locations (z-buffer determines visibility)

Vertex processor

Clipper and primitive assembler

Rasterizer Fragment processor

Vertices Pixels

Page 12: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Pipeline entities

v0

v1

v2

v3

v4

v5 v0

v1

v2

v3

v4

v5

Vertices Primitives Fragments

Pixels Fragments (shaded)

Page 13: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Rasterization

Page 14: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

What is rasterization?

Rasterization is the process of determining which pixels are “covered” by the primitive

Page 15: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

What is rasterization?

input: primitives output: fragments

enumerate the pixels covered by a primitive

interpolate attributes across the primitive

Vertex processor

Clipper and primitive assembler

RasterizerFragment processorVertices Pixels

Page 16: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Rasterization

Compute integer coordinates for pixels covered by the 2D primitives

Algorithms are invoked many, many times and so must be efficient

Output should be visually pleasing, for example, lines should have constant density

Obviously, should be able to draw all possible 2D primitives

Page 17: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Screen coordinates

Page 18: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Line Representation

Page 19: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex
Page 20: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex
Page 21: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex
Page 22: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex
Page 23: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex
Page 24: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Implicit Line Equation

<whiteboard>

Page 25: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Implicit Line Equation

decision variable, d

Page 26: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Implicit Line Equation

decision variable, d

Page 27: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Implicit Line Equation

decision variable, d

Page 28: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Implicit Line Equation

decision variable, d

Page 29: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Line Drawing

Page 30: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Which pixels should be used to approximate a line?

Draw the thinnest possible line that has no gaps

Page 31: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex
Page 32: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex
Page 33: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Line drawing algorithm

y = y0for x = x0 to x1 do draw(x,y) if (<condition>) then y = y+1

(case: 0 < m <= 1)

•move from left to right•choose between

(x+1,y) and (x+1,y+1)

Page 34: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Line drawing algorithm

y = y0for x = x0 to x1 do draw(x,y) if (<condition>) then y = y+1

(case: 0 < m <= 1)

•move from left to right•choose between

(x+1,y) and (x+1,y+1)

Page 35: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Use the midpoint between the two pixels to choose

Page 36: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Use the midpoint between the two pixels to choose

Page 37: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Use the midpoint between the two pixels to choose

Page 38: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Use the midpoint between the two pixels to choose

implicit line equation:

evaluate f at midpoint:<whiteboard>

Page 39: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Use the midpoint between the two pixels to choose

implicit line equation:

evaluate f at midpoint:

Page 40: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Line drawing algorithm(case: 0 < m <= 1)

y = y0for x = x0 to x1 do draw(x,y) if ( ) then y = y+1

Page 41: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

We can make the Midpoint Algorithm more efficient

y = y0for x = x0 to x1 do draw(x,y) if ( ) then y = y+1

Page 42: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

We can make the Midpoint Algorithm more efficient

by making it incremental!

Page 43: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

We can make the Midpoint Algorithm more efficient

Page 44: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

We can make the Midpoint Algorithm more efficient

Page 45: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

We can make the Midpoint Algorithm more efficient

y = y0d = f(x0+1,y0+1/2)for x = x0 to x1 do draw(x,y) if (d<0) then y = y+1 d = d+(y0-y1)+(x1-x0) else d = d+(y0-y1)

Page 46: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Adapt Midpoint Algorithm for other cases

case: 0 < m <= 1

Page 47: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Adapt Midpoint Algorithm for other cases

case: -1 <= m < 0

Page 48: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Adapt Midpoint Algorithm for other cases

case: 1 <= mor m <= -1

Page 49: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Line drawing references

• the algorithm we just described is the Midpoint Algorithm (Pitteway, 1967), (van Aken and Novak, 1985)

• draws the same lines as the Bresenham Line Algorithm (Bresenham, 1965)

Page 50: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

Triangles

Page 51: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

barycentric coordinates

Page 52: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

barycentric coordinates

Page 53: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

barycentric coordinates

Page 54: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

barycentric coordinates

Page 55: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

barycentric coordinates

Page 56: Rendering approachesshinar/courses/cs230-winter-2016/Lecture...v5 Vertices v0 v1 v2 v3 v4 v5 Primitives (triangles) Then organized into primitives that are clipped and culled… Vertex

barycentric coordinates

What are ?

<whiteboard>