CS 3388 Rendering Pipelines: Ray Casting vs Rasterization [Hill §12.1—12.3,7.4,3.2.2] TexPoint fonts used in EMF. Read the TexPoint manual before you delete.

Slides:



Advertisements
Similar presentations
Lecture 8 Transparency, Mirroring
Advertisements

Technische Universität München Computer Graphics SS 2014 Graphics Effects Rüdiger Westermann Lehrstuhl für Computer Graphik und Visualisierung.
Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Graphics Pipeline.
3D Graphics Rendering and Terrain Modeling
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
Introduction to 3D Graphics Lecture 5: From Realism to Real-Time Anthony Steed University College London.
1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Interpolation Clipping.
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
CS 4731: Computer Graphics Lecture 14: 3D Clipping and Viewport Transformation Emmanuel Agu.
HCI 530 : Seminar (HCI) Damian Schofield.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
CS 4731: Computer Graphics Lecture 18: Hidden Surface Removal Emmanuel Agu.
Game Engine Design ITCS 4010/5010 Spring 2006 Kalpathi Subramanian Department of Computer Science UNC Charlotte.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
1 Chapter 5 Viewing. 2 Perspective Projection 3 Parallel Projection.
Part I: Basics of Computer Graphics Rendering Polygonal Objects (Read Chapter 1 of Advanced Animation and Rendering Techniques) Chapter
2/26/04© University of Wisconsin, CS559 Spring 2004 Last Time General Orthographic Viewing –Specifying cameras in world coordinates –Building world  view.
09/18/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms.
Cornell CS465 Fall 2004 Lecture 3© 2004 Steve Marschner 1 Ray Tracing CS 465 Lecture 3.
Computer Graphics Mirror and Shadows
COMP 175: Computer Graphics March 24, 2015
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
02/26/02 (c) 2002 University of Wisconsin, CS 559 Last Time Canonical view pipeline Orthographic projection –There was an error in the matrix for taking.
MIT EECS 6.837, Durand and Cutler Graphics Pipeline: Projective Transformations.
2 COEN Computer Graphics I Evening’s Goals n Discuss the mathematical transformations that are utilized for computer graphics projection viewing.
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by David Luebke)
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CAP4730: Computational Structures in Computer Graphics 3D Transformations.
Programming 3D Applications CE Displaying Computer Graphics Week 3 Lecture 5 Bob Hobbs Faculty of Computing, Engineering and Technology Staffordshire.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Games Development 1 Camera Projection / Picking CO3301 Week 8.
Hidden Surface Removal
CS 450: COMPUTER GRAPHICS PROJECTIONS SPRING 2015 DR. MICHAEL J. REALE.
1 Visiblity: Culling and Clipping Computer Graphics COMP 770 (236) Spring 2009 January 21 & 26: 2009.
David Luebke11/26/2015 CS 551 / 645: Introductory Computer Graphics David Luebke
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
Computer Graphics Lecture 08 Fasih ur Rehman. Last Class Ray Tracing.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Three-Dimensional Viewing Hearn & Baker Chapter 7
Foundations of Computer Graphics (Spring 2012) CS 184, Lecture 5: Viewing
Implementation of a Renderer Consider Programs are processd by the system line & polygon, outside the view volume Efficiently Understanding of the implementation.
©2005, Lee Iverson Lee Iverson UBC Dept. of ECE EECE 478 Viewing and Projection.
MIT EECS 6.837, Durand and Cutler The Graphics Pipeline: Projective Transformations.
Chapter III Rasterization
1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection.
Rendering Pipeline Fall, D Polygon Rendering Many applications use rendering of 3D polygons with direct illumination.
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 29, 2015 RENDERING RASTERIZATION RAY CASTING PROGRAMMABLE SHADERS.
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
RENDERING : Global Illumination
OpenGL and You I Cast, Therefore I Am. Ray Casting Idea is simple, implementation takes some work –Cast rays as if you were the camera –Determine intersection.
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
Computer Graphics One of the central components of three-dimensional graphics has been a basic system that renders objects represented by a set of polygons.
Viewing. Classical Viewing Viewing requires three basic elements - One or more objects - A viewer with a projection surface - Projectors that go from.
Lecture 9 From Vertices to Fragments. Objectives Introduce basic implementation strategies Clipping Rasterization hidden-surface removal.
Rendering Pipeline Fall, 2015.
- Introduction - Graphics Pipeline
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2016
3D Graphics Rendering PPT By Ricardo Veguilla.
3D Clipping.
CS451Real-time Rendering Pipeline
Computer Graphics One of the central components of three-dimensional graphics has been a basic system that renders objects represented by a set of polygons.
Projection in 3-D Glenn G. Chappell
The Graphics Pipeline Lecture 5 Mon, Sep 3, 2007.
Chapter V Vertex Processing
Lecture 13 Clipping & Scan Conversion
Clipping University of British Columbia CPSC 314 Computer Graphics
Presentation transcript:

