CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
Advertisements

CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
Graphics Pipeline.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
Computer Graphics Lecture 8 Arbitrary Viewing II: More Projection, Clipping and Mathematics of 3D Viewing.
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a.
Computer Graphics Viewing.
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
Implementation Dr. Amy Zhang. Reading 2  Hill, Chapters  Hill, Chapter 10.
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
1 Jinxiang Chai CSCE 441 Computer Graphics. 2 Midterm Time: 10:10pm-11:20pm, 10/20 Location: HRBB 113.
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Clipping.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Chapter 7: From Vertices to Fragments Ed Angel Professor of Computer Science, Electrical.
CS 352: Computer Graphics Chapter 8: The Rendering Pipeline.
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Objectives Introduce basic implementation strategies Clipping Scan conversion.
From Vertices to Fragments Chapter 7. Part I Objectives Introduce basic implementation strategies Introduce basic implementation strategies Clipping Clipping.
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
Week 2 - Friday.  What did we talk about last time?  Graphics rendering pipeline  Geometry Stage.
CS 480/680 Computer Graphics Implementation III Dr. Frederick C Harris, Jr. Fall 2011.
CS 638, Fall 2001 Multi-Pass Rendering The pipeline takes one triangle at a time, so only local information, and pre-computed maps, are available Multi-Pass.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Week 3 Lecture 1: Implementation Based on Interactive Computer Graphics (Angel) - Chapter.
CSE Real Time Rendering Week 9. Post Geometry Shaders Courtesy: E. Angel and D. Shreiner – Interactive Computer Graphics 6E © Addison-Wesley 2012.
1Computer Graphics Implementation II Lecture 16 John Shearer Culture Lab – space 2
Implementation II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Implementation II.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Implementation of a Renderer Consider Programs are processd by the system line & polygon, outside the view volume Efficiently Understanding of the implementation.
Computer Graphics Lecture 20 Fasih ur Rehman. Last Class Clipping – What is clipping – Why we do clipping – How clipping is done.
Computer Graphics I, Fall 2010 Implementation II.
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
COMPUTER GRAPHICS CS 482 – FALL 2015 NOVEMBER 10, 2015 VISIBILITY CULLING HIDDEN SURFACES ANTIALIASING HALFTONING.
Lecture 9 From Vertices to Fragments. Objectives Introduce basic implementation strategies Clipping Rasterization hidden-surface removal.
Computer Graphics I, Fall 2010 Scan conversion algorithms.
Chapter 71 Computer Graphics - Chapter 7 From Vertices to Fragments Objectives are: How your program are processed by the system that you are using, Learning.
CS 352: Computer Graphics Chapter 8: The Rendering Pipeline.
Computer Graphics Clipping.
Computer Graphics Implementation II
Week 7 - Monday CS361.
Week 2 - Friday CS361.
The Rendering Pipeline
Computer Graphics CC416 Week 13 Clipping.
Transformations contd.
Computer Graphics Shading in OpenGL
3D Clipping.
The Graphics Rendering Pipeline
Real-time Computer Graphics Overview
Implementation I Ed Angel
Graphics Pipeline Clipping
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
Implementation II Ed Angel Professor Emeritus of Computer Science
Course code: 10CS65 | Computer Graphics and Visualization
Lecture 13 Clipping & Scan Conversion
Introduction to Computer Graphics with WebGL
From Vertices To Fragments
Clipping University of British Columbia CPSC 314 Computer Graphics
Implementation I Ed Angel Professor Emeritus of Computer Science
Implementation II Ed Angel Professor Emeritus of Computer Science
From Vertex to Fragment
Presentation transcript:

CS 352: Computer Graphics Chapter 7: The Rendering Pipeline

Interactive Computer GraphicsChapter Overview Geometric processing: normalization, clipping, hidden surface removal, lighting, projection (front end) Rasterization or scan conversion, including texture mapping (back end) Fragment processing and display

Interactive Computer GraphicsChapter Geometric Processing Front-end processing steps (3D floating point; may be done on the CPU) Evaluators (converting curved surfaces to polygons) Normalization (modeling transform, convert to world coordinates) Projection (convert to screen coordinates) Hidden-surface removal (object space) Computing texture coordinates Computing vertex normals Lighting (assign vertex colors) Clipping Perspective division Backface culling

Interactive Computer GraphicsChapter Rasterization Back-end processing works on 2D objects in screen coordinates Processing includes Scan conversion of primitives including shading Texture mapping Fog Scissors test Alpha test Stencil test Depth-buffer test Other fragment operations: blending, dithering, logical operations

