Game Development Reference
In-Depth Information
/ /
f o r
t h e
c u r r e n t
pose .
Note
t h e
m a t r i x
m u l t i p l i c a t i o n
/ /
[ 1 x3 ]
=
[ 1 x4 ]
x
[ 4 x3 ]
o u t p u t . modelPos
= mul ( i n p u t . pos ,
b l e n d e d M a t ) ;
o u t p u t . n o r m a l
= mul ( f l o a t 4 ( i n p u t . normal , 0 ) ,
b l e n d e d M a t ) ;
o u t p u t . n o r m a l
=
n o r m a l i z e ( o u t p u t . n o r m a l ) ;
/ /
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 ( f l o a t 4 ( o u t p u t . modelPos , 1 ) ,
m o d e l T o C l i p ) ;
/ /
P a s s
t h r o u g h
UVs
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.23
Vertex shader for skinned geometry
We have declared the vertices as an array of vertex shader constants, and
sending all these matrices to the hardware can be a significant performance
bottleneck. On certain platforms there are more e cient ways of doing this,
such as indexing into an auxiliary “vertex” stream.
Next, let's show how to use normal mapping on a skinned mesh. The
vertex shader in Listing 10.24 could be used with the pixel shader in List-
ing 10.22.
/ /
Mesh
i n p u t s .
s t r u c t
I n p u t
{
f l o a t 4
p o s
:
POSITION ;
/ /
model
space
posn
( b i n d i n g
pose )
f l o a t 3
n o r m a l
: NORMAL ;
/ /
v e r t e x
normal
i n
model
space
f l o a t 4
t a n g e n t D e t
:
TANGENT ;
/ /
model
space
t a n g e n t ,
d e t
i n w
by te 4
bones
:
BLENDINDICES ;
/ /
Bone
i n d i c e s .
Unused
e n t r i e s
0
f l o a t 4
w e i g h t
:
BLENDWEIGHT ;
/ /
Blend
w e i g h t s .
Unused
e n t r i e s
0
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 ,
spec
maps
} ;
/ /
V e r t e x
s h a d e r
o u t p u t
s t r u c t
O u t p u t
{
f l o a t 4
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
a l l
maps
f l o a t 3
L
:
TEXCOORD1 ;
/ /
v e c t o r
t o
l i g h t ,
i n
TANGENT space
f l o a t 3 H
:
TEXCOORD2 ;
/ /
h a l f w a y
v e c t o r ,
i n
TANGENT space
f l o a t 3
l i g h t C o l o r
:
TEXCOORD3 ;
/ /
l i g h t
c o l o r
+ and
a t t e n u a t i o n
f a c t o r
} ;
/ /
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 ;
/ /
A r r a y
o f
' ' b i n d i n g
pose −> c u r r e n t ' '
pose
m a t r i c e s
f o r
each
bone .
# d e f i n e
MAX BONES
40
uniform
f l o a t 4 x 3
b o n e M a t r i x [ MAX BONES ] ;
/ /
Omni
l i g h t
p o s i t i o n ,
i n MODEL space ,
and
r e c i p r o c a l
o f
/ /
f a l l o f f
i n
t h e w component
uniform
f l o a t 4
omniPosAndInvRad ;
/ /
U n a t t e n u a t e d
omni
l i g h t
c o l o r
uniform
f l o a t 3
o m n i C o l o r ;
Search WWH ::




Custom Search