The Fundamentals of Ray-Tracing - PowerPoint PPT Presentation

About This Presentation
Title:

The Fundamentals of Ray-Tracing

Description:

float FirstIntersect(ray iobject, x) // =0 if no intersection. t = -1. FOR each object ... Color Trace( ray ) IF (FirstIntersect(ray object, x) = 0) RETURN La. ENDIF ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 42
Provided by: infUs
Category:

less

Transcript and Presenter's Notes

Title: The Fundamentals of Ray-Tracing


1
The Fundamentals of Ray-Tracing
Szirmay-Kalos László Dept. of Control Engineering
and Information Technology Budapest University of
Technology email szirmay_at_iit.bme.hu Web
http//www.iit.bme.hu/szirmay
2
Rendering
Real world
color
?
3
Light-object interaction
Lin
Lin
kr Lin
?
?
?
Lin fr(?,?) cos?
kt Lin
prob. density
Coherent terms geometric optics
Incoherent terms probability theory
BRDF fr(?,?) Lout/Lin cos? Bi-directional
reflection distribution function
4
BRDF modelling
  • Depends on
  • the wavelength
  • light direction
  • viewing direction
  • surface normal
  • Physical measurements
  • Tuning simple formulae

5
Diffuse reflection
  • Light intensity is independent of the viewing
    direction

q
Lref Lir kd (l) cos ?
?
Lamberts law
6
Diffuse surfaces
7
Phongs specular reflection
?r
?r
q
y
diffuse
q
?
?
Function large at y0 and goes to zero
ks cosn y
8
DiffusePhong materials
own color
diffuse
Plastics ks is white
Phong
diffuse Phong
5 10 20 50
n
9
Diffuse Phong materials
10
General rendering problem
L
wr
?
Le
wt
11
Local Illumination
?l
pixel
Light sources
L (w) ? Le(w)Sl rl Ll (?l) fr (?l ,?) cos ?l
0/1 Light source visibility Shadows
Point, directional light sources
12
Role of the ambient term
Local illumination
ambient term
L (w) ? Le(w)Sl rl Ll (?l) fr (?l ,?) cos ?l
ka La
13
Ray-tracing
Refracted ray
Reflection ray
Ll
shadow ray
L(w) Le(w)Sl rl Ll (?l) fr (?l ,?) cos ?l
ka La kr Lin (wr) kt Lin(wt)
from the refraction direction
from the reflection direction
14
Ray-tracing Global illumination
Local illumination Local illumination shad
ows
Photorealistic image synthesis
15
Steps of ray-tracing
Refracted ray
Reflection ray
shadow ray
  • Light intensity coming through a pixel
  • Visible point and the normal vector here
  • Visible light sources from here
  • mirror and refraction directions
  • Light intensity coming from the reflection
    direction
  • Light intensity coming form the refraction
    direction
  • Adding up the light components andcolor the pixel

16
Tasks of ray-tracing
  • Visibility computation
  • Determination of that point which is visible from
    a point in a given direction normal vector here
  • pointdirection ray
  • Computation of the mirroring and refraction
    directions
  • Evaluation of the illumination formula ?

L(w) Le(w)Sl rl Ll (?l) fr (?l ,?) cos ?l
ka La kr Lin (wr) kt Lin(wt)
17
Visibility calculation
x
ray(t) eye v t, t gt 0
float FirstIntersect(ray ? iobject, x) //
lt0 if no intersection t -1 FOR each
object tnew Intersect( ray, object ) // lt 0
if no intersection IF (tnew gt 0 tnew lt t) t
tnew, iobject object ENDFOR IF (t gt
0) x eye v t RETURN t END
18
Intersection with a Sphere
r - center 2 R2
r
R
center
no root 1 root 2 roots
ray(t) - center 2 R2
(v v) t 2 2 ((eye-center) v) t ((eye-center)
(eye-center))- R2 0 Wanted minimum from the
positive solutions
Surface normal (ray(t) - center)/R
19
Quadric surfaces
x y z 1
Second order equation
x,y,z,1 A 0
Quadric surface
Infinite cone x2 y2
Ellipsoid x2 y2 z2
Infinite cylinder x2 y2
? ? ? -10
? ? - 1 0
? ? - z2 0
a2 b2
a2 b2 c2
a2 b2
20
Triangle
Phase 1
Phase 2
r3
n
p
r1
r2
r1
1. Intersection with the plane (ray(t) - r1) n
0, t gt 0 Normal vector n (r2 - r1) x (r3
- r1) 2. Is the intersection point p inside the
triangle? ((r2 - r1) x (p - r1)) ((r2 - r1)
x (r3 - r1)) gt 0 ((r3 - r2) x (p - r2))
((r3 - r2) x (r1 - r2)) gt 0 ((r1 - r3) x (p -
r3)) ((r1 - r3) x (r2 - r3)) gt 0
21
Shading normals
N
N2
N1
(X1 , Y1 , Z1 )
N3
N A X B Y C
A, B, C
N1 A X1 B Y1 C N2 A X2 B Y2 C N3 A
X3 B Y3 C
3 systems of equations of 3 unknowns
22
Parametric surfaces
control points
r(u,v) S S Bi,j (u,v) ri, j
blending functions
23
Intersecting parametric sufaces
r(u,v), u,v in 0,1 ray(t) eye v t, t gt
0 r(u,v) ray(t) Solution of the
equation u,v,t Test 0lt u,v lt 1, t gt 0
Recursive tessellation
24
Animated objects
T1
T1-1
T2
T2 -1
25
Tasks of ray-tracing
  • Visibility computation ?
  • Determination of that point which is visible from
    a point in a given direction normal vector here
  • pointdirection ray
  • Computation of the mirroring and refraction
    directions
  • Evaluation of the illumination formula ?

