Docsity

Ray Casting and Ray-Tracing Algorithms: Generating Rays and Determining Colors, Slides of Computer Graphics

Toggle sidebar
bg1
1
Ray Casting 2
Programming 2
Recap
•Spherical Coordinates
•Demo on board
•Per-Vertex Normals
•Demo on board
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
•(x1, y1, x2, y2, R, G, B)
•This data set anticipates a 512x512
window
•To read the array (line.data), use something
like the following code:
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Ray Casting and Ray-Tracing Algorithms: Generating Rays and Determining Colors and more Slides Computer Graphics in PDF only on Docsity!

Ray Casting 2

Programming 2

Recap

  • Spherical Coordinates
    • Demo on board
  • Per-Vertex Normals
    • Demo on board

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 512x window
    • To read the array (line.data), use something like the following code:

Programming 3 Info

  • For parts 2 and 3, the program should

respond to user input

  • Can do this several ways
    • Accept coordinates as command line input
    • Prompt for user input while running
    • Allow user to click and choose points (like polygon creation in assignment 1

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

Today

  • Extending some of the ideas from last

time

  • Briefly discussing the software

architecture of a raycaster

  • Optional course feedback survey
  • 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-Tracing

Algorithm

Ray Casting

Generating Rays in

3D

D u = D v =

V 0 =

V i,j = [ D u D v 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

Doing it Better

  • We now know how to generate a simple

raycasted image

  • However, we’ve assumed only a very

simple/limited camera definition

  • Now we’re going to extend our notion of

cameras

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.

Camera Extrinsics

  • These locate and orient the

camera in the world

  • Camera position
  • Camera orientation

Camera Extrinsics

  • These are easy to describe
    • Camera position
      • 3D point
    • Camera orientation
      • 2 3D vectors
        • LookAt vector
        • Up vector

Camera Orientation

  • So why do we need two vectors after

all?

  • Why not just a look vector?
  • LookAt vector describes which way the

camera is pointed

  • But not where the top of the film is
  • That’s what the up vector gives us

Building a Frustum

  • Let’s take a step back:
    • What are we trying to do?
      • Want to build a camera matrix that will generate our rays

Building a Frustum

  • That’s what we want
    • Here’s what we have to work with:
      • Field of view
      • Resolution (vertical & horizontal)
        • Gets us aspect ratio
      • Eye point & center point
        • Gets us look vector
      • Up vector

θ vRes, hRes

eye, center

Up

Building a Frustum

  • So, we have:
    • θ, hRes, vRes, eye, center, Up
  • Want to use these to compute

D u, D v, V 0

  • These three vectors define the image plane

Ey

e

V 0

D v

D u

Focal Length

• Remember this equation?

• We want to know how far along the

LookAt vector the image plane lies

  • Before, we assumed it was 1, so the distance from the center of the image to the left edge was just tan (θ/2)
  • Now it is hRes/

Distance to film Focal Length

Distance to scene

Complete Frustum

Specification

Given Points:

Given Unit

Vector:

Given FOV

Angle:

Given

Dimensions:

NOTE:

Normalize D u and D v!

D u = LookAt x Up

D v = LookAt x D u

eye, center

θ vRes, hRes

Up LookAt =

||center - eye||

center - eye

Raycaster System

Overview

For Each Pixel

Camera Ray

Generates

Linked List of Objects

Sphere

Plane

Etc.

App CameraMatrix

Test For Closest

Sphere Closest Object

Linked List of Materials

Material #

Material #

Linked List of Lights

Ambient #

Point #

Point #

Shade()

Material #

Shade()

Surface Material

Illuminated By

Pixel Color

Next Time

• Figuring out what raycasting/raytracing

really buys us over OpenGL

• Shadows

• Reflection

• Refraction

• i.e. Real Ray Tracing

Course

Feedback

Survey