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
|
[require]
GLSL >= 1.10
[fragment shader]
#define FRAGMENT_SHADER
// Warsow GLSL shader
#if !defined(__GLSL_CG_DATA_TYPES)
#define myhalf float
#define myhalf2 vec2
#define myhalf3 vec3
#define myhalf4 vec4
#else
#define myhalf half
#define myhalf2 half2
#define myhalf3 half3
#define myhalf4 half4
#endif
varying vec4 ProjVector;
#ifdef VERTEX_SHADER
// Vertex shader
void main(void)
{
gl_FrontColor = gl_Color;
mat4 textureMatrix;
textureMatrix = gl_TextureMatrix[0];
gl_Position = ftransform();
ProjVector = textureMatrix * gl_Vertex;
}
#endif // VERTEX_SHADER
#ifdef FRAGMENT_SHADER
// Fragment shader
uniform myhalf3 LightAmbient;
uniform float TextureWidth, TextureHeight;
uniform float ProjDistance;
uniform sampler2DShadow ShadowmapTexture;
void main(void)
{
myhalf color = myhalf(1.0);
if (ProjVector.w <= 0.0 || ProjVector.w >= ProjDistance)
discard;
float dtW = 1.0 / TextureWidth;
float dtH = 1.0 / TextureHeight;
vec3 coord = vec3 (ProjVector.xyz / ProjVector.w);
coord = (coord + vec3 (1.0)) * vec3 (0.5);
coord.s = float (clamp (float(coord.s), dtW, 1.0 - dtW));
coord.t = float (clamp (float(coord.t), dtH, 1.0 - dtH));
coord.r = float (clamp (float(coord.r), 0.0, 1.0));
myhalf shadow0 = myhalf(shadow2D(ShadowmapTexture, coord).r);
myhalf shadow = shadow0;
#if defined(APPLY_PCF2x2) || defined(APPLY_PCF3x3)
vec3 coord2 = coord + vec3(0.0, dtH, 0.0);
myhalf shadow1 = myhalf (shadow2D (ShadowmapTexture, coord2).r);
coord2 = coord + vec3(dtW, dtH, 0.0);
myhalf shadow2 = myhalf (shadow2D (ShadowmapTexture, coord2).r);
coord2 = coord + vec3(dtW, 0.0, 0.0);
myhalf shadow3 = myhalf (shadow2D (ShadowmapTexture, coord2).r);
#if defined(APPLY_PCF3x3)
coord2 = coord + vec3(-dtW, 0.0, 0.0);
myhalf shadow4 = myhalf (shadow2D (ShadowmapTexture, coord2).r);
coord2 = coord + vec3(-dtW, -dtH, 0.0);
myhalf shadow5 = myhalf (shadow2D (ShadowmapTexture, coord2).r);
coord2 = coord + vec3(0.0, -dtH, 0.0);
myhalf shadow6 = myhalf (shadow2D (ShadowmapTexture, coord2).r);
coord2 = coord + vec3(dtW, -dtH, 0.0);
myhalf shadow7 = myhalf (shadow2D (ShadowmapTexture, coord2).r);
coord2 = coord + vec3(-dtW, dtH, 0.0);
myhalf shadow8 = myhalf (shadow2D (ShadowmapTexture, coord2).r);
shadow = (shadow0 + shadow1 + shadow2 + shadow3 + shadow4 + shadow5 + shadow6 + shadow7 + shadow8) * myhalf(0.11);
#else
shadow = (shadow0 + shadow1 + shadow2 + shadow3) * myhalf(0.25);
#endif
#else
shadow = shadow0;
#endif
float attenuation = float (ProjVector.w) / ProjDistance;
myhalf compensation = myhalf(0.25) - max(LightAmbient.x, max(LightAmbient.y, LightAmbient.z))
;compensation = max (compensation, 0.0);
color = shadow + attenuation + compensation;
gl_FragColor = vec4(vec3(color),1.0);
}
#endif // FRAGMENT_SHADER
[vertex shader]
#define VERTEX_SHADER
// Warsow GLSL shader
#if !defined(__GLSL_CG_DATA_TYPES)
#define myhalf float
#define myhalf2 vec2
#define myhalf3 vec3
#define myhalf4 vec4
#else
#define myhalf half
#define myhalf2 half2
#define myhalf3 half3
#define myhalf4 half4
#endif
varying vec4 ProjVector;
#ifdef VERTEX_SHADER
// Vertex shader
void main(void)
{
gl_FrontColor = gl_Color;
mat4 textureMatrix;
textureMatrix = gl_TextureMatrix[0];
gl_Position = ftransform();
ProjVector = textureMatrix * gl_Vertex;
}
#endif // VERTEX_SHADER
#ifdef FRAGMENT_SHADER
// Fragment shader
uniform myhalf3 LightAmbient;
uniform float TextureWidth, TextureHeight;
uniform float ProjDistance;
uniform sampler2DShadow ShadowmapTexture;
void main(void)
{
myhalf color = myhalf(1.0);
if (ProjVector.w <= 0.0 || ProjVector.w >= ProjDistance)
discard;
float dtW = 1.0 / TextureWidth;
float dtH = 1.0 / TextureHeight;
vec3 coord = vec3 (ProjVector.xyz / ProjVector.w);
coord = (coord + vec3 (1.0)) * vec3 (0.5);
coord.s = float (clamp (float(coord.s), dtW, 1.0 - dtW));
coord.t = float (clamp (float(coord.t), dtH, 1.0 - dtH));
coord.r = float (clamp (float(coord.r), 0.0, 1.0));
myhalf shadow0 = myhalf(shadow2D(ShadowmapTexture, coord).r);
myhalf shadow = shadow0;
#if defined(APPLY_PCF2x2) || defined(APPLY_PCF3x3)
vec3 coord2 = coord + vec3(0.0, dtH, 0.0);
myhalf shadow1 = myhalf (shadow2D (ShadowmapTexture, coord2).r);
coord2 = coord + vec3(dtW, dtH, 0.0);
myhalf shadow2 = myhalf (shadow2D (ShadowmapTexture, coord2).r);
coord2 = coord + vec3(dtW, 0.0, 0.0);
myhalf shadow3 = myhalf (shadow2D (ShadowmapTexture, coord2).r);
#if defined(APPLY_PCF3x3)
coord2 = coord + vec3(-dtW, 0.0, 0.0);
myhalf shadow4 = myhalf (shadow2D (ShadowmapTexture, coord2).r);
coord2 = coord + vec3(-dtW, -dtH, 0.0);
myhalf shadow5 = myhalf (shadow2D (ShadowmapTexture, coord2).r);
coord2 = coord + vec3(0.0, -dtH, 0.0);
myhalf shadow6 = myhalf (shadow2D (ShadowmapTexture, coord2).r);
coord2 = coord + vec3(dtW, -dtH, 0.0);
myhalf shadow7 = myhalf (shadow2D (ShadowmapTexture, coord2).r);
coord2 = coord + vec3(-dtW, dtH, 0.0);
myhalf shadow8 = myhalf (shadow2D (ShadowmapTexture, coord2).r);
shadow = (shadow0 + shadow1 + shadow2 + shadow3 + shadow4 + shadow5 + shadow6 + shadow7 + shadow8) * myhalf(0.11);
#else
shadow = (shadow0 + shadow1 + shadow2 + shadow3) * myhalf(0.25);
#endif
#else
shadow = shadow0;
#endif
float attenuation = float (ProjVector.w) / ProjDistance;
myhalf compensation = myhalf(0.25) - max(LightAmbient.x, max(LightAmbient.y, LightAmbient.z))
;compensation = max (compensation, 0.0);
color = shadow + attenuation + compensation;
gl_FragColor = vec4(vec3(color),1.0);
}
#endif // FRAGMENT_SHADER
|