Presentation is loading. Please wait.

Presentation is loading. Please wait.

Background image by chromosphere.deviantart.com Fella in following slides by devart.deviantart.com DM2336 Programming hardware shaders Dioselin Gonzalez.

Similar presentations


Presentation on theme: "Background image by chromosphere.deviantart.com Fella in following slides by devart.deviantart.com DM2336 Programming hardware shaders Dioselin Gonzalez."— Presentation transcript:

1 Background image by chromosphere.deviantart.com Fella in following slides by devart.deviantart.com DM2336 Programming hardware shaders Dioselin Gonzalez - 2007 S2 DM2336 Programming hardware shaders Dioselin Gonzalez - 2007 S2 Week 2: Review of graphics API Programmable pipeline

2 DM2336 PHS – Dioselin Gonzalez – 2007 S2 2 OpenGL block diagram Application generation Application traversal Display list Evaluator Per-vertex operations & Primitive assembly Rasterization Per- fragment operations Texture memory Frame buffer Video display GenerationTraversalXformationRasteriz. & tex.Display Pixel operations Application & higher level graphics libraries OpenGL implementation

3 DM2336 PHS – Dioselin Gonzalez – 2007 S2 3 Per-vertex operations Transform vertex coords. (modelview m.)Transform vertex coords. (modelview m.) Transform and renormalize normalsTransform and renormalize normals Generate and transform texture coords.Generate and transform texture coords. Lighting calculationsLighting calculations Application generation Application traversal Display list Evaluator Per-vertex operations & Primitive assembly Rasterization Per- fragment operations Texture memory Frame buffer Video display Pixel operations

4 DM2336 PHS – Dioselin Gonzalez – 2007 S2 4 Primitive assembly Flat shadingFlat shading ClippingClipping Projection transformationsProjection transformations Viewport and depth-range operationsViewport and depth-range operations CullingCulling Application generation Application traversal Display list Evaluator Per-vertex operations & Primitive assembly Rasterization Per- fragment operations Texture memory Frame buffer Video display Pixel operations

5 DM2336 PHS – Dioselin Gonzalez – 2007 S2 5 Rasterization Convert each primitive into fragmentsConvert each primitive into fragments Fragment: “transient data structures”Fragment: “transient data structures” –position (x,y); depth; color; texture coordinates; coverage; … Application generation Application traversal Display list Evaluator Per-vertex operations & Primitive assembly Rasterization Per- fragment operations Texture memory Frame buffer Video display Pixel operations

6 Background image by katosu.deviantart.com DM2336 PHS – Dioselin Gonzalez – 2007 S2 Interpolation issues http://www.cse.ohio-state.edu/~hwshen/781/pipeline.ppt

7 DM2336 PHS – Dioselin Gonzalez – 2007 S2 7 Linear Interpolation Issues Linear interpolation takes place in screen spaceLinear interpolation takes place in screen space Problems can happen when projectingProblems can happen when projecting –Texture coordinates –Colors –Positions are okay. Cannot recover p’s color and texture coordinates from linear Interpolation Lerp(C p1’,C p2’ ) along L != C p perspective correct interpolation Need perspective correct interpolation for unprojected values p2 p1 p P1’ P2’ p L http://www.cse.ohio-state.edu/~hwshen/781/pipeline.ppt

8 DM2336 PHS – Dioselin Gonzalez – 2007 S2 8 More explanations Equal spacing in screen (pixel) space is not the same as in texture space in perspective projectionEqual spacing in screen (pixel) space is not the same as in texture space in perspective projection –Perspective foreshortening from Hill courtesy of H. Pfister http://www.cse.ohio-state.edu/~hwshen/781/pipeline.ppt