CS 3388 Rendering Pipelines: Ray Casting vs Rasterization [Hill §12.1—12.3,7.4,3.2.2] TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A A A A A A A

“Rendering” Generate visual representation of computer’s internal model Inverse problem:. Computer Vision 2 output: bitmap of rendered scene input: computer model of 3D scene computer model of camera rendering ? input: bitmap output: model

“Rendering” Problem: determine colour of every pixel Two major approaches: – ray tracing (“trace pixel’s path to the objects”) – rasterization (“project object onto image plane”) 3 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

Important facts about light: – travels along straight lines (geodesics, in general) – can reflect off surface, but usually scatters Ray Casting: “what surface point would send light into eye through this pixel?” Ray Tracing: “what is total amount of light that would really arrive at that surface point?” Ray Casting vs Ray Tracing 4 forward propagation of photons (only tiny fraction enter eye) ray casting

Light Isn’t Obvious Pythagoras (582—500BC) thought eyes sent out ‘feeler rays’ to sense objects 5 a b c “light consists of rays that, acting like feelers, travel in straight lines from the eye to the object, and the sensation of sight is obtained when these rays touch the object, much like the sense of touch.”

Aside: “Helmholtz Reciprocity” Can interchange light and camera, yet camera sees identical shading at fixed 3D point 6

Ray Casting Photon reaching eye through pixel ( i, j ) traveled on straight path from final surface Find closest intersection on eye-pixel ray! Called primary rays pixel grid ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² ² path photon would take wd £ ht pixels Assuming canonical view frustum:

Ray casting makes very local assumptions: – that photons arrive directly from a light source – that photons are never ‘blocked’ (no hard shadows) Hack: angle of light-ray, primary-ray, and normal determine colour Ray Casting 8 path photon would take We cover ray tracing for assignment 4!

Ray Casting Loop Really simple to implement Trivially parallelizable 9 // pseudocode for ray casting (wd,ht = framebuffer dimensions) raycast(scene,eye) { for i=0..wd-1 for j=0..ht-1 { define ray r_ij relative to eye for each surface in scene { hit = intersection of r_ij with surface (if any) if hit.z is closest to eye so far, keep it } compute colour at hit point store colour at pixel (i,j) }

We’ll Work in Flatland ( x - z Plane) 10 you live here A2 lives here

We’ll Work in Flatland ( x - z Plane) 11

We’ll Work in Flatland ( x - z Plane) 12

3D from 2D Ray Casting (“2.5D”) Define world as 2D lines (walls of height h ) Hit at means 3D points and perspective projection 13 x z horizon n assumes eye at height

2D Ray Casting Engines 14 Wolfenstein 3D DOOM Duke Nukem 3D a mirror!! John Carmack Ken Silverman (when he was 18!!!)

Ray Casting vs Rasterization Rendering needs final colour for every pixel Ray casting “samples” a colour at every pixel independently (perfect!) Rasterization does not “sample”… – apply perspective projection only at sparse 3D points (not surfaces!) – draw lines/surfaces by interpolating in screen-space 15 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

Rasterization Pipeline The “graphics pipeline” of a 3D triangle… 16 (modelview & perspective transformation) (clipping) (perspective divide) (viewport transformation) model coordinates clip coordinates normalized device coordinates (NDC) window coordinates (Z-culling, rasterization) (homogeneous) (cartesian)

Model View & Perspective (3D) 17 (modelview & perspective transformation) clip coordinates (homogeneous) x z x z model coordinates x0x0 pseudodepth world coordinates eye coordinates clip coordinates homogenous!!

The Projection Matrix Derive perspective transformation that distorts view frustum before projection Matrix P maps canonical view frustum to canonical view volume 18 x z y ¡z¡z x y P (NDC before clipping)

Assume point p in x - z plane Orthographic needs The Projection Matrix 19 what do we want here? P

