Documente Academic
Documente Profesional
Documente Cultură
Ray Casting
Ideal Scenario:
we'd like to magically know which rays will eventually contribute tothe
image, and trace only those
At the end weve done forward ray tracing, but only for the
rays that contribute to the image
Ray casting
This version of ray tracing is often called ray casting
The algorithm is:
loop y
loop x
shoot ray from eye point through pixel (x,y) into scene
intersect with all surfaces, find first one the ray hits
shade that point to compute pixel (x,y)s color
(perhaps simulating shadows)
Compute Intersections:
Projecting a polygon 3D to 2D
Barycentric coordinates in 1D
Linear interpolation between colors C0 and C1 by t
We can rewrite this as
Geometric intuition:
We are weighting each vertex by ratio of distances (or areas)
C0 a
C
C1
b
a and b are called barycentric coordinates
Barycentric coordinates in 2D
Now suppose we have 3 points instead of 2
C1
C2
C0
Define three barycentric coordinates: a, b, g
Para um triangulo
efine barycentric coordinates to be ratios of
triangle areas
in 2-D
Area(xy-projection(ABC)) = [(bx-ax)(cy-ay) (cx-ax)(by-ay)]/2 project
A,B,C to xy plane, take z component of cross product
positive if ABC is CCW (counterclockwise)
Usando lgebra
That short formula Area(ABC) = [(bx-ax)(cy-ay) (cx-ax)(by-ay)]/2
Where did it come from?
cy
ay
by
ax
bx cx
(bx-ax)(cy-ay)
(cx-ax)(by-ay)
+
cy
ay
/2=
by
ax bx cx
/2=
!
It works:-).