9 DM2336 PHS – Dioselin Gonzalez – 2007 S2 9 Perspective-Correct Texture Coordinate Interpolation Interpolate (tex_coord/w) over the polygon, then do perspective divide after interpolationInterpolate (tex_coord/w) over the polygon, then do perspective divide after interpolation Compute at each vertex after perspective transformationCompute at each vertex after perspective transformation –“Numerators” s/w, t/w –“Denominator” 1/w http://www.cse.ohio-state.edu/~hwshen/781/pipeline.ppt

10 DM2336 PHS – Dioselin Gonzalez – 2007 S2 10 Perspective-Correct Texture Coordinate Interpolation Linearly interpolate 1/w, s/w, and t/w across the polygonLinearly interpolate 1/w, s/w, and t/w across the polygon At each pixelAt each pixel  Perform perspective division of interpolated texture coordinates (s/w, t/w) by interpolated 1/w (i.e., numerator over denominator) to get (s, t) http://www.cse.ohio-state.edu/~hwshen/781/pipeline.ppt

11 DM2336 PHS – Dioselin Gonzalez – 2007 S2 11 Perspective-Correct Interpolation That fixed it!That fixed it!

12 Background image by katosu.deviantart.com DM2336 PHS – Dioselin Gonzalez – 2007 S2 Back to the pipeline

13 DM2336 PHS – Dioselin Gonzalez – 2007 S2 13 Rasterization Convert each primitive into fragmentsConvert each primitive into fragments Fragment: “transient data structures”Fragment: “transient data structures” –position (x,y); depth; color; texture coordinates; coverage; … Application generation Application traversal Display list Evaluator Per-vertex operations & Primitive assembly Rasterization Per- fragment operations Texture memory Frame buffer Video display Pixel operations

14 DM2336 PHS – Dioselin Gonzalez – 2007 S2 14 Per fragment operations (I) Generate texel for every fragmentGenerate texel for every fragment Fog calculationsFog calculations Coverage (antialiasing) values applicationCoverage (antialiasing) values application Application generation Application traversal Display list Evaluator Per-vertex operations & Primitive assembly Rasterization Per- fragment operations Texture memory Frame buffer Video display Pixel operations

15 DM2336 PHS – Dioselin Gonzalez – 2007 S2 15 Per fragment operations (II) ScissoringScissoring Alpha testAlpha test Stencil testStencil test Depth-buffer testDepth-buffer test Application generation Application traversal Display list Evaluator Per-vertex operations & Primitive assembly Rasterization Per- fragment operations Texture memory Frame buffer Video display Pixel operations BlendingBlending Dithering and logical operationDithering and logical operation MaskingMasking

16 DM2336 PHS – Dioselin Gonzalez – 2007 S2 16 Hello world Per- fragment Operations (I) Per- vertex Operations

17 DM2336 PHS – Dioselin Gonzalez – 2007 S2 17

18 DM2336 PHS – Dioselin Gonzalez – 2007 S2 18 Vertex shader Is run once every time a vertex position is specifiedIs run once every time a vertex position is specified –glVertex, glDrawArrays, … Must compute gl_PositionMust compute gl_Position May compute gl_ClipVertex or gl_PointSizeMay compute gl_ClipVertex or gl_PointSize

19 DM2336 PHS – Dioselin Gonzalez – 2007 S2 19 Hello world

20 DM2336 PHS – Dioselin Gonzalez – 2007 S2 20

21 DM2336 PHS – Dioselin Gonzalez – 2007 S2 21 Fragment shader Is run once for every fragment producedIs run once for every fragment produced Has access to the interpolated value for each varying variableHas access to the interpolated value for each varying variable –Color, 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 fragment –gl_FragDepth – computed depth value for the fragment –gl_FragData[n] – arbitrary data per fragment, stored in multiple render targets

22 Background image by katosu.deviantart.com DM2336 PHS – Dioselin Gonzalez – 2007 S2 Playing with GLSL Demo


Download ppt "Background image by chromosphere.deviantart.com Fella in following slides by devart.deviantart.com DM2336 Programming hardware shaders Dioselin Gonzalez."

Similar presentations


Ads by Google