Interactive Computer GraphicsChapter Display Convert frame buffer to video signal Other considerations: Color correction Antialiasing

Interactive Computer GraphicsChapter Geometric Transformations Five coordinate systems of interest: Object coordinates Eye (world) coordinates [after modeling transform, viewer at the origin] Clip coordinates [after projection] Normalized device coordinates [after ÷w] Window (screen) coordinates [scale to screensize]

Interactive Computer GraphicsChapter Line-Segment Clipping Clipping may happen in multiple places in the pipeline (e.g. early trivial accept/reject) After projection, have lines in plane, with rectangle to clip against

Interactive Computer GraphicsChapter Clipping a Line Against x min Given a line segment from (x 1,y 1 ) to (x 2,y 2 ), Compute m=(y 2 –y 1 )/(x 2 –x 1 ) Line equation: y = mx + h h = y 1 – m x 1 (y intercept) Plug in x min to get y Check if y is between y 1 and y 2. This take a lot of floating-point math. How to minimize?

Interactive Computer GraphicsChapter Cohen-Sutherland Clipping For both endpoints compute a 4-bit outcode (o 1, o 2 ) depending on whether coordinate is outside cliprect side Some situations can be handled easily

Interactive Computer GraphicsChapter Cohen-Sutherland Conditions Cases. 1. If o 1 =o 2 =0, accept 2. If one is zero, one nonzero, compute an intercept. If necessary compute another intercept. Accept. 3. If o 1 & o 2  0. If both outcodes are nonzero and the bitwise AND is nonzero, two endpoints lie on same outside side. Reject. 3. If o 1 & o 2  0. If both outcodes are nonzero and the bitwise AND is zero, may or may not have to draw the line. Intersect with one of the window sides and check the result.

Interactive Computer GraphicsChapter Cohen-Sutherland Results In many cases, a few integer comparisons and Boolean operations suffice. This algorithm works best when there are many line segments, and most are clipped But note that the y=mx+h form of equation for a line doesn’t work for vertical lines (need a special case in your code)

Interactive Computer GraphicsChapter Polygon Clipping Clipping a polygon can result in lots of pieces Replacing one polygon with many may be a problem in the rendering pipeline Could treat result as one polygon: but this kind of polygon can cause other difficulties Some systems allow only convex polygons, which don’t have such problems (OpenGL has tessellate function in glu library)

Interactive Computer GraphicsChapter Sutherland-Hodgeman Polygon Clipping Could clip each edge of polygon individually Pipelined approach: clip polygon against each side of rectangle in turn Treat clipper as “black box” pipeline stage

Interactive Computer GraphicsChapter Clipping Pipeline Clip each bound in turn

Interactive Computer GraphicsChapter Clipping in Hardware Build the pipeline stages in hardware so you can perform four clipping stages at once [A partial answer to the question of what to do with all that chip area, 1 billion + transistors…]

Interactive Computer GraphicsChapter Clipping complicated objects Suppose you have many complicated objects, such as models of parts of a person with thousands of polygons each When and how to clip for maximum efficiency? How to clip text? Curves?

Interactive Computer GraphicsChapter Clipping Other Primitives It may help to clip more complex shape early in the pipeline This may be simpler and less accurate One approach: bounding boxes (sometimes called trivial accept-reject) This is so useful that modeling systems often store bounding box

Interactive Computer GraphicsChapter Clipping Curves, Text Some shapes are so complex that they are difficult to clip analytically Can approximate with line segments Can allow the clipping to occur in the frame buffer (pixels outside the screen rectangle aren’t drawn) Called “scissoring” How does performance compare?

Interactive Computer GraphicsChapter Hidden surface removal Object space vs. Image space The main image-space algorithm: depth buffer Drawbacks Aliasing Rendering invisible objects Doesn’t handle transparency correctly How would object-space hidden surface removal work?

Interactive Computer GraphicsChapter Depth sorting The painter’s algorithm: draw from back to front Depth-sort hidden surface removal: sort display list by z-coordinate from back to front render Drawbacks it takes some time (especially with bubble sort!) it doesn’t work

Interactive Computer GraphicsChapter Depth-sort difficulties Polygons with overlapping projections Cyclic overlap Interpenetrating polygons What to do?

