Rasterization & the Graphics Pipeline 15.1 Rasterization Basics
Total Page:16
File Type:pdf, Size:1020Kb
1 1 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 15.1Rasterization Basics Rasterization & TheGraphics Pipeline Rasterization& -1 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 In This Video • The Graphics Pipeline and how it processes triangles – Projection, rasterisation, shading, depth testing • DirectX12 and its stages 2 Modern Graphics Pipeline • Input – Geometric model • Triangle vertices, vertex normals, texture coordinates – Lighting/material model (shader) • Light source positions, colors, intensities, etc. • Texture maps, specular/diffuse coefficients, etc. – Viewpoint + projection plane – You know this, you’ve done it! • Output – Color (+depth) per pixel Colbert & Krivanek 3 The Graphics Pipeline • Project vertices to 2D (image) • Rasterize triangle: find which pixels should be lit • Compute per-pixel color • Test visibility (Z-buffer), update frame buffer color 4 The Graphics Pipeline • Project vertices to 2D (image) • Rasterize triangle: find which pixels should be lit – For each pixel, test 3 edge equations • if all pass, draw pixel • Compute per-pixel color • Test visibility (Z-buffer), update frame buffer color 5 The Graphics Pipeline • Perform projection of vertices • Rasterize triangle: find which pixels should be lit • Compute per-pixel color • Test visibility, update frame buffer color – Store minimum distance to camera for each pixel in “Z-buffer” • ~same as tmin in ray casting! – if new_z < zbuffer[x,y] zbuffer[x,y]=new_z framebuffer[x,y]=new_color frame buffer Z buffer 6 The Graphics Pipeline For each triangle transform into eye space (perform projection) setup 3 edge equations for each pixel x,y if passes all edge equations compute z if z<zbuffer[x,y] zbuffer[x,y]=z framebuffer[x,y]=shade() 7 (Simplified version) DirectX 12 Pipeline (Vulkan & Metal are highly similar) Vertex & Textures, index data etc. Input Vertex Hull Domain Geometry Pixel Tessellator Rasterizer assembly shader shader shader shader shader Frame buffer (output picture) Fixed-function hardware Programmable stage Memory input/output 8 DirectX 12 Pipeline (Simplified version) Vertex & Textures, index data etc. Input Vertex Hull Domain Geometry Pixel Tessellator Rasterizer assembly shader shader shader shader shader Frame 1. Project vertices to 2D (image) buffer (output picture) Fixed-function hardware Programmable stage Memory input/output 9 DirectX 12 Pipeline (Simplified version) Vertex & Textures, index data etc. Input Vertex Hull Domain Geometry Pixel Tessellator Rasterizer assembly shader shader shader shader shader Frame 1. Project vertices to 2D (image) buffer 2. Figure out which pixels to draw (output picture) Fixed-function hardware Programmable stage Memory input/output 10 DirectX 12 Pipeline (Simplified version) Vertex & Textures, index data etc. Input Vertex Hull Domain Geometry Pixel Tessellator Rasterizer assembly shader shader shader shader shader Frame 1. Project vertices to 2D (image) buffer 2. Figure out which pixels to draw (output 3. Compute per-pixel color picture) Fixed-function hardware Programmable stage Memory input/output 11 DirectX 12 Pipeline (Simplified version) Vertex & Textures, index data etc. Input Vertex Hull Domain Geometry Pixel Tessellator Rasterizer assembly shader shader shader shader shader Frame 1. Project vertices to 2D (image) buffer 2. Figure out which pixels to draw (output 3. Compute per-pixel color picture) 4. Test depth and update frame buffer (“ROP”) Fixed-function hardware Programmable stage Memory input/output 12 DirectX 12 Pipeline (Simplified version) Vertex & Textures, index data etc. Input Vertex Hull Domain Geometry Pixel Tessellator Rasterizer assembly shader shader shader shader shader Frame Programmable vertex processing and buffer (output tessellation allow all kinds of fun picture) shenanigans – don’t hesitate to explore for extra credit! Fixed-function hardware Programmable stage Memory input/output 13.