-
Notifications
You must be signed in to change notification settings - Fork 0
/
soldier_skin.cg
230 lines (173 loc) · 5.79 KB
/
soldier_skin.cg
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include "tools.cg"
/*
// integrated outline
void soldier_skin_vp(
uniform float4x4 matrices[17],
uniform float4x4 viewProj,
uniform float pointSize,
// uniform float4 fogColor,
// uniform float4 fogParams,
float4 position : POSITION,
float4 color : COLOR,
float u : TEXCOORD0,
out float4 outPosition : POSITION,
out float4 outColor : COLOR,
// for some reason, nvidia seems to have all texcoord* as texture coordinates
// for the point sprite in fragment shader, it's no use passing anything
// here
// out float4 outFogColor : TEXCOORD1,
out float outSize : PSIZE)
{
float4x4 result = matrices[u];
result = mul(viewProj, result);
outPosition = mul(result, position);
// color.a carries info about outline mesh
// 0 means outline, 1 means colors
float outlineFactor = 1.0 - color.a;
outColor.rgb = color.rgb * color.a;
outColor.a = 1.0;
outSize = pointSize * (1.0 + outlineFactor);
//outFogColor = fog(fogColor, oPosition.z, fogParams);
outPosition.z = outPosition.z + 0.005 * outlineFactor;
}
*/
void soldier_skin_vp(
uniform float4x4 matrices[17],
uniform float4x4 viewProj,
//uniform float4 fogColor,
//uniform float4 fogParams,
float4 position : POSITION,
float4 color : COLOR,
float u : TEXCOORD0,
out float4 outPosition : POSITION,
out float4 outColor : COLOR)
// for some reason, nvidia seems to have all texcoord* as texture coordinates
// for the point sprite in fragment shader, it's no use passing anything
// here
//out float4 outFogColor : TEXCOORD1,
{
float4x4 result = matrices[u];
result = mul(viewProj, result);
outPosition = mul(result, position);
outColor.rgb = color.rgb;
outColor.a = 1.0;
//outFogColor = fog(fogColor, oPosition.z, fogParams);
}
void soldier_skin_fp(
float4 color : COLOR,
float4 uv : TEXCOORD0,
uniform float4 fogColor,
uniform float4 fogParams,
uniform float4 cameraPositionInObjectSpace,
uniform float4 diffuseLightColor,
out float4 result : COLOR)
{
// apply some internal shading, just a bit, too much causes ants
float factor = 0.85;
color *= step(0.5, 1.0 - uv.y) * (1.0 - factor) + factor;
// apply some diffuse light
color = (color * 0.75 + diffuseLightColor * color * 0.95);
float4 f = fog(fogColor, length(cameraPositionInObjectSpace), fogParams);
f.a *= 0.9;
float4 res = blend_fog(f, color);
result = cb_color_convert(res);
}
void soldier_skin_ghost_vp(
uniform float4x4 matrices[17],
uniform float4 teamColor,
uniform float4x4 viewProj,
uniform float4 ambient,
float4 position : POSITION,
float4 color : COLOR,
float u : TEXCOORD0,
out float4 oPosition : POSITION,
out float4 oColor : COLOR)
{
float4x4 result = matrices[u];
result = mul(viewProj, result);
oPosition = mul(result, position);
float weight = 0.5;
oColor.rgb = weight * ambient.rgb + (1.0 - weight) * teamColor.rgb * 1.2;
oColor.a = 1.0;
}
void soldier_skin_ghost_fp(
float4 color : COLOR,
out float4 result : COLOR)
{
result = cb_color_convert(color);
}
void soldier_skin_shadow_vp(
uniform float4x4 matrices[17],
uniform float4x4 viewProj,
uniform float4 texelOffsets,
float4 position : POSITION,
float u : TEXCOORD0,
out float4 oPosition : POSITION,
out float2 outDepth : TEXCOORD0)
{
int index = u;
float4x4 result = matrices[u];
result = mul(viewProj, result);
oPosition = mul(result, position);
// fix pixel / texel alignment
oPosition.xy += texelOffsets.zw * oPosition.w;
outDepth.x = oPosition.z;
outDepth.y = oPosition.w;
}
void soldier_skin_normal_and_depth_vp(
uniform float4x4 matrices[17],
uniform float4x4 viewProj,
float4 position : POSITION,
float u : TEXCOORD0,
uniform float nearDepth,
uniform float farDepth,
out float4 oPosition : POSITION,
out float4 oNormalDepth : COLOR)
{
int index = u;
float4x4 result = matrices[u];
result = mul(viewProj, result);
oPosition = mul(result, position);
oNormalDepth.r = 0.5;
oNormalDepth.g = 0.5;
oNormalDepth.b = 0.0;
//oPosition.z -= 0.0;
oNormalDepth.a = saturate((oPosition.z - nearDepth) / (farDepth - nearDepth));
}
void soldier_skin_normal_and_depth_fp(
float4 color : COLOR,
out float4 oColor : COLOR)
{
oColor = color;
}
void soldier_skin_outline_vp(
uniform float4x4 matrices[17],
uniform float4x4 viewProj,
float4 position : POSITION,
float4 color : COLOR,
float u : TEXCOORD0,
out float4 oPosition : POSITION,
out float4 oColour : COLOR)
{
float4x4 result = matrices[u];
result = mul(viewProj, result);
oPosition = mul(result, position);
//oPosition.z = oPosition.z + 0.01;
oPosition.z = oPosition.z + 0.005;
oColour.r = 0.0;
oColour.g = 0.0;
oColour.b = 0.0;
oColour.a = 1.0;
}
void soldier_skin_outline_fp(
float4 color : COLOR,
uniform float4 fogColor,
uniform float4 fogParams,
uniform float4 cameraPositionInObjectSpace,
out float4 oColor : COLOR)
{
float4 f = fog(fogColor, length(cameraPositionInObjectSpace), fogParams);
f.a *= 0.8;
oColor = blend_fog(f, color);
//oColor = color;
}