week 2: review of graphics api

Post on 11-Jan-2016

32 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Week 2: Review of graphics API. Programmable pipeline. OpenGL block diagram. Generation. Traversal. Xformation. Rasteriz. & tex. Display. Display list. Per-vertex operations & Primitive assembly. Per- fragment operations. Frame buffer. Video display. Evaluator. Rasterization. - PowerPoint PPT Presentation

TRANSCRIPT

Background image by chromosphere.deviantart.comFella in following slides by devart.deviantart.com

DM2336 Programming hardware shadersDioselin Gonzalez - 2007 S2DM2336 Programming hardware shadersDioselin Gonzalez - 2007 S2

Week 2: Review of graphics API

Week 2: Review of graphics API

Programmable pipelineProgrammable pipeline

DM2336 PHS – Dioselin Gonzalez – 2007 S2

2

OpenGL block diagramOpenGL block diagram

Applicationgeneration

Applicationtraversal

Displaylist

Evaluator

Per-vertexoperations& Primitiveassembly

RasterizationPer-

fragmentoperations

Texturememory

Framebuffer

Videodisplay

Generation Traversal Xformation Rasteriz. & tex. Display

Pixeloperations

Application & higher level

graphics libraries

OpenGL implementation

DM2336 PHS – Dioselin Gonzalez – 2007 S2

3

Per-vertex operationsPer-vertex operations

• Transform vertex coords. (modelview m.)Transform vertex coords. (modelview m.)• Transform and renormalize normals Transform and renormalize normals • Generate and transform texture coords.Generate and transform texture coords.• Lighting calculationsLighting calculations

Applicationgeneration

Applicationtraversal

Displaylist

Evaluator

Per-vertexoperations

& Primitiveassembly

RasterizationPer-

fragmentoperations

Texturememory

Framebuffer

Videodisplay

Pixeloperations

DM2336 PHS – Dioselin Gonzalez – 2007 S2

4

Primitive assemblyPrimitive assembly

• Flat shadingFlat shading• ClippingClipping• Projection transformationsProjection transformations• Viewport and depth-range operationsViewport and depth-range operations• CullingCulling

Applicationgeneration

Applicationtraversal

Displaylist

Evaluator

Per-vertexoperations

& Primitiveassembly

RasterizationPer-

fragmentoperations

Texturememory

Framebuffer

Videodisplay

Pixeloperations

DM2336 PHS – Dioselin Gonzalez – 2007 S2

5

RasterizationRasterization

• Convert each primitive into fragmentsConvert each primitive into fragments• Fragment: “transient data structures”Fragment: “transient data structures”

– position (x,y); depth; color; texture position (x,y); depth; color; texture coordinates; coverage; …coordinates; coverage; …

Applicationgeneration

Applicationtraversal

Displaylist

Evaluator

Per-vertexoperations

& Primitiveassembly

RasterizationPer-

fragmentoperations

Texturememory

Framebuffer

Videodisplay

Pixeloperations

Background image by katosu.deviantart.com

DM2336 PHS – Dioselin Gonzalez – 2007 S2

Interpolation issuesInterpolation issues

http://www.cse.ohio-state.edu/~hwshen/781/pipeline.ppt

DM2336 PHS – Dioselin Gonzalez – 2007 S2

7

Linear Interpolation IssuesLinear Interpolation Issues

• Linear interpolation takes place in screen Linear interpolation takes place in screen space space

• Problems can happen when projecting Problems can happen when projecting – Texture coordinates Texture coordinates – ColorsColors– Positions are okay. Positions are okay.

• Cannot recover p’s color and texture coordinates from linear Interpolation Lerp(Cp1’,Cp2’) along L != Cp

• Need perspective correct perspective correct interpolationinterpolation for unprojected values

p2

p1

pP1’

P2’

p

L

http://www.cse.ohio-state.edu/~hwshen/781/pipeline.ppt

DM2336 PHS – Dioselin Gonzalez – 2007 S2

8

More explanationsMore explanations

• Equal spacing in screen (pixel) space is Equal spacing in screen (pixel) space is notnot the the same as in texture space in perspective projectionsame as in texture space in perspective projection– Perspective foreshorteningPerspective foreshortening

from Hill

courtesy ofH. Pfister

http://www.cse.ohio-state.edu/~hwshen/781/pipeline.ppt

DM2336 PHS – Dioselin Gonzalez – 2007 S2

9

Perspective-Correct Texture Coordinate Interpolation

Perspective-Correct Texture Coordinate Interpolation

• Interpolate (tex_coord/Interpolate (tex_coord/ww) over the ) over the polygon, then do perspective divide polygon, then do perspective divide afterafter interpolation interpolation

