/
shaders.dei
273 lines (248 loc) · 9.86 KB
/
shaders.dei
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# Doomsday's Core Set of Shaders
#
# In each "shader" block, there can be:
# - path: path to both the .vsh and .fsh files (omit extension:
# "shaders/test" => shaders/test.vsh, shaders/test.fsh)
# - path.vertex: path to the vertex shader file
# - path.fragment: path to the fragment shader file
# - vertex: source of the vertex shader
# - fragment: source of the fragment shader
group generic {
# Simple shader with untextured vertices. There is an additional constant
# color applied to all vertices. Uses a combined model-view-projection
# matrix.
shader color_ucolor {
vertex = "
uniform highp mat4 uMvpMatrix;
uniform highp vec4 uColor;
attribute highp vec4 aVertex;
attribute highp vec4 aColor;
varying highp vec4 vColor;
void main(void) {
gl_Position = uMvpMatrix * aVertex;
vColor = uColor * aColor;
}"
fragment = "
varying highp vec4 vColor;
void main(void) {
gl_FragColor = vColor;
}"
}
shader texture {
vertex = "
uniform highp mat4 uMvpMatrix;
attribute highp vec4 aVertex;
attribute highp vec2 aUV;
varying highp vec2 vUV;
void main(void) {
gl_Position = uMvpMatrix * aVertex;
vUV = aUV;
}"
fragment = "
uniform sampler2D uTex;
varying highp vec2 vUV;
void main(void) {
gl_FragColor = texture2D(uTex, vUV);
}"
}
group textured {
# Simple shader with one texture plus a color per vertex. Uses a
# combined model-view-projection matrix.
shader color {
vertex = "
uniform highp mat4 uMvpMatrix;
attribute highp vec4 aVertex;
attribute highp vec2 aUV;
attribute highp vec4 aColor;
varying highp vec2 vUV;
varying highp vec4 vColor;
void main(void) {
gl_Position = uMvpMatrix * aVertex;
vUV = aUV;
vColor = aColor;
}"
fragment = "
uniform sampler2D uTex;
varying highp vec2 vUV;
varying highp vec4 vColor;
void main(void) {
gl_FragColor = vColor * texture2D(uTex, vUV);
}"
}
# Simple shader with one texture plus a color per vertex. There is
# an additional constant color applied to all vertices. Uses a
# combined model-view-projection matrix.
shader color_ucolor {
vertex = "
uniform highp mat4 uMvpMatrix;
uniform highp vec4 uColor;
attribute highp vec4 aVertex;
attribute highp vec2 aUV;
attribute highp vec4 aColor;
varying highp vec2 vUV;
varying highp vec4 vColor;
void main(void) {
gl_Position = uMvpMatrix * aVertex;
vUV = aUV;
vColor = aColor * uColor;
}"
fragment = "
uniform sampler2D uTex;
varying highp vec2 vUV;
varying highp vec4 vColor;
void main(void) {
gl_FragColor = vColor * texture2D(uTex, vUV);
}"
}
}
}
group fx {
group blur {
shader horizontal {
path.vertex = "shaders/blur.vsh"
fragment = "
uniform sampler2D uTex;
uniform highp vec2 uBlurStep;
varying highp vec2 vUV;
varying highp vec4 vColor;
void main(void) {
highp vec4 sum = vec4(0.0);
sum += texture2D(uTex, vec2(vUV.s - 4.0 * uBlurStep.s, vUV.t)) * 0.05;
sum += texture2D(uTex, vec2(vUV.s - 3.0 * uBlurStep.s, vUV.t)) * 0.09;
sum += texture2D(uTex, vec2(vUV.s - 2.0 * uBlurStep.s, vUV.t)) * 0.123;
sum += texture2D(uTex, vec2(vUV.s - uBlurStep.s, vUV.t)) * 0.154;
sum += texture2D(uTex, vUV) * 0.165;
sum += texture2D(uTex, vec2(vUV.s + uBlurStep.s, vUV.t)) * 0.154;
sum += texture2D(uTex, vec2(vUV.s + 2.0 * uBlurStep.s, vUV.t)) * 0.123;
sum += texture2D(uTex, vec2(vUV.s + 3.0 * uBlurStep.s, vUV.t)) * 0.09;
sum += texture2D(uTex, vec2(vUV.s + 4.0 * uBlurStep.s, vUV.t)) * 0.05;
gl_FragColor = sum;
gl_FragColor.a = 1.0;
}"
}
shader vertical {
path.vertex = "shaders/blur.vsh"
fragment = "
uniform sampler2D uTex;
uniform highp vec2 uBlurStep;
varying highp vec2 vUV;
varying highp vec4 vColor;
void main(void) {
highp vec4 sum = vec4(0.0);
sum += texture2D(uTex, vec2(vUV.s, vUV.t - 4.0 * uBlurStep.t)) * 0.05;
sum += texture2D(uTex, vec2(vUV.s, vUV.t - 3.0 * uBlurStep.t)) * 0.09;
sum += texture2D(uTex, vec2(vUV.s, vUV.t - 2.0 * uBlurStep.t)) * 0.123;
sum += texture2D(uTex, vec2(vUV.s, vUV.t - uBlurStep.t )) * 0.154;
sum += texture2D(uTex, vUV) * 0.165;
sum += texture2D(uTex, vec2(vUV.s, vUV.t + uBlurStep.t )) * 0.154;
sum += texture2D(uTex, vec2(vUV.s, vUV.t + 2.0 * uBlurStep.t)) * 0.123;
sum += texture2D(uTex, vec2(vUV.s, vUV.t + 3.0 * uBlurStep.t)) * 0.09;
sum += texture2D(uTex, vec2(vUV.s, vUV.t + 4.0 * uBlurStep.t)) * 0.05;
gl_FragColor = sum * vColor;
}"
}
}
shader lensflares {
path.vertex = "shaders/lensflares.vsh"
path.fragment = "shaders/lensflares.fsh"
}
# Post-processing shaders need to have uFadeInOut (0..1) for
# fading the effect in/out.
group post {
shader monochrome {
vertex = "
uniform highp mat4 uMvpMatrix;
attribute highp vec4 aVertex;
attribute highp vec2 aUV;
varying highp vec2 vUV;
void main(void) {
gl_Position = uMvpMatrix * aVertex;
vUV = aUV;
}"
fragment = "
uniform sampler2D uTex;
uniform highp float uFadeInOut;
varying highp vec2 vUV;
void main(void) {
highp vec4 original = texture2D(uTex, vUV);
highp float intens =
(0.2125 * original.r) +
(0.7154 * original.g) +
(0.0721 * original.b);
gl_FragColor = vec4(vec3(intens), 1.0);
if(uFadeInOut < 1.0) {
gl_FragColor = mix(original, gl_FragColor, uFadeInOut);
}
}"
}
shader monochrome.inverted {
vertex = "
uniform highp mat4 uMvpMatrix;
attribute highp vec4 aVertex;
attribute highp vec2 aUV;
varying highp vec2 vUV;
void main(void) {
gl_Position = uMvpMatrix * aVertex;
vUV = aUV;
}"
fragment = "
uniform sampler2D uTex;
uniform highp float uFadeInOut;
varying highp vec2 vUV;
void main(void) {
highp vec4 original = texture2D(uTex, vUV);
highp float intens =
(0.2125 * original.r) +
(0.7154 * original.g) +
(0.0721 * original.b);
gl_FragColor = vec4(vec3(1.0 - intens), 1.0);
if(uFadeInOut < 1.0) {
gl_FragColor = mix(original, gl_FragColor, uFadeInOut);
}
}"
}
}
}
group vr {
group oculusrift {
shader barrel {
vertex = "
#version 120
attribute highp vec4 aVertex;
attribute highp vec2 aUV;
varying highp vec2 vTexCoord;
void main() {
gl_Position = aVertex;
vTexCoord = aUV;
}"
path.fragment = "shaders/oculusrift-barrel.fsh"
}
}
}
group debug {
group textured {
# Visualize alpha information.
shader alpha {
vertex = "
uniform highp mat4 uMvpMatrix;
attribute highp vec4 aVertex;
attribute highp vec2 aUV;
attribute highp vec4 aColor;
varying highp vec2 vUV;
varying highp vec4 vColor;
void main(void) {
gl_Position = uMvpMatrix * aVertex;
vUV = aUV;
vColor = aColor;
}"
fragment = "
uniform sampler2D uTex;
varying highp vec2 vUV;
varying highp vec4 vColor;
void main(void) {
highp vec4 col = vColor * texture2D(uTex, vUV);
gl_FragColor = vec4(col.a, col.a, col.a, 1.0);
}"
}
}
}