Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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

2 “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

3 “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 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

4 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

5 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.”

6 Aside: “Helmholtz Reciprocity” Can interchange light and camera, yet camera sees identical shading at fixed 3D point 6 http://www.cs.virginia.edu/~mjh7v/vision/final/index.php

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

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

9 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) }

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

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

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

13 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

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

15 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 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

16 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)

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

18 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)

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

20 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?

21 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

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

23 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: http://research.microsoft.com/pubs/73937/p245-blinn.pdf http://research.microsoft.com/pubs/73937/p245-blinn.pdf Jim Blinn SIGGRAPH 1978

24 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

25 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]

26 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]

27 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 ”

28 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]

29 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)

30 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(...)

31 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

32 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


Download ppt "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."

Similar presentations


Ads by Google