• Compute at each vertex after Compute at each vertex after perspective transformationperspective transformation– ““Numerators” Numerators” ss//ww, , tt//ww – ““Denominator” Denominator” 1/1/ww

http://www.cse.ohio-state.edu/~hwshen/781/pipeline.ppt

DM2336 PHS – Dioselin Gonzalez – 2007 S2

10

Perspective-Correct Texture Coordinate Interpolation

Perspective-Correct Texture Coordinate Interpolation

• Linearly interpolate Linearly interpolate 1/1/ww, , ss//ww, and , and tt//ww across the polygonacross the polygon

• At each pixelAt each pixel Perform perspective division of Perform perspective division of

interpolated texture coordinates interpolated texture coordinates ((ss//ww, , tt//ww)) by interpolated by interpolated 1/1/ww (i.e., (i.e., numerator over denominator) to get numerator over denominator) to get ((ss, , tt))

http://www.cse.ohio-state.edu/~hwshen/781/pipeline.ppt

DM2336 PHS – Dioselin Gonzalez – 2007 S2

11

Perspective-Correct InterpolationPerspective-Correct Interpolation

• That fixed it!That fixed it!

Background image by katosu.deviantart.com

DM2336 PHS – Dioselin Gonzalez – 2007 S2

Back to the pipelineBack to the pipeline

DM2336 PHS – Dioselin Gonzalez – 2007 S2

13

RasterizationRasterization

• Convert each primitive into fragmentsConvert each primitive into fragments• Fragment: “transient data structures”Fragment: “transient data structures”

– position (x,y); depth; color; texture position (x,y); depth; color; texture coordinates; coverage; …coordinates; coverage; …

Applicationgeneration

Applicationtraversal

Displaylist

Evaluator

Per-vertexoperations

& Primitiveassembly

RasterizationPer-

fragmentoperations

Texturememory

Framebuffer

Videodisplay

Pixeloperations

DM2336 PHS – Dioselin Gonzalez – 2007 S2

14

Per fragment operations (I)Per fragment operations (I)

• Generate texel for every fragmentGenerate texel for every fragment• Fog calculationsFog calculations• Coverage (antialiasing) values applicationCoverage (antialiasing) values application

Applicationgeneration

Applicationtraversal

Displaylist

Evaluator

Per-vertexoperations

& Primitiveassembly

RasterizationPer-fragmentoperations

Texturememory

Framebuffer

Videodisplay

Pixeloperations

DM2336 PHS – Dioselin Gonzalez – 2007 S2

15

Per fragment operations (II)Per fragment operations (II)

• ScissoringScissoring• Alpha testAlpha test• Stencil testStencil test• Depth-buffer testDepth-buffer test

Applicationgeneration

Applicationtraversal

Displaylist

Evaluator

Per-vertexoperations

& Primitiveassembly

RasterizationPer-fragmentoperations

Texturememory

Framebuffer

Videodisplay

Pixeloperations

• BlendingBlending• Dithering and Dithering and

logical operationlogical operation• MaskingMasking

DM2336 PHS – Dioselin Gonzalez – 2007 S2

16

Hello worldHello world

Per-fragment

Operations(I)

Per-vertex

Operations

DM2336 PHS – Dioselin Gonzalez – 2007 S2

17

DM2336 PHS – Dioselin Gonzalez – 2007 S2

18

Vertex shaderVertex shader

• Is run once every time a vertex position is Is run once every time a vertex position is specifiedspecified– glVertex, glDrawArrays, … glVertex, glDrawArrays, …

• MustMust compute gl_Position compute gl_Position

• MayMay compute gl_ClipVertex or gl_PointSize compute gl_ClipVertex or gl_PointSize

DM2336 PHS – Dioselin Gonzalez – 2007 S2

19

Hello worldHello world

DM2336 PHS – Dioselin Gonzalez – 2007 S2

20

DM2336 PHS – Dioselin Gonzalez – 2007 S2

21

Fragment shaderFragment shader

• Is run once for every fragment producedIs run once for every fragment produced

• Has access to the interpolated value for each Has access to the interpolated value for each varying variablevarying variable– Color, normal, texture coordinates, arbitrary valuesColor, normal, texture coordinates, arbitrary values

• Output goes to the fixed pipelineOutput goes to the fixed pipeline– gl_FragColor – computed R, G, B, A for the fragmentgl_FragColor – computed R, G, B, A for the fragment– gl_FragDepth – computed depth value for the gl_FragDepth – computed depth value for the

fragmentfragment– gl_FragData[n] – arbitrary data per fragment, gl_FragData[n] – arbitrary data per fragment,

stored in multiple render targetsstored in multiple render targets

Background image by katosu.deviantart.com

DM2336 PHS – Dioselin Gonzalez – 2007 S2

Playing with GLSL DemoPlaying with GLSL Demo

top related