Interactive Computer GraphicsChapter Scan Conversion At this point in the pipeline, we have only polygons and line segments. Render! To render, convert to pixels (“fragments”) with integer screen coordinates (ix, iy), depth, and color Send fragments into fragment-processing pipeline

Interactive Computer GraphicsChapter Rendering Line Segments How to render a line segment from (x 1, y 1 ) to (x 2, y 2 )? Use the equation y = mx + h What about horizontal vs. vertical lines?

Interactive Computer GraphicsChapter DDA Algorithm DDA: Digital Differential Analyzer for (x=x 1 ; x<=x 2 ; x++) y += m; draw_pixel(x, y, color) Handle slopes 0 <= m <= 1; handle others symmetrically Does this need floating point math?

Interactive Computer GraphicsChapter Bresenham’s Algorithm The DDA algorithm requires a floating point add and round for each pixel: eliminate? Note that at each step we will go E or NE. How to decide which? −

Interactive Computer GraphicsChapter Bresenham Decision Variable Note that at each step we will go E or NE. How to decide which? Hint: consider d=a-b, where a and b are distances to NE and E pixels −

Interactive Computer GraphicsChapter Bresenham Decision Variable Bresenham algorithm uses decision variable d=a-b, where a and b are distances to NE and E pixels If d 0, go E Let d x = x 2 -x 1, d y =y 2 -y 1 Use decision variable d = d x (a-b) [only sign matters] −

Interactive Computer GraphicsChapter Bresenham Decision Variable d =(a-b) d x Let d k be the value of d at x = k + ½ Move E: d k = d x (a-b) = d x ((j+3/2–y k ) – (y k –(j+1/2))) d k+1 = d x (a-b) = d x ((j+3/2–y k –m) – (y k +m–(j+1/2))) d x+1 – d k = d x (-2m) = - 2 d Y Algorithm: d k+1 = d k – 2 d y (if d k > 0) (last move was E) d k+1 = d k – 2 (d y -d x ) (if d k <= 0) (last move was NE) −

Interactive Computer GraphicsChapter Bresenham’s Algorithm Set up loop computing d at x 1, y 1 for (x=x 1 ; x<=x 2 ; ) x++; d += 2dy; if (d >= 0) { y++; d –= 2dx; } drawpoint(x,y); Pure integer math, and not much of it So easy that it’s usually implemented in one graphics instruction for several points in parallel

Interactive Computer GraphicsChapter Rasterizing Polygons Polygons may be or may not be simple, convex, flat. How to render? Amounts to inside-outside testing: how to tell if a point is in a polygon?

Interactive Computer GraphicsChapter Winding Test Most common way to tell if a point is in a polygon: the winding test. Define “winding number” w for a point: signed number of revolutions around the point when traversing boundary of polygon once When is a point “inside” the polygon?

Interactive Computer GraphicsChapter OpenGL and Complex Polygons OpenGL guarantees correct rendering only for simple, convex, planar polygons OpenGL tessellates concave polygons Tessellation depends on winding rule you tell OpenGL to use: Odd, Nonzero, Pos, Neg, ABS_GEQ_TWO

Interactive Computer GraphicsChapter Winding Rules

