Loading in 5 sec....

Computer Graphics SS 2014 RasterizationPowerPoint Presentation

Computer Graphics SS 2014 Rasterization

- 155 Views
- Uploaded on
- Presentation posted in: General

Computer Graphics SS 2014 Rasterization

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Computer Graphics

SS 2014

Rasterization

Rüdiger Westermann

Lehrstuhl für Computer Graphik und Visualisierung

- Concept
- Transformstrianglesandprojectsthetransformedtrianglesintothepixelraster
- The rasterizerdeterminesthepixelsthatarecoveredby a triangleandgenerates a fragmentforeverycoveredpixel
- Performsoperations (texturing,blending)on fragments

User / Driver

Vertex/GeometryStage

Pixel Stage

Texture 0

Texture 1

Texture 2

Texture 3

Vertex Stream

Transform

Rasterizer

Fragment Stream

Texturing

Blending/Ops

- The pipelinestages

Geometry Processing

Modelview

TransformVertices

Perspective

TransformVertices

Geometry

Scan

ConversionTriangles

Fragment

Tests & OpsFragments

FramebufferPixels

TexturingFragments

BlendingFragments

Rasterization

Fragment Processing

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

- 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!

- The pipelinestages

Geometry Processing

Modelview

TransformVertices

Perspective

TransformVertices

Geometry

Scan

ConversionTriangles

Fragment

Tests & OpsFragments

FramebufferPixels

TexturingFragments

BlendingFragments

Rasterization

Fragment 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

+

- The GPU canonlyrendertriangles

Trianglesareflat!

A linear interpolationfunctionexistswithin a triangle– seebarycentricinterpolation

- Transformation – cameraanalogy
- Modeling: scale, rotate, translatethe model
- Viewing: positionandorientationofthecamera
- Projection: adjustcameralens
- Viewport: photograph

viewing volume

camera

Model

- 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

- Transformations
- Transformations in homogeneouscoordinates

Rotation

Shear

Scaling

Translation

Homogeneous part

Projection

- Objects are placed in the global world coordinatespace
- Done via the affine modeling transformation (see chapter on transformations)

Objectcoordinatesystem

World coordinatesystem

- 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

- How to build the viewing transformation
- The user specifies:
- Camera position C
- Viewing direction D
- Up vector U

- The user specifies:

U

D

U

- Move camera C to origin:
- Translation by –C:Mtrans

D

U

D

- 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

ModelviewTransformation

Matrix M

- Modeling andviewingtransform in onesingletransformThemodelviewmatrix:

Vertex P

Transformedvertex& normalotherattributestypicallyremainunchanged

After themodelviewtransformtheverticesare in viewspace

Normal N

- The cameralensissetbydefiningthetransformationwhichprojectstheverticesontothescreen
- This is a perspectivetransformationwiththecamerabeingthecenterofprojection

y

camera

z

screen

- 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

y

eye

z

View

Coordinates

are

perspectivelydistorted

…

near

far

y

eye

at

infinity

z

near

far

- Observation:To project ontoz=1, dividecomponentsbyz

y

1

z

- 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

- The projectionmatrix (n = near, f = far)
- Not complete,seelater

- 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

- 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

y

eye

at

infinity

View

Coordinates

arefinally

transformed

Into

Normalized Device

Coordinates

z

near

far

y

1

eye

at

infinity

–1

1

z

–1

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)

- Modelview and perspective transformation in one single transformation
vertex transformation:

perspective (homogeneous) division: =

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

- 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

- 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

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

- Resultofrasterizationstage:A setoffragments, eachstoringitspixelcoordinateaswellasinterpolated z-value, color, texturecoordinate, normal, etc. A fragmentis in fact a surfacepointseenthroughtherespectivepixel

X,Y

z

RGB

u,v

…