Assume point p in x - z plane Perspective is tricky The Projection Matrix 20 what do we want here? P whaaaa? how does this work?

Deriving the Projection Matrix Assuming l = ¡ 1, r = 1, want #1 means must have #1. need perspective divide #2. must scale x #3. need pseudo depth( n ) = ¡ 1 pseudo depth( f ) = 1 x not relevant to depth so set b 1 =0

General Projection Matrices General perspective matrix in x - z plane Full 3D projection matrices orthographicperspective reminder: we assume near plane z=n for n 0 orthographic! what we wanted!

Clipping Must clip in homogeneous coordinates, before perspective divide! Clip to canonical view volume – axis-aligned faces ) easy to clip! 23 clip coordinates (homogeneous) (clipping) Excellent research paper explains how it all works: Jim Blinn SIGGRAPH 1978

Clipping in x - z Plane Canonical view ‘area’ = four boundaries For boundary i, three cases: 1.both a and b outside i (trivial reject) 2.both a and b inside i (don’t clip to i ) 3.one inside and one outside i (may need to clip) 24 ¡1 · x · 1¡1 · x · 1 ¡1 · z · 1¡1 · z · 1 ( ¡ 1,1) (1,1) ( ¡ 1, ¡ 1)(1, ¡ 1) HAVEWANT three lines two clipped lines a b

Clipping in x - z Plane Apply “Cohen-Sutherland” clipping to homogeneous coordinates 25 // return false if line was clipped away entirely, true otherwise bool clip(a,b) { test a against every boundary test b against every boundary if a and b both outside same boundary return false // trivial reject if a and b inside all boundaries return true // trivial accept for each boundary clip a or b against this boundary (if applicable) return true if line not empty } [Hill p.106]

Clipping in x - z Plane How to test if a =( x, z, w ) inside boundary? What if w · 0 ? Means original point was behind near plane! (its z > n ) Such points automatically fail above tests 26 x ¸ ¡1x ¸ ¡1 x · 1x · 1 z ¸ ¡1z ¸ ¡1 z · 1z · 1 Assuming w > 0 we have... if all are true, then a inside all boundaries! [Hill p.357]

Clipping in x - z Plane How to clip line ( a, b ) to x = ¡ 1 ? Write line parametrically as Solve for t such that Where have we seen these “boundary coordinate” quantities before? 27 a b x ¸ ¡1x ¸ ¡1 a(t)a(t) “boundary coordinate of a on x = ¡ 1 ” “boundary coordinate of b on x = ¡ 1 ”

Clipping in x - z Plane 28 bool clip(a,b) { abc[0..3] = boundary coordinates of point a bbc[0..3] = boundary coordinates of point b if any abc[i] and bbc[i] both negative return false // trivial reject (outside same boundary) if all abc and bbc non-negative return true // trivial accept (inside all boundaries) for i = 0..3 if abc[i] < 0 tmin[i] = abc[i] / (abc[i] – bbc[i]) else if bbc[i] < 0 tmax[i] = abc[i] / (abc[i] – bbc[i]) if max(tmin) > min(tmax) return false // line was clipped away entirely set a based on max(tmin) // careful not to invalidate tmin/tmax set b based on min(tmax) // by changing a and b before finished! return true } [Hill. p359]

Device Coordinates After clipping, all w > 0 so safe to divide Must map NDC to viewport coordinates V is viewport transformation matrix 29 (perspective divide) (viewport transformation) normalized device coordinates (NDC) window coordinates (cartesian)

3D Viewport Transformation 30 ¡z¡z x y NDC window coordinates viewport ¡z¡z x y x y V A2 warning: bitmap coordinates have flipped y axis!! maps pseudodepth to [0,1] glViewport(...)

Raster Interpolation Final stage in 3D rasterization pipeline Take ( x, y ) window coordinates and draw 2D primitives (points, lines, polygons) – next topic!! Also use pseudodepth to figure out which 2D pixels are ‘in front’ of others 31 convexnon-convex always convex

The z -Buffer Test For every pixel in framebuffer, remember its final pseudodepth (the z -buffer) Overwrite colour at ( x, y ) if corresponding pseudodepth < zbuffer[ x, y ] (‘in front’) Can draw opaque objects in any order!! 32 framebuffer (BGR 2 [0..255]) z-buffer (pseudodepth 2 [0,1]) pseudodepth ¼ 0 pseudodepth z = 1