250 likes | 615 Views
Rasterization. COMP 5411: ADVANCED COMPUTER GRAPHICS FALL 2013. Major steps of rendering pipeline. Vertex processing Triangle rasterization Pixel processing. Rasterization. From vertices and primitives to pixels (basics covered earlier in course). Before we start. Front-faces.
E N D
Rasterization COMP 5411: ADVANCED COMPUTER GRAPHICSFALL 2013
Major steps of rendering pipeline Vertex processing Triangle rasterization Pixel processing
Rasterization From vertices and primitives to pixels (basics covered earlier in course)
Backface culling 2 2 3 3 1 1 • Don’t rasterize back-facing triangles • Or front-facing, you decide • Points and lines are always rasterized • One possible implementation • Look at 2D screen coordinates • Two possible orientations • No relation to vertex normals
What if triangles share an edge? Image from “Advanced Rasterization”,Nicolas Capens, 2004 • Missing or repeated fragments • Neither triangle emits, both of them emit • Cracks or overdraw (when blending)
The top-left rule Image from “Advanced Rasterization”,Nicolas Capens, 2004 • Pixel center inside: emit fragment • Center on edge: emit if top edge or left edge • Top edges are horizontal and above all others • Left edges are not horizontal and are to the left • Triangles can have one or two left edges
Top-rule examples Image from “Microsoft’s Direct3D 10 Rasterization Rules”, 2010
Interpolation Hardware does perspective correct interpolation Vertex shader == Pixel shaderoutput structure input structure
The Z-Buffer Algorithm • Now that we have Z, we can compute visibility! • Use depth values from interpolation • Use an additional buffer to hold depth values • Render primitives in arbitrary order • Record their depths in the depth buffer • If the depth of a fragment about to be drawn is greater than what’s already there, throw it away • Image precision hidden surface removal (Covered earlier in class)
Early Z culling When a fragment fails the Z-test, it can’t modify the frame-buffers What is the point of shading such fragments? Hardware tests Z first, and only runs shader on fragments that pass the Z-test
HiZ culling • Hardware keeps a coarse version of Z-buffer • Stores maximum depth over a region • Entire blocks of fragments can be rejected • If min of new block larger than max of HiZ • Saves bandwidth and improves performance
Keep Early Z and HiZ in mind • What happens if you modify Z inside a shader? • Early Z-culling and HiZ are disabled • Significant slowdown • What happens if you render back to front? • Early Z-culling and HiZ are ineffective • A lot of overdraw • Significant slowdown • You should try to render front to back • Counter-intuitive • Opposite of Painter’s algorithm
Triangle rasterization issues Images from “Triangle Rasterization” Brandon Lloyd, 2007 Sliver triangles
Triangle rasterization issues Images from “Triangle Rasterization” Brandon Lloyd, 2007 Moving sliver triangles
Supersampling in hardware Hardware support for higher-quality strategies FSAA, MSAA, CSAA
Full-scene antialiasing (FSAA) 2 samples 2 taps Sample more than once per pixel (samples) Filter to produce final pixel color (taps) There are many, many different options
Full-scene antialiasing (FSAA) 2 samples 5 taps QUINCUNX Sample more than once per pixel (samples) Filter to produce final pixel color (taps) There are many, many different strategies
FSAA comparison Images from “OpenGL Multisample” Sébastien Dominé, 2002
FSAA comparison Images from “OpenGL Multisample” Sébastien Dominé, 2002
Full-scene antialiasing (FSAA) 4 samples 4 taps RGSS 2 samples 4 taps FLIPQUAD Humans find aliasing at angles close to vertical and horizontal to be more disturbing Use pattern with more resolution for same cost
Multisampleantialiasing (MSAA) • Rasterize at higher resolution • Shade at fragment resolution • Solves aliasing only across polygon edges • Which is usually more problematic • Smaller computational cost • Same memory cost
Interesting new hardware functionality • Pixel shaders have access to subpixel position • Pixel shaders can set coverage mask • Pixel shaders can choose where to evaluate interpolated attributes • In other words • Rasterizer is slowly becoming programmable