pipeline operations - cornell university · cornell cs4620 fall 2013 • lecture 10 © 2013 steve...

53
© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10 Pipeline Operations CS 4620 Lecture 10 1

Upload: others

Post on 17-Aug-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Pipeline Operations

CS 4620 Lecture 10

1

Page 2: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

APPLICATION

COMMAND STREAM

VERTEX PROCESSING

TRANSFORMED GEOMETRY

RASTERIZATION

FRAGMENTS

FRAGMENT PROCESSING

FRAMEBUFFER IMAGE

DISPLAY

you are here

3D transformations; shading

conversion of primitives to pixels

blending, compositing, shading

user sees this

Pipeline

2

Page 3: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Pipeline of transformations

• Standard sequence of transforms

3

!

!

!

!

!

!

!

!

7.1. Viewing Transformations 147

object space

world space

camera space

canonicalview volume

scre

en

sp

ace

modelingtransformation

viewporttransformation

projectiontransformation

cameratransformation

Figure 7.2. The sequence of spaces and transformations that gets objects from their

original coordinates into screen space.

space) to camera coordinates or places them in camera space. The projection

transformation moves points from camera space to the canonical view volume.

Finally, the viewport transformation maps the canonical view volume to screen Other names: camera

space is also “eye space”

and the camera

transformation is

sometimes the “viewing

transformation;” the

canonical view volume is

also “clip space” or

“normalized device

coordinates;” screen space

is also “pixel coordinates.”

space.

Each of these transformations is individually quite simple. We’ll discuss them

in detail for the orthographic case beginning with the viewport transformation,

then cover the changes required to support perspective projection.

7.1.1 The Viewport Transformation

We begin with a problemwhose solution will be reused for any viewing condition.

We assume that the geometry we want to view is in the canonical view volume The word “canonical” crops

up again—it means

something arbitrarily

chosen for convenience.

For instance, the unit circle

could be called the

“canonical circle.”

and we wish to view it with an orthographic camera looking in the !z direction.The canonical view volume is the cube containing all 3D points whose Cartesian

coordinates are between !1 and +1—that is, (x, y, z) " [!1, 1]3 (Figure 7.3).We project x = !1 to the left side of the screen, x = +1 to the right side of thescreen, y = !1 to the bottom of the screen, and y = +1 to the top of the screen.

Recall the conventions for pixel coordinates fromChapter 3: each pixel “owns”

a unit square centered at integer coordinates; the image boundaries have a half-

unit overshoot from the pixel centers; and the smallest pixel center coordinates

Page 4: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Hidden surface elimination

• We have discussed how to map primitives to image space– projection and perspective are depth cues– occlusion is another very important cue

4

Page 5: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Back face culling

• For closed shapes you will never see the inside– therefore only draw surfaces that face the camera

– implement by checking n . v

5

Page 6: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Back face culling

• For closed shapes you will never see the inside– therefore only draw surfaces that face the camera

– implement by checking n . v

5

Page 7: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Back face culling

• For closed shapes you will never see the inside– therefore only draw surfaces that face the camera

– implement by checking n . v

5

Page 8: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Back face culling

• For closed shapes you will never see the inside– therefore only draw surfaces that face the camera

– implement by checking n . vn

vn

v

5

Page 9: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Painter’s algorithm

• Simplest way to do hidden surfaces• Draw from back to front, use overwriting in

framebuffer

6

Page 10: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Painter’s algorithm

• Simplest way to do hidden surfaces• Draw from back to front, use overwriting in

framebuffer

6

Page 11: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Painter’s algorithm

• Simplest way to do hidden surfaces• Draw from back to front, use overwriting in

framebuffer

6

Page 12: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Painter’s algorithm

• Simplest way to do hidden surfaces• Draw from back to front, use overwriting in

framebuffer

6

Page 13: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Painter’s algorithm

• Simplest way to do hidden surfaces• Draw from back to front, use overwriting in

framebuffer

6

Page 14: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Painter’s algorithm

• Simplest way to do hidden surfaces• Draw from back to front, use overwriting in

framebuffer

6

Page 15: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

B

A

C

E

D

F AB

C

F

D

E

Painter’s algorithm

