11. Raytracing
Brock University
COSC 3P98 Computer Graphics
Instructor: Brian J. Ross
Back to raytracing
-
raytracing: trace a path from user eye through each pixel, and intersect
that ray through object surface in scene. Colour the pixel the appropriate
colour:
-
use the front-most object intersection point (does hidden surface)
-
compute the colour at that precise intersection
-
raytracing gives photorealistic effects because:
-
(a) not limited to polygonal models - can define mathematical volumes
-
(b) possible to extend the ray throughout the picture, through glass (refraction),
mirrors (reflection),... very complex lighting effects
-
two essential mathematical principles used:
-
1. intersection of ray through various geometric objects
-
2. compute the illumination at intersection point
-
the position of eye, screen, perspective, and scene extents are all defined
for the algorithm
-
use similar subroutines to OpenGL's perspective, lookat, etc
Raytracing
Raytracing
- define objects and light sources in scene
- set up the camera
- for j = 0 to MAXROW
for i = 0 to MAXCOL /* cast i,jth pixel's ray */
- build the parameters of i,j-th ray
- find all intersections of ray with objects in the scene
- identify the intersection that lies closest to camera
- find the colour of light returning to camera along the
ray from the point of intersection
- if ray reflects at hit point:
determine reflection ray, and recurse
- if ray refracts at hit point:
determine refraction ray, and recurse
- combine colour of eye ray, reflection ray, refraction ray
- draw combined color: SetPixel(i,j,colour)
end
Raytracing
-
raytracers have a stock library of geometric objects
-
building blocks for entire image
-
includes polygons, spline surfaces
-
eg. Bryce 2's object primitives...
-
you then build objects by placing & intersecting geometric objects
-
together, defining various material and lighting properties to them
-
possible data structures (from [Hill 1990], code 18.3, p.623):
ray = record
start, dir: vector3D
end;
generic type = (sphere, cone, cylinder, cube, ...);
obj_ptr = ^instance;
instance = record
kind: generic_type; /* type of object */
transf: affine3D; /* 3D transformation for object */
nature:... ; /* surface props, materials, reflect,...*/
next: obj_ptr; /* points to next object in scene */
... etc ...
end;
Raytracing: intersecting the eye ray with an object
-
optimized mathematical equations will be used for determining intersection
of ray
-
Ray equation similar to that of a line: P0
+ su
-
where P0 is start location,
and u is direction parameterized by s
-
eg. intersecting a ray with a sphere (easiest object for ray tracers to
handle!):
-
surface points P of sphere at location Pc of
radius r: | P-Pc |^2 - r^2 = 0
-
substitute ray into equation: | P0 + su
-
Pc |^2 - r^2 = 0
-
This can be solved for s: s = u dot DP +/- sqrt((u
dot DP)^2 - abs(DP)^2 + r^2)
-
where DP = Pc - P0; a dot b = dot
product
-
If s is negative, no intersection; else substitute s into ray equation
to get intersect point.
-
eg. ray with a polyhedron:
-
first, enclose polyhedron in a bounding sphere
-
If ray intersects sphere, then attempt intersection with polygon sides
of polyhedron
-
(i) determine intersection of ray with plane containing a polygon
-
(ii) Using inside/outside test, determine of that intersection within polygon
-
(iii) repeat until closest intersection point found (if it intersects at
all)
Raytracing
-
Hit spot: where eye ray hits object (intersection point)
-
we find hit spots for ray and all objects in scene; then use the closest
hit spot (visible surface determination)
-
finding normal at hit spot: depends on object
-
eg. sphere - normals point out radially from sphere center to surface
-
eg. cube - normal perpendicular to the surface containing hit spot
-
once normal found, you put it in the lighting equation we used before
-
Can also apply texture to that point: look in object data structure, and
see it a texture is to be applied. If so, compute a texture colour for
it
-
Once colour determined, we draw the pixel using that colour, and move onto
the next pixel (ie. new eye ray)
Raytracing
-
raytracing can be advanced: refraction, reflection, bump maps, ...

