cs 543 computer graphics introduction to ray tracing

CS 543 - Computer Graphics: Introduction to Ray Tracing by Robert - PDF document

CS 543 - Computer Graphics: Introduction to Ray Tracing by Robert W. Lindeman gogo@wpi.edu (with help from Peter Lohrmann ;-) View Volume View volume similar to gluPerspective Angle Aspect Near? Far? But we draw in 2D


  1. CS 543 - Computer Graphics: Introduction to Ray Tracing by Robert W. Lindeman gogo@wpi.edu (with help from Peter Lohrmann ;-) View Volume  View volume similar to gluPerspective  Angle  Aspect  Near?  Far?  But we draw in 2D  gluOrtho(…) R.W. Lindeman - WPI Dept. of Computer Science 2 1

  2. Primary Rays  Generate ray from eye through pixel into scene of objects  Determine if ray hits an object  Calculate lighting at that point  Set pixel to necessary color R.W. Lindeman - WPI Dept. of Computer Science 3 Primary Rays  Blue lines represent ‘primary rays’  Some rays receive color from object  Some rays receive background color R.W. Lindeman - WPI Dept. of Computer Science 4 2

  3. Determining a Hit  For each pixel, test every object for a hit  Gather info about hit - Point - Normal R.W. Lindeman - WPI Dept. of Computer Science 5 What's so hard about that?  Consider a mesh with only 1300 polygons being rendered to a screen resolution of 640x480.  640x480x1300 = 399,360,000 possible intersections!!  Adding 2 reflections = 1,198,080,000  Adding soft shadows = 13,178,880,000 R.W. Lindeman - WPI Dept. of Computer Science 6 3

  4. A Little Better Appreciation? R.W. Lindeman - WPI Dept. of Computer Science 7 Real or Rendered? R.W. Lindeman - WPI Dept. of Computer Science 8 4

  5. Traveling Through Spaces  Transformed shape in world space  Generated ray in camera space  Converted to world space during generation  How do we calculate if a ray hits an object?  Transformed objects could have ANY shape R.W. Lindeman - WPI Dept. of Computer Science 9 Determining A Hit  Apply inverse transformation matrix  Move object back to generic shape  Move ray to some new location. R.W. Lindeman - WPI Dept. of Computer Science 10 5

  6. Determining A Hit (Sphere)  Parametric Equations  P = S + t D  F(x,y,z) = x 2 + y 2 + z 2 -1  F(P) = |P| 2 -1 = 0  Substituting P into F(P) = 0, we get:  D 2 * t 2 + 2( S • D )*t + ( S 2 – 1) = 0  Recall the dot-product relation: |a+b| 2 = |a| 2 + 2a•b + |b| 2  This is a quadratic equation of A 2 *t 2 + 2Bt + C = 0 where A = D 2 B = S • D C = S 2 – 1 R.W. Lindeman - WPI Dept. of Computer Science 11 Determining A Hit (Sphere)  Utilize quadratic equation:  Find the hit point using: B 2 � AC t hit = � B A ± A  If discriminant ( B 2 -AC ) is negative: ray misses sphere  If discriminant is zero: ray grazes sphere edge  Hit point is –B/A  Discriminant positive: ray pierces sphere  Two hits times (+ and – discriminant)  Normal?  Easy! It's the hit point! R.W. Lindeman - WPI Dept. of Computer Science 12 6

  7. Intersecting Transformed Objects  F(P) becomes F(T -1 (P))  F(T -1 (S + tD)) = 0  T -1 (S + tD) = (T -1 S) + (T -1 D)t R.W. Lindeman - WPI Dept. of Computer Science 13 Hit Info  Once we calculate a hit, gather information  Hit time  Hit object (pointer)  Entering?  Which surface of object  Hit point  Hit normal R.W. Lindeman - WPI Dept. of Computer Science 14 7

  8. Parametric Shapes  http://www.econym.demon.co.uk/isotut/parametric.htm R.W. Lindeman - WPI Dept. of Computer Science 15 Find Best Hit  Given a set of hit times (intersections)  Find the closest (soonest) hit  For each object that is hit by the ray  Test if that hit time is the closest thus far  Clipping?  Now we know which object the ray hit, where it hit ,and the normal  Time to color the pixel! R.W. Lindeman - WPI Dept. of Computer Science 16 8

  9. Coloring Pixels  Is there a need to LERP?  If there are no hits, use a background color  Otherwise…  "Default" color? (no lights …. ambient)  Contribution of lights  Add calculated diffuse color  Add calculated specular color  Contribution of other effects R.W. Lindeman - WPI Dept. of Computer Science 17 Review Coloring (Ambient) + Ambient = R.W. Lindeman - WPI Dept. of Computer Science 18 9

  10. Review Coloring (Diffuse) = X R.W. Lindeman - WPI Dept. of Computer Science 19 Review Coloring (Specular) + = R.W. Lindeman - WPI Dept. of Computer Science 20 10

  11. Review Coloring (Shadows) ? = R.W. Lindeman - WPI Dept. of Computer Science 21 Shade Function Get the first hit in the scene If no hits, then return background color Gather some information about the best hit pixelColor += ambient contribution For each light in the scene pixelColor += calculated diffuse contribution pixelColor += calculated specular contribution return pixelColor R.W. Lindeman - WPI Dept. of Computer Science 22 11

  12. References  F.S. Hill – Chapter 12 R.W. Lindeman - WPI Dept. of Computer Science 23 12

Recommend


More recommend