• Amounts to a topological sort of the graph of occlusions– that is, an edge from A to B means A sometimes occludes B– any sort is valid

• ABCDEF• BADCFE

– if there are cycles there is no sort

7

Page 16: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Painter’s algorithm

• Amounts to a topological sort of the graph of occlusions– that is, an edge from A to B means A sometimes occludes B– any sort is valid

• ABCDEF• BADCFE

– if there are cycles there is no sort

[Fol

ey e

t al

.]

7

Page 17: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Painter’s algorithm

• Useful when a valid order is easy to come by• Compatible with alpha blending

[Fol

ey e

t al

.]

8

Page 18: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

The z buffer

• In many (most) applications maintaining a z sort is too expensive– changes all the time as the view changes– many data structures exist, but complex

• Solution: draw in any order, keep track of closest– allocate extra channel per pixel to keep track of closest

depth so far– when drawing, compare object’s depth to current closest

depth and discard if greater– this works just like any other compositing operation

9

Page 19: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

The z buffer

– another example of a memory-intensive brute force approach that works and has become the standard

[Fol

ey e

t al

.]

10

Page 20: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Precision in z buffer

• The precision is distributed between the near and far clipping planes– this is why these planes have to exist– also why you can’t always just set them to very small and

very large distances

• Generally use z’ (not world z) in z buffer

11

Page 21: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Interpolating in projection

linear interp. in screen space ≠ linear interp. in world (eye) space

12

Page 22: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Interpolating in projection

linear interp. in screen space ≠ linear interp. in world (eye) space

12

Page 23: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Interpolating in projection

linear interp. in screen space ≠ linear interp. in world (eye) space

12

Page 24: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Interpolating in projection

linear interp. in screen space ≠ linear interp. in world (eye) space

12

Page 25: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Interpolating in projection

linear interp. in screen space ≠ linear interp. in world (eye) space

12

Page 26: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Interpolating in projection

linear interp. in screen space ≠ linear interp. in world (eye) space

12

Page 27: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Interpolating in projection

linear interp. in screen space ≠ linear interp. in world (eye) space

12

Page 28: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Pipeline for minimal operation

• Vertex stage (input: position / vtx; color / tri)– transform position (object to screen space)– pass through color

• Rasterizer – pass through color

• Fragment stage (output: color)

– write to color planes

13

Page 29: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Result of minimal pipeline

14

Page 30: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Pipeline for basic z buffer

• Vertex stage (input: position / vtx; color / tri)– transform position (object to screen space)– pass through color

• Rasterizer – interpolated parameter: z’ (screen z)– pass through color

• Fragment stage (output: color, z’)– write to color planes only if interpolated z’ < current z’

15

Page 31: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Result of z-buffer pipeline

16

Page 32: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Flat shading

• Shade using the real normal of the triangle– same result as ray tracing a bunch of triangles

• Leads to constant shading and faceted appearance– truest view of the

mesh geometry

[Fol

ey e

t al

.]

17

Page 33: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Pipeline for flat shading

• Vertex stage (input: position / vtx; color and normal / tri)– transform position and normal (object to eye space)– compute shaded color per triangle using normal– transform position (eye to screen space)

• Rasterizer – interpolated parameters: z’ (screen z)– pass through color

• Fragment stage (output: color, z’)

– write to color planes only if interpolated z’ < current z’

18

Page 34: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Result of flat-shading pipeline

19

Page 35: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner •(with previous instructors James/Bala)

Cornell CS4620 Fall 2013 • Lecture 6

Transforming normal vectors

• Transforming surface normals– differences of points (and therefore tangents) transform OK– normals do not --> use inverse transpose matrix

20

Page 36: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner •(with previous instructors James/Bala)

Cornell CS4620 Fall 2013 • Lecture 6

Transforming normal vectors

• Transforming surface normals– differences of points (and therefore tangents) transform OK– normals do not --> use inverse transpose matrix

20

Page 37: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

[Gou

raud

the

sis]

Gouraud shading

• Often we’re trying to draw smooth surfaces, so facets are an artifact– compute colors at

vertices using vertex normals

– interpolate colors across triangles

– “Gouraud shading”– “Smooth shading”

21

Page 38: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

[Gou

raud

the

sis]

