Game Development Reference
In-Depth Information
/ /
View
p o s i t i o n ,
i n MODEL space
uniform
f l o a t 3
v i e w P o s ;
/ /
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 ;
/ /
G e n e r a t e
a
blended
m a t r i x .
f l o a t 4 x 3 b l e n d e d M a t =
b o n e M a t r i x [ i n p u t . bones . x ] i n p u t . w e i g h t . x
+
b o n e M a t r i x [ i n p u t . bones . y ] i n p u t . w e i g h t . y
+
b o n e M a t r i x [ i n p u t . bones . z ] i n p u t . w e i g h t . z
+
b o n e M a t r i x [ i n p u t . bones .w] i n p u t . w e i g h t .w;
/ /
P e r f o r m
s k i n n i n g
t o
g e t
v a l u e s
i n
model
space ,
/ /
i n
t h e
c u r r e n t
pose
f l o a t 3
p o s
= mul ( i n p u t . pos ,
b l e n d e d M a t ) ;
f l o a t 3
n o r m a l
=
n o r m a l i z e ( mul ( f l o a t 4 ( i n p u t . normal , 0 ) ,
b l e n d e d M a t ) ) ;
f l o a t 3 t a n g e n t =
n o r m a l i z e ( mul ( f l o a t 4 ( i n p u t . t a n g e n t D e t . xyz , 0 ) ,
b l e n d e d M a 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 . po s
= mul ( f l o a t 4 ( pos , 1 ) ,
m o d e l T o C l i p ) ;
/ /
Compute
v e c t o r
t o
l i g h t
( i n
model
space )
f l o a t 3
L m o d e l
=
omniPosAndInvRad . x y z
p o s ;
/ /
Normalize
i t ,
and
s a v e
o f f
d i s t a n c e
t o
use
l a t e r
/ /
f o r
a t t e n u a t i o n
f l o a t
d i s t
=
l e n g t h ( L m o d e l ) ;
f l o a t 3
L m o d e l n o r m
=
L m o d e l
/
d i s t ;
/ /
Compute
view
and
h a l f w a y
v e c t o r
f l o a t 3
V model
=
n o r m a l i z e ( v i e w P o s
p o s ) ;
f l o a t 3
H model
=
n o r m a l i z e ( V model
+
L m o d e l n o r m ) ;
/ /
R e c o n s t r u c t
t h e
t h i r d
b a s i s
v e c t o r
f l o a t 3
b i n o r m a l
=
c r o s s ( normal ,
t a n g e n t )
i n p u t . t a n g e n t D e t .w;
/ /
R o t a t e
l i g h t i n g r e l a t e d
v e c t o r s
i n t o
t a n g e n t
space
o u t p u t . L . x
=
dot ( L model ,
t a n g e n t ) ;
o u t p u t . L . y
=
dot ( L model ,
b i n o r m a l ) ;
o u t p u t . L . z
=
dot ( L model ,
n o r m a l ) ;
o u t p u t .H. x
=
dot ( H model ,
t a n g e n t ) ;
o u t p u t .H. y
=
dot ( H model ,
b i n o r m a l ) ;
o u t p u t .H. z
=
dot ( H model ,
n o r m a l ) ;
/ /
Compute UNCLAMPED
c o l o r
+
a t t e n u a t i o n
f a c t o r .
1
d i s t omniPosAndInvRad .w;
f l o a t
a t t e n F a c t o r
=
o u t p u t . l i g h t C o l o r
=
o m n i C o l o r
a t t e n F a c t o r ;
/ /
P a s s
t h r o u g h
mapping
c o o r d 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 . uv
=
i n p u t . uv ;
r e t u r n
o u t p u t ;
}
Listing 10.24
Vertex shader for skinned, normal-mapped geometry
Search WWH ::




Custom Search