Game Development Reference
In-Depth Information
/ /
V e r t e x
s h a d e r
o u t p u t .
Note
t h a t
w i t h
t h e
e x c e p t i o n
o f
t h e
o u t p u t
/ /
p o s i t i o n ,
which
i s
o u t p u t
under
t h e
POSITION
s e m a t i c ,
a l l
o t h e r s
go
/ /
under
t h e
TEXCOORDx
s e m a n t i c .
D e s p i t e
i t s
name ,
t h i s
s e m a n t i c
i s
/ /
a c t u a l l y
used
f o r
p r e t t y
much ANY
i n t e r p o l a t e d
v e c t o r
v a l u e
up
t o
4D
/ /
t h a t
we want
t o
p a s s
t o
t h e
p i x e l
s h a d e r ,
n o t
j u s t
t e x t u r e
c o o r d s .
s t r u c t
O u t p u t
{
f l o a t 4
c l i p P o s
:
POSITION ;
/ /
c l i p space
p o s i t i o n
f l o a t 2
uv
:
TEXCOORD0 ;
/ /
t e x t u r e
c o o r d s
f o r
d i f f u s e ,
spec
maps
f l o a t 3
n o r m a l
:
TEXCOORD1 ;
/ /
v e r t e x
normal
i n
model
space
f l o a t 3
modelPos
:
TEXCOORD2 ;
/ /
p o s i t i o n
i n
model
space
} ;
/ /
Model −> c l i p
t r a n s f o r m
m a t r i x .
uniform
f l o a t 4 x 4
m o d e l T o C l i p ;
/ /
The
body
o f
our
v e r t e x
s h a d e r
O u t p u t
main ( I n p u t
i n p u t )
{
O u t p u t
o u t p u t ;
/ /
T r a n s f o r m
v e r t e x
p o s i t i o n
t o
c l i p
space .
o u t p u t . c l i p P o s
= mul ( i n p u t . pos ,
m o d e l T o C l i p ) ;
/ /
P a s s
t h r o u g h
v e r t e x
i n p u t s
w i t h o u t
m o d i f i c a t i o n
o u t p u t . n o r m a l = i n p u t . n o r m a l ;
o u t p u t . uv = i n p u t . uv ;
o u t p u t . modelPos
=
i n p u t . p os ;
r e t u r n
o u t p u t ;
}
Listing 10.13
Vertex shader for per-pixel lighting of a single omni plus ambient
Listing 10.14 is the corresponding pixel shader, where all the action
happens. Notice that we are using two different texture maps, one for the
diffuse color and another for the specular color. We assume that the two
maps use the same texture-mapping coordinates.
/ /
I n t e r p o l a t e d
i n p u t s
from
t h e
v e r t e x
s h a d e r .
s t r u c t
I n p u t
{
f l o a t 2
uv
:
TEXCOORD0 ;
/ /
t e x t u r e
c o o r d s
f o r
d i f f u s e ,
spec
maps
f l o a t 3
n o r m a l
:
TEXCOORD1 ;
/ /
v e r t e x
normal
i n
model
space
f l o a t 3
modelPos
:
TEXCOORD2 ;
/ /
model
space
p o s i t i o n
( f o r
l i g h t i n g )
} ;
/ /
A
g l o b a l
c o n s t a n t
RGB and
o p a c i t y
uniform
f l o a t 4
c o n s t a n t C o l o r ;
/ /
Omni
l i g h t
p o s i t i o n ,
i n MODEL space ,
uniform
f l o a t 3
omniPos ;
/ /
R e c i p r o c a l
o f
omni
l i g h t
r a d i u s .
( The
l i g h t
w i l l
f a l l o f f
/ /
l i n e a r l y
t o
z e r o
a t
t h i s
r a d i u s ) .
Note
t h a t
i t ' s
common
t o
t u c k
/ /
t h i s
i n t o
t h e w component
o f
t h e
p o s i t i o n ,
t o
reduce
t h e
number
o f
/ /
c o n s t a n t s ,
s i n c e
each
c o n s t a n t
u s u a l l y
t a k e s
a
f u l l
4D v e c t o r
s l o t .
uniform
f l o a t
invOmniRad ;
Search WWH ::




Custom Search