Intro. to Advanced Lighting, Basic Ray Tracing - PowerPoint PPT Presentation

About This Presentation
Title:

Intro. to Advanced Lighting, Basic Ray Tracing

Description:

12 Apr 2004. CS 481/681. 2. Intro. to Advanced Lighting ... 12 Apr 2004. CS 481/681. 5. Basic Ray Tracing: Tracing A Ray. What do we do when we have a hit? ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 12
Provided by: glenngc
Learn more at: https://www.cs.uaf.edu
Category:

less

Transcript and Presenter's Notes

Title: Intro. to Advanced Lighting, Basic Ray Tracing


1
Intro. to Advanced Lighting,Basic Ray Tracing
  • Glenn G. ChappellCHAPPELLG_at_member.ams.org
  • U. of Alaska Fairbanks
  • CS 481/681 Lecture Notes
  • Monday, April 12, 2004

2
Intro. to Advanced Lighting
  • In our next unit, we look at advanced techniques
    for lighting scenes.
  • Most of these do not fit well within the
    pipeline-based rendering model we have been
    discussing.
  • Most of these techniques are also too slow for
    real-time rendering.
  • The first technique we will look at is called
    ray tracing.

3
Basic Ray TracingIntroduction
  • In normal rendering
  • We deal with a series of objects, made of
    primitives.
  • For each primitive, we determine which pixels it
    affects, if any.
  • Ray tracing turns this around
  • We deal with pixels, one by one.
  • For each pixel, we ask what we see (which
    primitive?) when we look at it.

4
Basic Ray TracingTracing A Ray
  • The way we determine what we see when we look at
    a pixel is to draw an imaginary ray from the
    viewing position, through the pixel, into the
    scene.
  • We ask which objects in the scene the ray hits.
  • The first hit is the one that counts.

Image
Scene objects
Current pixel
First hit
5
Basic Ray TracingTracing A Ray
  • What do we do when we have a hit?
  • We determine what color the object is at that
    point.
  • Light sources and the objects normal may affect
    the computation.
  • We can also do true specular reflection
  • Reflect the ray and do the ray tracing
    computation again.
  • We can also do true refraction, for translucent
    objects.

Original ray
Reflected ray
Normal
6
Basic Ray TracingTwo Questions
  • When we do ray tracing, there are two basic
    questions that need to be answered repeatedly
  • Given a ray, does it hit an object in the scene,
    and, if so, which one does it hit first?
  • If a ray hits an object, what color do we see
    when we look along the ray?
  • Designing code to answer these is an excellent
    application of object-oriented design principles.

7
Basic Ray TracingWhat is a Ray?
  • A ray is half of a line. It has a starting point
    and a direction.
  • To store a ray, we need
  • A starting point pos.
  • A direction vector (unit vector) vec.
  • It is reasonable to implement a ray as a class.
  • For convenience, rays can know how to reflect and
    refract themselves.

8
Basic Ray TracingRay-Object Intersection
  • The first question that needs to be answered is
    whether a ray hits any object in the scene.
  • To answer this, test the ray against each object
    in turn.
  • This test is called ray-object intersection.
  • What class knows how to do this?
  • Answer The objects class.
  • Since every object class needs to be able to do
    ray-object intersection
  • Write an abstract base class for objects.
  • Each object is derived from the base class.
  • Ray-object intersection is a virtual function.

9
Basic Ray TracingWhat Do Objects Do?
  • More generally, what do objects need to be able
    to do?
  • Answer They need to be able to answer the two
    questions, for themselves.
  • So, an object has two member functions
  • First, given a ray, test whether the ray hits the
    object, and, if so, how far from the start of the
    ray the hit lies.
  • How far, so we can tell which hit comes first.
  • Second, given a ray that hits the object, tell
    what color is seen along the ray.
  • And that is all!
  • Except for administrative stuff constructors,
    etc.
  • Right??

10
Basic Ray TracingHits
  • In practice, to determine the color (question 2),
    an object needs to know where the ray hit and
    what the normal is.
  • These are almost always calculated during the
    ray-object intersection test (question 1).
  • Therefore, it is convenient to have a hit
    class. This holds
  • Whether the ray hit the object bool.
  • If so
  • How far along the ray double.
  • Where the hit is pos.
  • The objects normal vector at this point vec.
  • Again, this is not required, but will nearly
    always speed things up by avoiding repeating a
    computation.

11
Basic Ray TracingClass Summary
  • So, in a simple ray tracer, we have
  • A ray class.
  • An object base class.
  • Various objects are derived from it.
  • Virtual functions for ray-object intersection and
    color computation.
  • A hit class.
  • This design is easily extended.
  • Adding new objects works without changing other
    code.
  • We can add features like multiple rays per pixel,
    etc.
Write a Comment
User Comments (0)
About PowerShow.com