26
Reflection Direction
horizontal vector
new ray x vr t
N
v N cosa
v N cosa
N cosa
vr
v
L vr, V v ReflectDir( L, N, V )
L V - N (N V) 2
a
a
x
cos a - (vN)
vr v 2 cos a N
27
Refraction Direction
horizontal vector
N
Snellius law
sin a
v Ncosa
n
sin b
v
a
N?
N?sinb
-Ncosb
b
vt
28
Camera definition
fov, aspect
lookat
eye
XRES, YRES
29
Ray-tracing algorithm
p
ray
Render( ) for each pixel p Ray r ray( eye
? pixel p ) color Trace(ray) WritePixel(
p, color) endfor end
p
color
30
Trace function
Color Trace( ray ) IF
(FirstIntersect(ray ? object, x) lt 0) RETURN
La ENDIF color Le (x, -ray.dir)
color Direct Lightsource(x, -ray.dir)
IF ( kr gt 0 ) THEN ReflectDir( ray,
reflected ray) color kr Trace( reflected
ray ) ENDIF IF ( kt gt 0
RefractDir( ray, refracted ray ) ) color kt
Trace( refracted ray ) ENDIF RETURN color
Color Trace( ray, d) IF d gt dmax THEN
RETURN La IF ( FirstIntersect(ray ? object,
x) lt 0) RETURN La ENDIF color
Le (x, -ray.dir) color Direct
Lightsource(x, -ray.dir) IF ( kr gt 0 ) THEN
ReflectDir( ray, reflected ray) color kr
Trace( reflected ray, d1 ) ENDIF IF
( kt gt 0 RefractDir( ray, refracted ray )
) color kt Trace( refracted ray, d1 )
ENDIF RETURN color
ray
31
DirectLightsource function
DirectLightsource( x, vdir ) color ka La
FOR each lightsource l DO shadowray x to
lightsourcel t FirstIntersect( shadowray
) IF (t lt 0 t gt x - lightsourcel.pos)
color Brdf(ldir, x, vdir) cos ??l'
lightsourcel.Intensity ENDIF
ENDFOR RETURN color
shadow
pixel
vdir
x
32
Ray-tracer class diagram
Material Le, kd, ks, shine kr, kt,
n BRDF ReflectDir RefractDir
Scene
Object
Light
La
transform
Le, pos
Primitive( )
Define Render FirstIntersect DirectLightsource Tra
ce(Ray)
Dir(Point) Intens(Point)
Primitive
Intersect(Ray) Normal( )
Camera
Ray
XRES, YRES eye, lookat, vup fov, aspect
Sphere
Mesh
dir, start
Center, radius
vertices
Dir( ) Start( )
GetXRes( ) GetYRes( ) GetRay(int,int)
Intersect(Ray) Normal( )
Intersect(Ray) Normal( )
33
Ray-tracing results
PovRay
Computation time ? Pixel Object (Light
source 1)
34
Speeding up the intersection calculation
  • Speeding up for each objects
  • bounding volumes
  • Computing for less number of objects
  • space partitioning

35
Bounding Volume
36
Space partitioning methods
objects
pre- processing
ray- tracing
Space-partitioning data structure
First intersection
  • Data structure
  • Knowing the ray, it reduces the number of
    objects the ray may intersect.
  • If we find an intersected object, the search can
    be terminated.

37
Uniform space partitioning
Preprocessing FOR each cell identify the
objects that are partly
here complexity O(n c ) O(n 2)
38
Octree
Tree build IF a cell contains just a few
objects register objects in this cell
ELSE subdivide cells c1, c2, , c8 Tree
build(c1) Tree build(c8) ENDIF
2
1
3
Octree
39
Kd (BSP) tree
Tree build IF a cell contains just a few
objects register objects in this cell
ELSE find a subdivision plane cell halving with
the plane c1, c2 Tree build (c1) Tree build
(c2) ENDIF
2
1
3
kd-tree
40
Example 1
41
Example 2
Write a Comment
User Comments (0)
About PowerShow.com