aboutsummaryrefslogtreecommitdiff
path: root/mp/src/materialsystem/stdshaders/vertexlitgeneric_inc.vsh
blob: da6b6bf948b6aa500cdb905f42a2bc8934f17626 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "macros.vsh"

sub VertexLitGeneric
{
	local( $detail ) = shift;
	local( $envmap ) = shift;
	local( $envmapcameraspace ) = shift;
	local( $envmapsphere ) = shift;
	local( $decal ) = shift;

	local( $worldPos, $worldNormal, $projPos );
	local( $reflectionVector );

	;------------------------------------------------------------------------------
	; Vertex blending 
	;------------------------------------------------------------------------------
	&AllocateRegister( \$worldPos );
	&AllocateRegister( \$worldNormal );
	&AllocateRegister( \$projPos );
;	if( $g_staticLightType eq "static" && $g_ambientLightType eq "none" &&
;		$g_localLightType1 eq "none" && $g_localLightType2 eq "none" && !$envmap )
	if( 0 )
	{
		; NOTE: Don't do this optimization anymore since it would mean a gazillion combos
		; of the flashlight shaders
		; Special case for static prop lighting.  We can go directly from 
		; world to proj space for position, with the exception of z, which 
		; is needed for fogging *if* height fog is enabled.

		; NOTE: We don't use this path if $envmap is defined since we need
		; worldpos for envmapping.
		dp4 $projPos.x, $vPos, $cModelViewProj0
		dp4 $projPos.y, $vPos, $cModelViewProj1
		dp4 $projPos.z, $vPos, $cModelViewProj2
		dp4 $projPos.w, $vPos, $cModelViewProj3
		; normal
		dp3 $worldNormal.x, $vNormal, $cModel0
		dp3 $worldNormal.y, $vNormal, $cModel1
		dp3 $worldNormal.z, $vNormal, $cModel2

		; Need this for height fog if it's enabled and for height clipping
		dp4 $worldPos.z, $vPos, $cModel2
	}
	else
	{
		&SkinPositionAndNormal( $worldPos, $worldNormal );

		if( $SKINNING == 1 )
		{
			&Normalize( $worldNormal );
		}

		;------------------------------------------------------------------------------
		; Transform the position from world to view space
		;------------------------------------------------------------------------------
		dp4 $projPos.x, $worldPos, $cViewProj0
		dp4 $projPos.y, $worldPos, $cViewProj1
		dp4 $projPos.z, $worldPos, $cViewProj2
		dp4 $projPos.w, $worldPos, $cViewProj3
	}

	mov oPos, $projPos

	;------------------------------------------------------------------------------
	; Fog
	;------------------------------------------------------------------------------
	&CalcFog( $worldPos, $projPos );
	&FreeRegister( \$projPos );

	;------------------------------------------------------------------------------
	; Lighting
	;------------------------------------------------------------------------------
	&DoLighting( $worldPos, $worldNormal );

	if( !$envmap )
	{
		&FreeRegister( \$worldNormal );
	}

	;------------------------------------------------------------------------------
	; Texture coordinates
	;------------------------------------------------------------------------------

	dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
	dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1

	if( $envmap )
	{
		if( $envmapcameraspace )
		{
			&AllocateRegister( \$reflectionVector );
			&ComputeReflectionVector( $worldPos, $worldNormal, $reflectionVector );

			; transform reflection vector into view space
			dp3 oT1.x, $reflectionVector, $cViewModel0
			dp3 oT1.y, $reflectionVector, $cViewModel1
			dp3 oT1.z, $reflectionVector, $cViewModel2

			&FreeRegister( \$reflectionVector );
		}
		elsif( $envmapsphere )
		{
			&AllocateRegister( \$reflectionVector );
			&ComputeReflectionVector( $worldPos, $worldNormal, $reflectionVector );
			&ComputeSphereMapTexCoords( $reflectionVector, "oT1" );

			&FreeRegister( \$reflectionVector );
		}
		else
		{
			&ComputeReflectionVector( $worldPos, $worldNormal, "oT1" );
		}

		; envmap mask
		dp4 oT2.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2
		dp4 oT2.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3

		&FreeRegister( \$worldNormal );
	}
	else
	{
		if ( $decal )
		{
			&AllocateRegister( \$temp );
			mov $temp, $vTexCoord0
			sub oT1.xyz, $temp.xyz, $vTexCoord1.xyz
			sub oT2.xyz, $vTexCoord2.xyz, $temp.xyz
			&FreeRegister( \$temp );
		}
		else
		{
			; YUCK!  This is to make texcoords continuous for mat_softwaretl
			mov oT1, $cZero
			mov oT2, $cZero
		}
	}

	if( $detail )
	{
		dp4 oT3.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_4
		dp4 oT3.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_5
	}
	&FreeRegister( \$worldPos );
}