1 / 59

CS G140 Graduate Computer Graphics

CS G140 Graduate Computer Graphics. Prof. Harriet Fell Spring 2009 Lecture 3 - January 21, 2009. Today’s Topics. From 3D to 2D 2 Dimensional Viewing Transformation http://www.siggraph.org/education/materials/HyperGraph/viewing/view2d/2dview0.htm Viewing – from Shirley et al. Chapter 7

trey
Download Presentation

CS G140 Graduate Computer Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS G140Graduate Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 3 - January 21, 2009

  2. Today’s Topics • From 3D to 2D • 2 Dimensional Viewing Transformationhttp://www.siggraph.org/education/materials/HyperGraph/viewing/view2d/2dview0.htm • Viewing – from Shirley et al. Chapter 7 • Recursive Ray Tracing • Reflection • Refraction

  3. Scene is from my photo of Estes Park – Harriet Fell Kitchen window from http://www.hoagy.org/cityscape/graphics/cityscapeAtNight.jpg

  4. (1, 1) (-1, -1)

  5. from a 3D World to a 2D Screen When we define an image in some world coordinate system, to display that image we must somehow map the image to the physical output device. • Project 3D world down to a 2D window (WDC). • Transform WDC to a Normalized Device Coordinates Viewport (NDC). • Transform (NDC) to 2D physical device coordinates (PDC).

  6. 2 Dimensional Viewing Transformationhttp://www.siggraph.org/education/materials/HyperGraph/viewing/view2d/2dview0.htm • Window • Example: Want to plot x vs. cos(x) for x between 0.0 and 2Pi. The values of cos x will be between -1.0 and +1.0. So we want the window as shown here.

  7. 2D Viewing Transformation World Viewport Device

  8. Pixel Coordinates y y = 4.5 (0,3) (3,2) x (0,0) y = -03.5 x = 4.5 x = -0.5

  9. y (-1,1) reflect x (1,-1) scale (-nx/2,ny/2) y translate x (nx/2,-ny/2) Canonical View to Pixels y (1,1) x (-1,-1) (-0.5, ny--0.5) y x (nx-0.5, -0.5)

  10. 2D Rectangle to Rectangle w1 (a, b) w2 (c, d) h1 h2 (0, 0) T(c, d) T(-a, -b) S(w2/w1, h2/h1)

  11. Canonical View Volume z (1,1,1) y x (-1,-1,-1)

  12. Orthographic Projection (r,t,f) y (l,b,n) z x left bottom near right top far

  13. Orthographic Projection Math

  14. Orthographic Projection Math

  15. Arbitrary View Positions v = wxu gaze the view-up eye w = -g ||g|| u = txw ||txw||

  16. Arbitrary Position Geometry v w e (u=l,v=b,w=n) z u o (u=r,v=t,w=f) x y

  17. Arbitrary Position Transformation Move e to the origin and align (u, v, w) with (x, y, z). Compute M = MoMv. For each line segment (a,b) p = Ma, q = Mb, drawline(p,q).

  18. Perspective Projection (l,b,n) y (r,t,f) z x

  19. Lines to Lines

  20. Perspective Geometry View plane y ys e g n z ys = (n/z)y

  21. Perspective Transformation The perspective transformation should take Where p(n) = n p(f) = f and nz1> z2f implies p(z1) > p(z2). P(z) = n + f – fn/z satisfies these requirements.

  22. Perspective Transformation is not a linear transformation. is a linear transformation.

  23. The Whole Truth about Homogeneous Coordinates A point in 2-space corresponds to a line through the origin in 3-space minus the origin itself. A point in 3-space corresponds to a line through the origin in 4-space minus the origin itself.

  24. Homogenize

  25. Perspective Transformation Matrix Compute M = MoMpMv. For each line segment (a,b) p = Ma, q = Mb, drawline(homogenize(p), homogenize(q)).

  26. Viewing for Ray-TracingSimplest Views screen (0, 0, 0) (wd/s, ht/2, d) (wd, ht, 0)

  27. (0, 0, 0) |p|j (w/2, h/2, n) -nk (w, h, 0) A Viewing System for Ray-Tracing w h perp gaze eye (ex, ey, ez) = near distance = |g| You need a transformation that sends (ex, ey, ez) to (w/2, h/2, n) g to –nk p to |p|j

  28. Time for a Break

  29. Recursive Ray Tracing Adventures of the 7 Rays - Watt Specular Highlight on Outside of Shere

  30. Recursive Ray Tracing Adventures of the 7 Rays - Watt Specular Highlight on Inside of Sphere

  31. Recursive Ray Tracing Adventures of the 7 Rays - Watt Reflection and Refraction of Checkerboard

  32. Recursive Ray Tracing Adventures of the 7 Rays - Watt Refraction Hitting Background

  33. Recursive Ray Tracing Adventures of the 7 Rays - Watt Local Diffuse Plus Reflection from Checkerboard

  34. Recursive Ray Tracing Adventures of the 7 Rays - Watt Local Diffuse in Complete Shadow

  35. Recursive Ray Tracing Adventures of the 7 Rays - Watt Local Diffuse in Shadow from Transparent Sphere

  36. Recursive Ray-Tracing • How do we know which rays to follow? • How do we compute those rays? • How do we organize code so we can follow all those different rays?

  37. select center of projection(cp) and window on view plane; for (each scan line in the image ) { for (each pixel in scan line ) { determine ray from the cp through the pixel; pixel = RT_trace(ray, 1);}} // intersect ray with objects; compute shade at closest intersection // depth is current depth in ray tree RT_color RT_trace (RT_ray ray; int depth){ determine closest intersection of ray with an object; if (object hit) { compute normal at intersection; return RT_shade (closest object hit, ray, intersection, normal, depth);} else return BACKGROUND_VALUE; }

  38. // Compute shade at point on object, // tracing rays for shadows, reflection, refraction. RT_color RT_shade ( RT_object object, // Object intersected RT_ray ray, // Incident ray RT_point point, // Point of intersection to shade RT_normal normal, // Normal at point int depth ) // Depth in ray tree { RT_color color; // Color of ray RT_ray rRay, tRay, sRay;// Reflected, refracted, and shadow ray color = ambient term ; for ( each light ) { sRay = ray from point to light ; if ( dot product of normal and direction to light is positive ){ compute how much light is blocked by opaque and transparent surfaces, and use to scale diffuse and specular terms before adding them to color;}}

  39. if ( depth < maxDepth ) {// return if depth is too deep if ( object is reflective ) { rRay = ray in reflection direction from point; rColor = RT_trace(rRay, depth + 1); scale rColor by specular coefficient and add to color; } if ( object is transparent ) { tRay = ray in refraction direction from point; if ( total internal reflection does not occur ) { tColor = RT_trace(tRay, depth + 1); scale tColor by transmission coefficient and add to color; } } } return color; // Return the color of the ray }

  40. VN VN Computing R V + R=(2 VN) N R = (2 VN) N - V R V N V+R R V  

  41. Reflections, no Highlight

  42. Second Order Reflection

  43. Refelction with Highlight

  44. Nine Red Balls

  45. Refraction N I I T T -N

  46. Refraction and Wavelength N I I T T -N

  47. sin(I) cos(I) M Computing T I = - sin(I)M + cos(I)N N T = sin(T)M - cos(T)N I I How do we compute M, sin(T), and cos(T)? We look at this in more detail T T -N

  48. cos(T) I x sin(T) Computing T T T -N

  49. I Computing T I Parallel to I T T -N cos(T) I = x sin(T)

More Related