Game Development Reference
In-Depth Information
f o r
( each
x , y
s c r e e n
p i x e l )
{
/ /
S e l e c t
a
r a y
f o r
t h i s
p i x e l
Ray
r a y
=
g e t R a y F o r P i x e l ( x , y ) ;
/ /
I n t e r s e c t
t h e
r a y
a g a i n s t
t h e
geometry .
T h i s
w i l l
/ /
n o t
j u s t
r e t u r n
t h e
p o i n t
o f
i n t e r s e c t i o n ,
b u t
a l s o
/ /
a
s u r f a c e
normal
and some
o t h e r
i n f o r m a t i o n
needed
/ /
t o
shade
t h e
p o i n t ,
such
a s
an
o b j e c t
r e f e r e n c e ,
/ /
m a t e r i a l
i n f o r m a t i o n ,
l o c a l
S , T
c o o r d i n a t e s ,
e t c .
/ /
Don ' t
t a k e
t h i s
pseudocode
t o o
l i t e r a l l y .
V e c t o r 3
pos ,
n o r m a l ;
O b j e c t
o b j ;
M a t e r i a l
m t l ;
i f
( r a y I n t e r s e c t S c e n e ( r a y ,
pos ,
normal ,
o b j ,
m t l ) )
{
/ /
Shade
t h e
i n t e r s e c t i o n
p o i n t .
( What
l i g h t
i s
/ /
e m i t t e d / r e f l e c t e d
from
t h i s
p o i n t
t o w a r d s
t h e
camera ? )
C o l o r
c
=
s h a d e P o i n t ( r a y ,
pos ,
normal ,
o b j ,
m t l ) ;
/ /
P u t
i t
i n t o
t h e
f ra m e
b u f f e r
w r i t e F r a m e B u f f e r ( x , y ,
c ) ;
}
e l s e
{
/ /
Ray
m i s s e d
t h e
e n t i r e
s ce ne .
J u s t
use
a
g e n e r i c
/ /
background
c o l o r
a t
t h i s
p i x e l
w r i t e F r a m e B u f f e r ( x , y ,
b a c k g r o u n d C o l o r ) ;
}
}
Listing 10.1
Pseudocode for the raytracing algorithm
or reflected from that surface back in the direction of the ray. A highly
simplified summary of this algorithm is illustrated by Listing 10.1.
The other major strategy for visible surface determination, the one used
for real-time rendering at the time of this writing, is known as depth buffer-
ing. The basic plan is that at each pixel we store not only a color value, but
also a depth value. This depth buffer value records the distance from the
eye to the surface that is reflecting or emitting the light used to determine
the color for that pixel. As illustrated in Listing 10.1, the “outer loop” of
a raytracer is the screen-space pixels, but in real-time graphics, the “outer
loop” is the geometric elements that make up the surface of the scene.
The different methods for describing surfaces are not important here.
What is important is that we can project the surface onto screen-space and
map them to screen-space pixels through a process known as rasterization.
For each pixel of the surface, known as the source fragment, we compute
the depth of the surface at that pixel and compare it to the existing value
color” is not too bad of a description of the reconstruction process. Nonetheless, whether
pixels are rectangles or point samples, we still might not send a single ray through the
center of each pixel, but rather we might send several rays (“samples”) in a smart pattern,
and average them together them in a smart way.
Search WWH ::




Custom Search