aboutsummaryrefslogtreecommitdiff
path: root/mp/src/materialsystem/stdshaders/Cable.vsh
blob: 857a2e3b26419a2942e5558de389478ae8fd44cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
vs.1.1

#include "macros.vsh"

# DYNAMIC: "DOWATERFOG"				"0..1"

;------------------------------------------------------------------------------
; The cable equation is:
; [L dot N] * C * T
;
; where:
; C = directional light color
; T = baseTexture
; N = particle normal (stored in the normal map)
; L = directional light direction
;
;	$SHADER_SPECIFIC_CONST_0		= Directional light direction
;------------------------------------------------------------------------------


;------------------------------------------------------------------------------
; Transform position from object to projection space
;------------------------------------------------------------------------------

&AllocateRegister( \$projPos );

dp4		$projPos.x, $vPos, $cModelViewProj0
dp4		$projPos.y, $vPos, $cModelViewProj1
dp4		$projPos.z, $vPos, $cModelViewProj2
dp4		$projPos.w, $vPos, $cModelViewProj3

mov		oPos, $projPos


;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------

alloc $worldPos
if( $DOWATERFOG == 1 )
{
	; Get the worldpos z component only since that's all we need for height fog
	dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos

&FreeRegister( \$projPos );

;------------------------------------------------------------------------------
; Setup the tangent space
;------------------------------------------------------------------------------

&AllocateRegister( \$tmp1 );
&AllocateRegister( \$tmp2 );
&AllocateRegister( \$tmp3 );
&AllocateRegister( \$r );

; Get S crossed with T (call it R)
mov		$tmp1, $vTangentS
mov		$tmp2, $vTangentT

mul		$tmp3, $vTangentS.yzxw,  $tmp2.zxyw
mad		$r, -$vTangentS.zxyw, $tmp2.yzxw, $tmp3

&FreeRegister( \$tmp2 );
&FreeRegister( \$tmp3 );

&AllocateRegister( \$s );

; Normalize S (into $s)
dp3		$s.w, $vTangentS, $vTangentS
rsq		$s.w, $s.w
mul		$s.xyz, $vTangentS, $s.w

; Normalize R (into $r)
dp3		$r.w, $r, $r
rsq		$r.w, $r.w
mul		$r.xyz, $r, $r.w

&AllocateRegister( \$t );

; Regenerate T (into $t)
mul		$t, $r.yzxw,  $tmp1.zxyw
mad		$t, -$r.zxyw, $tmp1.yzxw, $t

&FreeRegister( \$tmp1 );

;------------------------------------------------------------------------------
; Transform the light direction (into oD1)
;------------------------------------------------------------------------------

&AllocateRegister( \$lightDirection );

dp3		$lightDirection.x, $s, $SHADER_SPECIFIC_CONST_0
dp3		$lightDirection.y, $t, $SHADER_SPECIFIC_CONST_0
dp3		$lightDirection.z, $r, $SHADER_SPECIFIC_CONST_0

&FreeRegister( \$r );
&FreeRegister( \$s );
&FreeRegister( \$t );

; Scale into 0-1 range (we're assuming light direction was normalized prior to here)
add		oT2, $lightDirection, $cHalf	; + 0.5 
&FreeRegister( \$lightDirection );

;------------------------------------------------------------------------------
; Copy texcoords for the normal map and base texture
;------------------------------------------------------------------------------

mov		oT0, $vTexCoord0
mov		oT1, $vTexCoord1

; Pass the dirlight color through
mov		oD0.xyzw, $vColor