Gouraud shading

[Fol

ey e

t al

.]

• Often we’re trying to draw smooth surfaces, so facets are an artifact– compute colors at

vertices using vertex normals

– interpolate colors across triangles

– “Gouraud shading”– “Smooth shading”

21

Page 39: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Pipeline for Gouraud shading

• Vertex stage (input: position, color, and normal / vtx)– transform position and normal (object to eye space)– compute shaded color per vertex– transform position (eye to screen space)

• Rasterizer – interpolated parameters: z’ (screen z); r, g, b color

• Fragment stage (output: color, z’)– write to color planes only if interpolated z’ < current z’

22

Page 40: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Result of Gouraud shading pipeline

23

Page 41: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Local vs. infinite viewer, light

• Phong illumination requires geometric information:– light vector (function of position)– eye vector (function of position)– surface normal (from application)

• Light and eye vectors change– need to be computed (and

normalized) for each vertex

24

Page 42: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Local vs. infinite viewer, light

• Look at case when eye or light is far away:– distant light source: nearly parallel illumination– distant eye point: nearly orthographic projection– in both cases, eye or light vector changes very little

• Optimization: approximate eye and/or lightas infinitely far away

25

Page 43: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Directional light

• Directional (infinitely distant) light source– light vector always points in the same direction– often specified by

position [x y z 0]– many pipelines are faster

if you use directional lights

26

Page 44: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Directional light

• Directional (infinitely distant) light source– light vector always points in the same direction– often specified by

position [x y z 0]– many pipelines are faster

if you use directional lights

26

Page 45: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Infinite viewer

• Orthographic camera– projection direction is constant

• “Infinite viewer”– even with perspective,

can approximate eye vector using the image plane normal

– can produce weirdness for wide-angle views

– Blinn-Phong: light, eye, half vectorsall constant!

27

Page 46: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Vertex normals

• Need normals at vertices tocompute Gouraud shading

• Best to get vtx. normals fromthe underlying geometry– e. g. spheres example

• Otherwise have to infer vtx.normals from triangles– simple scheme: average

surrounding face normals

[Fol

ey e

t al

.]

28

Page 47: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Non-diffuse Gouraud shading

• Can apply Gouraud shading to any illumination model– it’s just an interpolation method

• Results are not so good with fast-varying models like specular ones– problems with any

highlights smallerthan a triangle

[Fol

ey e

t al

.]

29

Page 48: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Per-pixel (Phong) shading

• Get higher quality by interpolating the normal– just as easy as interpolating the color– but now we are evaluating the illumination model per pixel

rather than per vertex (and normalizing the normal first)– in pipeline, this means we are moving illumination from the

vertex processing stage to the fragment processing stage

30

Page 49: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Per-pixel (Phong) shading

• Bottom line: produces much better highlights

[Fol

ey e

t al

.]

31

Page 50: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Pipeline for per-pixel shading

• Vertex stage (input: position, color, and normal / vtx)– transform position and normal (object to eye space)– transform position (eye to screen space)– pass through color

• Rasterizer – interpolated parameters: z’ (screen z); r, g, b color; x, y, z

normal

• Fragment stage (output: color, z’)– compute shading using interpolated color and normal– write to color planes only if interpolated z’ < current z’

32

Page 51: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Result of per-pixel shading pipeline

33

Page 52: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

Programming hardware pipelines

• Modern hardware graphics pipelines are flexible– programmer defines exactly what happens at each stage– do this by writing shader programs in domain-specific

languages called shading languages– rasterization is fixed-function, as are some other operations

(depth test, many data conversions, …)

• One example: OpenGL and GLSL (GL Shading Language)– several types of shaders process primitives and vertices; most

basic is the vertex program– after rasterization, fragments are processed by a fragment

program

34

Page 53: Pipeline Operations - Cornell University · Cornell CS4620 Fall 2013 • Lecture 10 © 2013 Steve Marschner • Pipeline Operations CS 4620 Lecture 10 1

© 2013 Steve Marschner • Cornell CS4620 Fall 2013 • Lecture 10

GLSL Shaders

35

framebuffer

uniform variables

attributes

varying parameters

varying parameters

colordepth

rasterizer

vertex program

fragment program

triangles

application