Game Development Reference
In-Depth Information
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
&
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 ;
/ /
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 ;
/ /
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 ;
/ /
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 ) ;
/ /
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
i n p u t . p o s . x y z ;
/ /
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
i n p u t . 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 ( i n p u t . normal ,
i n p u t . t a n g e n t D e t . x y z )
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 ,
i n p u t . t a n g e n t D e t . x y z ) ;
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 ,
i n p u t . n o r m a l ) ;
o u t p u t .H. x
=
dot ( H model ,
i n p u t . t a n g e n t D e t . x y z ) ;
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 ,
i n p u t . 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 .
f l o a t
a t t e n F a c t o r
=
1
d i s t omniPosAndInvRad .w;
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.21
Vertex shader for omni lighting of normal mapped object, with lighting done in tangent space
Search WWH ::




Custom Search