1 / 34

Computer Graphics SS 2014 Rasterization

Computer Graphics SS 2014 Rasterization. Rüdiger Westermann Lehrstuhl für Computer Graphik und Visualisierung. Rasterization based graphics pipeline. Concept Transforms triangles and projects the transformed triangles into the pixel raster

ganya
Télécharger la présentation

Computer Graphics SS 2014 Rasterization

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Graphics SS 2014 Rasterization Rüdiger Westermann Lehrstuhl für Computer Graphik und Visualisierung

  2. Rasterizationbasedgraphicspipeline • Concept • Transformstrianglesandprojectsthetransformedtrianglesintothepixelraster • The rasterizerdeterminesthepixelsthatarecoveredby a triangleandgenerates a fragmentforeverycoveredpixel • Performsoperations (texturing,blending)on fragments

  3. User / Driver Vertex/GeometryStage Pixel Stage Texture 0 Texture 1 Texture 2 Texture 3 Rasterizationbasedgraphicspipeline Vertex Stream Transform Rasterizer Fragment Stream Texturing Blending/Ops

  4. Rasterizationbasedgraphicspipeline • The pipelinestages Geometry Processing Modelview TransformVertices Perspective TransformVertices Geometry Scan ConversionTriangles Fragment Tests & OpsFragments FramebufferPixels TexturingFragments BlendingFragments Rasterization Fragment Processing

  5. Graphics pipeline on recentgraphicscards IB Input Data Memory VB Input Assembler Buffer Resources: Stage (IA) Buffers, Textures, Vertex Shader Texture, Constant Buffer Stage (VS) Geometryisstored in vertex, indexandattributebuffers(seechaptermodelling.sharedvertexrep.) Shadersareprogramswrittenbythegraphics programmer Geometry Shader Texture, Constant Buffer Stage (GS) Stream Output Buffer Stage (SO) Rasterizer Stage (RS) Texture, Constant Buffer Pixel Shader Stage (PS) States Output Merger Stage (OM) Output Data Buffer, Texture, Constant Buffer

  6. Programmablegraphicspipeline • Allows „almost“ arbitrarygraphicseffectsbyperformingoperations on verticesandfragments • Shadinglanguages: GLSL (OpenGL), HLSL (DirectX), Nvidia CG (both) • Syntax similarto C/C++ • Compile (atprogramstartup)  Link (shaderstages)  Run (drawobjects) • Hardware independent (compilerembeddedintodriver) • A graphicsengineprogrammerwritesshaderprograms!

  7. Rasterizationbasedgraphicspipeline • The pipelinestages Geometry Processing Modelview TransformVertices Perspective TransformVertices Geometry Scan ConversionTriangles Fragment Tests & OpsFragments FramebufferPixels TexturingFragments BlendingFragments Rasterization Fragment Processing

  8. Geometry processing • Works on vertices; performed in thevertexshaderstage Per-vertexattributes: Coordinate (x,y,z,1)Color (RGB)Normal (nx,ny,nz,0)Texturecoordinate (u,v) A setoftransformationmatrices,typicallyissued via theapplicationprogram +

  9. Geometric primitives • The GPU canonlyrendertriangles Trianglesareflat! A linear interpolationfunctionexistswithin a triangle– seebarycentricinterpolation

  10. Geometryprocessing • Transformation – cameraanalogy • Modeling: scale, rotate, translatethe model • Viewing: positionandorientationofthecamera • Projection: adjustcameralens • Viewport: photograph viewing volume camera Model

  11. Geometryprocessing • The transformationpipeline • Green: in thevertexshaderstage • Orange: in therasterizerstage Normalized device ccordinates Viewspace Objectspace Clipspace Window coordinates v e r t e x Modelview Matrix Projection Matrix Perspective Division Viewport Transform

  12. Geometryprocessing • Transformations • Transformations in homogeneouscoordinates Rotation Shear Scaling Translation Homogeneous part Projection

  13. Geometry processing • Objects are placed in the global world coordinatespace • Done via the affine modeling transformation (see chapter on transformations) Objectcoordinatesystem World coordinatesystem

  14. Geometry processing • To render a portion of the world coordinatespace, one positions and orients the camera • The same image can be shotby fixing the camera in world space (eg. at (0.0.0), orienting along (0,0,1)), and transforming objects accordingly • This is the viewing transform

  15. Geometry processing • How to build the viewing transformation • The user specifies: • Camera position C • Viewing direction D • Up vector U U D

  16. Geometry processing U • Move camera C to origin: • Translation by –C:Mtrans D U D

  17. Geometry processing • Build orthonormal frame: • „right“R = DxU • „zenith“ U= RxD(only if U and D are not orthogonal) • Adjust orientation: • Matrix [R,U,D]maps [] to [R,U,D] • So use [R,U,D]-1 • Final transform: = [R,U,D]-1Mtrans U D U D

  18. ModelviewTransformation Matrix M Geometry processing • Modeling andviewingtransform in onesingletransformThemodelviewmatrix: Vertex P Transformedvertex& normalotherattributestypicallyremainunchanged After themodelviewtransformtheverticesare in viewspace Normal N

  19. Geometryprocessing • The cameralensissetbydefiningthetransformationwhichprojectstheverticesontothescreen • This is a perspectivetransformationwiththecamerabeingthecenterofprojection y camera z screen

  20. Geometryprocessing • The perspectiveprojectionisdefinedbyspecifyingthe so calledviewfrustum • The field of view of the camera, or the region of space that is mapped onto the image plane • Defined by the field of view angle (in the 'y' direction), front & near plane, aspect ratio; or alternatively by n = near, f = far, r= right, l = left, t = top, b= bottom (r,t,f) (r,t,n) width (l,b,n) fov height

  21. Perspective Projections y eye z View Coordinates are perspectivelydistorted … near far y eye at infinity z near far

  22. De-Homogenization • Observation:To project ontoz=1, dividecomponentsbyz y 1 z

  23. Perspectiveprojections • Matrix representation of the standard projection onto the z= 1 plane • Note that a division by one of the vector components cannot be realized as a matrix-vector operation • Thus, projection in two step: 1. matrix-vector operation to bring z component into the 4th component, 2. divide through 4th component

  24. Perspective Projections • The projectionmatrix (n = near, f = far) • Not complete,seelater

  25. Perspective Projections • Examples Point on near plane remains on near plane Point on far plane remains on far plane Point on near plane remainsunchanged on near plane

  26. Perspective Projections • Examples Point on far plane moves on far plane Points betweennearandfarmovetowardsfar plane Assume n = 1, f = 2, z = 1.5  z = 5/3 > 1.5

  27. Perspective Projections y eye at infinity View Coordinates arefinally transformed Into Normalized Device Coordinates z near far y 1 eye at infinity –1 1 z –1

  28. Perspective Projections View frustum • The API projectionmatrix • n = near, f = far, r = right, l = left, t = top, b = bottom • Scalesthetransformedfrustumto -1,1 andcentersaround (0,0,0) via a translation (r,t,f) (r,t,n) (l,b,n)

  29. PerspectiveProjections • Modelview and perspective transformation in one single transformation vertex transformation: perspective (homogeneous) division: =

  30. Rasterization normalized device view object homogeneousclip window v e r t e x Modelview Matrix Projection Matrix Perspective Division Viewport Transform transformedvertices Rasterization Fragment Generation fragments Green: in thevertexshaderstage Orange: in therasterizerstage

  31. Rasterization • Viewport transformationmapsfrom NDC (Normalized Device Coordinates) topixelcoordinates • Example: Px = 1024, Py = 512  • (613, 306) arethepixelcoordinatesofthevertex Py 1 WindowCoordinates Normalized Device Coordinates -1 1 Px -1

  32. Rasterizationbasedgraphicspipeline • Resultofvertexshaderstage • Homogeneousvertexcoordinates after perspectiveprojection • (modelviewtransformed) normals • Additional attributeslikecolorandtexturecoordinates • The transformed, attributedvertexstreamispassedtotherasterizerstage • The rasterizerperformsdivisionbyw andmaps NDC topixelcoordinates • Foreachtriangle, therasterizerdeterminesthepixelscoveredbythistriangle – foreach such pixel a fragmentisgenerated • Per-vertex attributesareinterpolatedtoeachfragment

  33. Rasterization • Fragment generation: foreachcoveredpixel, onefragmentisgenerated • Foreachfragment: per-vertex attributes (color, normal, z-value, texturecoordinates,…) areinterpolated at pixelcenter via barycentricinterpolation

  34. Rasterization • Resultofrasterizationstage:A setoffragments, eachstoringitspixelcoordinateaswellasinterpolated z-value, color, texturecoordinate, normal, etc. A fragmentis in fact a surfacepointseenthroughtherespectivepixel X,Y z RGB u,v …

More Related