Docsity

Ray Casting: Generating Images by Shooting Rays into a Scene, Slides of Computer Graphics

Partial preview of the text

Download Ray Casting: Generating Images by Shooting Rays into a Scene and more Slides Computer Graphics in PDF only on Docsity!

  • Ray Casting

Programming 3 Info

  • Test data for part 1 (Lines) is available
    • As C/C++ array, or just as a text file
      • In both cases, each line has 7 parameters
        • (x 1 , y 1 , x 2 , y 2 , R, G, B)
      • This data set anticipates a 512x512 window
    • To read the array (line.data), use something like the following code:

Programming 3 Info

  • For part 3 (line clipping), should display

a window bigger than the clip window

  • i.e. Viewport (^) Clip against this

Last Time

  • Derived the math for ray casting
    • Intersecting rays and objects
    • Generating rays
      • aka generating a camera matrix
    • Coloring pixels
      • Phong shading for each ray

Ray-Tracing Algorithm

  • for each pixel / subpixel

shoot a ray into the scene

find nearest object the ray intersects

if surface is (nonreflecting OR light)

color the pixel

else

calculate new ray direction

recurse

Ray-Tracing Algorithm

  • for each pixel / subpixel

shoot a ray into the scene

find nearest object the ray intersects

if surface is (nonreflecting OR light)

color the pixel

else

calculate new ray direction

recurse

Ray Casting

Computing Ray-Object Intersections

  • If a ray intersects an object, want to

know the value of t where the

intersection occurs:

  • t < 0: Intersection is behing the ray, ignore it
  • t = 0: Undefined
  • t > 0: Good intersection
  • If there are multiple intersections, we

want the one with the smallest t

  • This will be the closest surface r (t) = p + t d

Generating Rays

  • Now, given a ray, we know how to test if it

intersects an object

  • But we don’t yet know how to generate the rays
  • We talked a bit about lenses last time, but

an ideal pinhole camera is still the simplest

model

  • So let’s assume that

Generating Rays in 2D

Eye Once we know this ray, the rest are easy This is referred to as a “Pencil of Rays”

Generating Rays in 3D

Eye +x +y +z

D v =

D u =

V 0 D v D u V 0 =

A Basic 3D Camera Matrix

  • Assumes:
    • Camera on the z-axis
    • Looking down - z
    • Ideal pinhole model
    • Fixed focal length (focal length = 1)

Determining Color

  • Since we’re not yet talking about tracing

rays

  • Really just talking about OpenGL-style lighting and shading - Since surfaces are implicitly defined, can solve Phong lighting equation at every intersection

Camera Intrinsics and Extrinsics

  • We normally divide camera properties

into two classes: intrinsic and

extrinsic

  • Intrinsic properties are those belonging to the camera itself - Intrinsic properties are inside the camera
  • Extrinsic properties define how the camera is situated in the world

Camera Intrinsics

  • These describe the behavior of the camera
    • Focal length
    • Aspect ratio
    • Resolution
    • Aperture
    • Shutter speed
    • etc.