Ray Tracing Graphics Pipeline Review Alternative Approaches

Ray Tracing Graphics Pipeline Review Alternative Approaches

Ray Tracing Graphics Pipeline Review Properties of the Graphics Pipeline Beyond the Graphics Pipeline Primitives are processed one at a time Ray Casting All analytic processing early on Ray-Object Intersection Sampling occurs late Global Illumination - Minimal state required (immediate mode rendering) Reflections and Transparency Processing is forward-mapping Acceleration Techniques CSG Lecture 17 Slide 1 6.837 Fall 2001 Lecture 17 Slide 2 6.837 Fall 2001 Alternative Approaches Ray Casting Outline There are other ways to compute views of scenes defined by geometric For every pixel construct a ray primitives. One of the most common is ray-casting. Ray-casting searches from the eye through the pixel. along lines of sight, or rays, to determine the primitive that is visible along it. For every object in the scene Find “time” of intersection with the ray closest (and in front of) the eye Compute normal at point of intersection Compute color for pixel based on point and normal at intersection Properties of ray-casting: closest to the eye (e.g. by Phong illumination model). Go through all primitives at each pixel Sample first t Analytic processing afterwards 0 Requires a display list Lecture 17 Slide 3 6.837 Fall 2001 Lecture 17 Slide 4 6.837 Fall 2001 1 First Step - From Pixels to Rays Java Version // Compute viewing transformation that maps a // screen coordinate to a ray direction Vector3D look = new Vector3D(lookat.x-eye.x, lookat.y-eye.y, lookat.z-eye.z); Du = Vector3D.normalize(look.cross(up)); Dv = Vector3D.normalize(look.cross(Du)); float fl = (float)(width / (2*Math.tan((0.5*fov)*Math.PI/180))); Vp = Vector3D.normalize(look); Vp.x = Vp.x*fl - 0.5f*(width*Du.x + height*Dv.x); Vp.y = Vp.y*fl - 0.5f*(width*Du.y + height*Dv.y); Vp.z = Vp.z*fl - 0.5f*(width*Du.z + height*Dv.z); Example use: Vector3D dir = new Vector3D(i*Du.x + j*Dv.x + Vp.x, i*Du.y + j*Dv.y + Vp.y, i*Du.z + j*Dv.z + Vp.z); Ray ray = new Ray(eye, dir); // normalizes dir Lecture 17 Slide 5 6.837 Fall 2001 Lecture 17 Slide 6 6.837 Fall 2001 Object Intersection Early Rejection Intersecting a sphere with a ray: The performance of ray casting is determined by how efficiently ray object intersections can be determined. Let's rethink the series of computations used to determine the ray-sphere intersection while looking for ways to eliminate unnecessary work. Step 1: A sphere is defined by its center, s, and its radius r. The intersection of a ray with a sphere can be computed as follows: Thus, we can test if (v - r) is greater than the closes intersection thus far, tbest. If it is then this intersection cannot be closer. We can use this test to avoid the rest of the intersection calculation. Lecture 17 Slide 7 6.837 Fall 2001 Lecture 17 Slide 8 6.837 Fall 2001 2 More Trivial Rejections Example Code public boolean intersect(Ray ray) { float dx = center.x - ray.origin.x; We can even structure the intersection test to avoid even more float dy = center.y - ray.origin.y; unnecessary work: float dz = center.z - ray.origin.z; float v = ray.direction.dot(dx, dy, dz); Step 2: // Do the following quick check to see if there is even a chance 2 2 // that an intersection here might be closer than a previous one What if the term, r -b < 0 if (v - radius > ray.t) return false; // Test if the ray actually intersects the sphere float t = radSqr + v*v - dx*dx - dy*dy - dz*dz; if (t < 0) return false; // Test if the intersection is in the positive // ray direction and it is the closest so far Clearly we need to test for this case anyway since it will generate an t = v - ((float) Math.sqrt(t)); exception when we calculate the expression: if ((t > ray.t) || (t < 0)) return false; ray.t = t; ray.object = this; return true; } Lecture 17 Slide 9 6.837 Fall 2001 Lecture 17 Slide 10 6.837 Fall 2001 Global Illumination Recursive Ray-Casting Early on, in the development of computer graphics, ray-casting was Starting from the viewing position, first compute the visible object along recognized as viable approach to 3-D rendering. However, it was generally each ray. Then compute the visibility of each light source from the visible dismissed because: surface point, using a new ray. If there is an object between the light 1. Takes no advantage of screen space coherence source and the object point it is in shadow, and we ignore the illumination 2. Requires costly visibility computation from that source. We can also model reflection and refraction 3. Only works for solids similarly. 4. Forces per pixel illumination evaluations 5. Not suited for immediate mode rendering It was not until Turner Whitted (1980) recognized that recursive ray casting, which has come to be called ray tracing, could be used to address global illumination that interest in ray tracing became widespread. Lecture 17 Slide 11 6.837 Fall 2001 Lecture 17 Slide 12 6.837 Fall 2001 3 Ray Tracing Illumination The Ray Tree Recursive L R E T R 3 Viewpoint Nˆ 2 V Vreflected N T 2 1 R R 3 = + + I I reflected 1 N I(E,V ) I direct I reflected I transmitted 3 L P 1 L2 V N1 L3 I transmitted L = transmitted 1 R T I reflected kr I(P,Vreflected ) 1 1 L L = Eye 2 3 I transmitted kt I(P,Vtransmitted ) Ni surface normal R R T R reflected ray 2 3 3 = + ()(ˆ ⋅ ˆ + − ˆ ⋅ ˆ )nshiny i I direct ka I ambient I light kd N L k s V R L shadow ray i Check for shadowing (intersection with object along ray (P,L)) Ti transmitted (refracted) ray Lecture 17 Slide 13 6.837 Fall 2001 Lecture 17 Slide 14 6.837 Fall 2001 Refraction Rendering Equation Nˆ cos θ − Iˆ Nˆ Global illumination computes the more general problem of light transfer sin θ η i between all objects in the scene, including direct and indirect illumination. Snell’s Law i = i = η θ η r Nˆ cos θ Rendering equation is the general formulation of the global illumination sin t t Iˆ θ i i Mˆ problem: it describes how the radiance from surface x reflects from the surface x’: Tˆ = sin θ Mˆ − cos θ Nˆ t t r r (Nˆ cos θ − Iˆ) θ L(x′,ω′) = E(x′) + ρ(x′)L(x,ω)G(x, x′)V (x, x′)dA Mˆ = i t θ − ˆ Tˆ ∫ sin i N S sin θ Tˆ = t (Nˆ cos θ − Iˆ) − cos θ Nˆ L is the radiance from a point on a surface in a given direction ω sin θ i t Note that I is the negative of i the incoming ray E is the emitted radiance from a point: E is non-zero only if x’ is emissive Tˆ = (η cos θ − cos θ )Nˆ −η Iˆ V is the visibility term: 1 when the surfaces are unobstructed along the r i t r direction ω, 0 otherwise θ = ˆ ⋅ ˆ cos i N I G is the geometry term, which depends on the geometric relationship θ = − 2 θ = −η 2 2 θ = −η 2 − ˆ ⋅ ˆ 2 between the two surfaces x and x’ cos t 1 sin t 1 r sin i 1 r (1 (N I ) ) Tˆ = η (Nˆ ⋅ Iˆ) − 1 −η 2 (1 − (Nˆ ⋅ Iˆ) 2 )Nˆ −η Iˆ Total internal reflection when the Ray tracing approximates the rendering equation by sampling along rays r r r square root is imaginary where the integrand is likely to be large. Lecture 17 Slide 15 6.837 Fall 2001 Lecture 17 Slide 16 6.837 Fall 2001 4 Designing a Ray Tracer A Ray Object Building a ray tracer is simple. First we start with a convenient vector class Ray { algebra library. public static final float MAX_T = Float.MAX_VALUE; class Vector3D { Vector3D origin, direction; float t; Renderable object; public float x, y, z; // constructors public Ray(Vector3D eye, Vector3D dir) { public Vector3D( ) { } origin = new Vector3D(eye); public Vector3D(float x, float y, float z); direction = Vector3D.normalize(dir); public Vector3D(Vector3D v); } public boolean trace(Vector objects) { // methods Enumeration objList = objects.elements(); public Vector3D to(Vector3D B) // B - this t = MAX_T; public float dot(Vector3D B); // this with B object = null; public float dot(float Bx, float By, float Bz); // B spelled out while (objList.hasMoreElements()) { public static float dot(Vector3D A, Vector3D B); // A dot B Renderable object = (Renderable) objList.nextElement(); object.intersect(this); public Vector3D cross(Vector3D B); // this with B } public Vector3D cross(float Bx, float By, float Bz); // B spelled out return (object != null); public static Vector3D cross(Vector3D A, Vector3D B); // A cross B } // ray.Shade(...) is nicer than ray.object.Shade(ray, ...) public float length( ); // of this public final Color Shade(Vector lights, Vector objects, Color bgnd) { public static float length(Vector3D A); // of A return object.Shade(this, lights, objects, bgnd); public void normalize( ); // makes this unit length } public static Vector3D normalize(Vector3D A); // makes A unit length } public String toString(); // convert to a string } Lecture 17 Slide 17 6.837 Fall 2001 Lecture 17 Slide 18 6.837 Fall 2001 Light Source Object Renderable Interface // All the public variables here are ugly, but I // An object must implement a Renderable interface in order to // wanted Lights and Surfaces to be "friends" // be ray traced.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    12 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us