Game Development Reference
In-Depth Information
/ /
I n t e r p o l a t e
c o l o r ,
z b u f f e r
v a l u e ,
/ /
and
t e x t u r e
mapping
c o o r d s
/ /
The
p i x e l
s h a d e r
t a k e s
i n t e r p o l a t e d
v a l u e s
/ /
and
computes
a
c o l o r
and
a l p h a
v a l u e
c o l o r
=
s h a d e P i x e l ( ) ;
/ /
P e r f o r m
z b u f f e r i n g
i f
( ! z b u f f e r T e s t ( ) )
c o n t i n u e ;
/ /
Alpha
t e s t
t o
i g n o r e
p i x e l s
t h a t
a r e
” t o o
/ /
t r a n s p a r e n t ”
i f
( ! a l p h a T e s t ( ) )
c o n t i n u e ;
/ /
W r i t e
t o
t h e
f r am e
b u f f e r
and
z b u f f e r
w r i t e P i x e l ( c o l o r ,
i n t e r p o l a t e d Z ) ;
/ /
Move on
t o
t h e
n e x t
p i x e l
i n
t h i s
t r i a n g l e
}
/ /
Move on
t o
t h e
n e x t
t r i a n g l e
i n
t h i s
o b j e c t
}
/ /
Move on
t o
t h e
n e x t
p o t e n t i a l l y
v i s i b l e
o b j e c t
}
Listing 10.10
Pseudocode for the graphics pipeline
It wasn't too long ago that a graphics programmer would be responsi-
ble for writing code to do all of the steps shown Listing 10.10 in software.
Nowadays, we delegate many tasks to a graphics API such as DirectX or
OpenGL. The API may perform some of these tasks in software on the main
CPU, and other tasks (ideally, as many as possible) are dispatched to spe-
cialized graphics hardware. Modern graphics hardware allows the graphics
programmer (that's us) very low level control through vertex shaders and
pixel shaders, which are basically microprograms we write that are exe-
cuted on the hardware for each vertex and pixel that is processed. While
performance concerns in the old single processor software rendering days
were addressed with hand-tuned assembly, nowadays the concerns are more
about using the GPU as e ciently as possible, and ensuring that it is never
idle, waiting on the CPU to do anything. Of course, both now and then the
simplest way to speed up rendering something is to simply avoid rendering
it at all (if it isn't visible) or to render a cheaper approximation of it (if it's
not large on the screen).
In summary, a modern graphics pipeline involves close cooperation of
our code and the rendering API. When we say “rendering API,” we mean
the API software and the graphics hardware. On PC platforms the API
software layer is necessarily very “thick,” due to the wide variety of under-
lying hardware that must be supported. On console platforms where the
Search WWH ::




Custom Search