(from [Hill 1990])
-
Each bounced ray has the basic raytracing principle applied to it recursively;
hence "recursive raytracing"
-
need to supply a depth level, otherwise recursion for raytracing may never
stop!
-
Optimization considerations
-
simplify and optimize intersection computations
-
enclose objects in bounding volumes (eg. spheres or cubes) whose intersections
are fast to compute; if the ray doesn't intersect the volume, don't bother
intersecting with the actual object
-
Hierarchies: organize model such that the children in a tree hierarchy
cannot intersect a ray if its parent cannot
-
spatial partitioning: partition scene into grids, and compute intersection
with objects within the grid that the ray passes
Raytracing: POV (Persistence of Vision)
-
Many raytracers are available commercially or in public domain
- one example: POV "Persistence of Vision"
- www.povray.org
-
runs on Windows, OSX soon (?)>
-
current version: 3.7
-
there's a 700+ page book by Waite Group on POV: amazon.com
-
user sets up a scene using POV language:
-
you set up camera (eye), objects, surfaces, colours, textures, lights,
and POV draws it eventually (after seconds, minutes, or hours!)
-
Typical POV file (text)
-
at least a few CAD-like interactive scene editors are available on PC
-
PV3D, povcad (windows)
-
they convert the scene you make into a POV language file (text)
Beyond Raytracing: Radiosity
-
Raytracing and raster-scan algorithms presume a constant ambient light
for entire environment.
-
Radiosity is another rendering approach
-
based on thermal-engineering models for the emission and reflection of
radiation
-
presumes conservation of emitted and reflected light in an environment
-
radiosity: sum of the rates at which the surface emits energy and reflects
or transmits it from that surface or other surfaces
-
approach:
-
1. determine all the light interactions in an environment
-
2. render a view
-
visible surface determination, interpolative shading
-
Differences from ray tracing
-
all objects can emit light from their surfaces
-
much more realistic rendering than ray tracing, which seems harsh in comparison
-
subtle interaction of objects wrt one another
-
soft shadows
-
computationally very expensive (upwards of 6+ times slower)
-
but as CPU's become faster, and algorithms become more optimized, it will become more common
-
Illustration [Watt and Watt]
- Site with raytracing, radiosity examples
Raytracing: comments
-
Historically, raytracing has not been intended for interactive animated 3D graphics:
-
too many calculations to do within an interactive frame iteration
-
BUT... this is changing with advent of powerful hardware (GPU's): real-time ray tracing.
- Will raytracing be a realtime rendering technology? It is already... Battlefield V
- Demo.
- Another demo.
-
note the difference between OpenGL (scan converted) photorealism and a ray
tracer's:
-
a) ray tracer computes exact lighting at each pixel
-
b) OpenGL computes exact lighting at polygon vertices, and interpolates
intermediate surface lighting
-
Gouraud, Phong shading give "estimated" smoothness, and OpenGL's lighting techniques
give "estimated" lighting values
-
--> much faster to interpolate!
- BUT... ray tracing scales better to very large scenes. Scan conversion can render
unseen models needlessly.
-
Cannot compute refraction &reflection in OpenGL, so
you'll don't get those photorealistic effects.
-
Raytracing isn't the ultimate rendering technique
-
many commercial packages do not use raytracing (eg. Renderman)
-
movie Toy Story: no raytracing!
- reflection & refraction can be simulated using environment mapping
- Radiosity is much more realistic.
References
-
Introduction to Computer Graphics , Foley, van Dam, et
al, Addison Wesley, ISBN 0-201-60921-5.
-
Computer Graphics, F.S. Hill Jr, Macmillan 1990, ISBN 0-02-354860-6.
-
Ray Tracing Worlds with POV-RAY, Enzmann et al, Waite Group
1994, ISBN 1-878739-64-6.
Back to
COSC 3P98 index
COSC 3P98 Computer Graphics
Brock University
Dept of Computer Science
Copyright © 2021 Brian J.
Ross (Except noted figures).
http://www.cosc.brocku.ca/Offerings/3P98/course/lectures/raytracing/
Last updated: April 6, 2021