Interactive Computer GraphicsChapter Scan-Converting a Polygon General approach: ideas? One idea: flood fill Draw polygon edges Pick a point (x,y) inside and flood fill with DFS flood_fill(x,y) { if (read_pixel(x,y)==white) { write_pixel(x,y,black); flood_fill(x-1,y); flood_fill(x+1,y); flood_fill(x,y-1); flood_fill(x,y+1);}

Interactive Computer GraphicsChapter Scan-Line Approach More efficient: use a scan-line rasterization algorithm For each y value, compute x intersections. Fill according to winding rule How to compute intersection points? How to handle shading? Some hardware can handle multiple scanlines in parallel

Interactive Computer GraphicsChapter Singularities If a vertex lies on a scanline, does that count as 0, 1, or 2 crossings? How to handle singularities? One approach: don’t allow. Perturb vertex coordinates OpenGL’s approach: place pixel centers half way between integers (e.g. 3.5, 7.5), so scanlines never hit vertices

Interactive Computer GraphicsChapter Aliasing How to render the line with reduced aliasing? What to do when polygons share a pixel?

Interactive Computer GraphicsChapter Anti-Aliasing Simplest approach: area-based weighting Fastest approach: averaging nearby pixels Most common approach: supersampling (compute four values per pixel and avg, e.g.) Best approach: weighting based on distance of pixel from center of line; Gaussian fall-off

Interactive Computer GraphicsChapter Temporal Aliasing Need motion blur for motion that doesn’t flicker Common approach: temporal supersampling render images at several times within frame time interval average results

Interactive Computer GraphicsChapter Display Considerations Color systems Color quantization Gamma correction Dithering and Halftoning

Interactive Computer GraphicsChapter Additive and Subtractive Color

Interactive Computer GraphicsChapter Common Color Models

Interactive Computer GraphicsChapter Color Systems RGB YIQ CMYK HSV, HLS Chromaticity Color gamut

Interactive Computer GraphicsChapter HLS Hue: “direction” of color: red, green, purple, etc. Saturation: intensity. E.g. red vs. pink Lightness: how bright To the right: original, H, S, L

Interactive Computer GraphicsChapter YIQ Used by NTSC TV Y = luma, same as black and white I = in-phase Q = quadrature The eye is more sensitive to blue-orange than purple-green, so more bandwidth is allotted Y = 4 MHz, I = 1.3 MHz, Q = 0.4 MHz, overall bandwidth 4.2 MHz Linear transformation from RBG: Y = R G B I = R – G – B Q = R – G B

Interactive Computer GraphicsChapter Chromaticity Color researchers often prefer chromaticity coordinates: t1 = T1 / (T1 + T2 + T3) t2 = T2 / (T1 + T2 + T3) t3 = T3 / (T1 + T2 + T3) Thus, t1+t2+t3 = 1.0. Use t1 and t2; t3 can be computed as 1-t1-t2 Chromaticity diagram uses XYZ color system based on human perception experiments Y, luminance X, redness (roughly) Z, blueness (roughly)

Interactive Computer GraphicsChapter Color temperature Compute color temperature by comparing chromaticity with that of an ideal black- body radiator Color temperature is that were the headed black- body radiator matches color of light source Higher temperatures are “cooler” colors – more green/blue; warmer colors (yellow-red) have lower temperatures CIE 1931 chromaticity diagram (wikipedia)

Interactive Computer GraphicsChapter Halftoning How do you render a colored image when colors can only be on or off (e.g. inks, for print)? Halftoning: dots of varying sizes [But what if only fixed-sized pixels are available?]

Interactive Computer GraphicsChapter Dithering Dithering (patterns of b/w or colored dots) used for computer screens OpenGL can dither But, patterns can be visible and bothersome. A better approach?

Interactive Computer GraphicsChapter Floyd-Steinberg Error Diffusion Dither Spread out “error term” 7/16 right 3/16 below left 5/16 below 1/16 below right Note that you can also do this for color images (dither a color image onto a fixed 256-color palette)

Interactive Computer GraphicsChapter Color Quantization Color quantization: modifying a full-color image to render with a 256-color palette For a fixed palette (e.g. web-safe colors), can use closest available color, possibly with error-diffusion dither Algorithm for selecting an adaptive palette? E.g. Heckbert Median-Cut algorithm Make a 3-D color histogram Recursively cut the color cube in half at a median Use average color from each resulting box

Interactive Computer GraphicsChapter Hardware Implementations Pipeline architecture for speed (but what about latency?) Originally, whole pipeline on CPU Later, back-end on graphics card Then, whole pipeline in hardware on graphics card Then, parts of pipeline done on GPUs Now, hardware pipeline is gone—done in software on a large number of GPUs

Interactive Computer GraphicsChapter Future Architectures? 20 years ago, performance of 1 M polygons per second cost millions Performance limited by memory bandwidth Main component of price was lots of memory chips Now an iPhone 5 does 115 million triangles (1.8 billion texels) per second Fastest performance today achieved with many cores on each graphics chip (and several chips in parallel) How to use parallel graphics cores/chips? All vertices go through vertex shaders – can do in parallel All fragments go through fragment shaders – can do in parallel Resulting fragments combined into a single image – easy with sufficient memory bandwidth

NVidia GeForce GTX 590 Facts “Most powerful graphics card ever built” (of 2011) Dual 512-core GTX 500 GPUs (1024 CUDA unified shaders) 2 x 16 Streaming Multiprocessor (SM) processor groups, each with 32 Streaming Processors (SPs) PhysX physics engine on the card (used for flowing clothing, smoke, debris, turbulence, etc) Memory bandwidth: GB/sec Texture fill rate: 77.7 billion/sec 4X antialiasing 3 billion transistors x 2 Real-time ray tracing Power: 365 w Interactive Computer GraphicsChapter