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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
//! Maps a [`Shader`] variant to the WGSL preprocessor defines that select the
//! matching shader in `noesis.wgsl`.
use std::collections::HashSet;
use noesis_runtime::render_device::types::Shader;
/// Returns the WGSL define set for `shader`.
///
/// # Panics
///
/// Panics if `shader` has no `noesis.wgsl` variant yet; the message names the
/// missing one.
#[must_use]
#[allow(clippy::too_many_lines)] // one arm per shader variant, no abstraction buys clarity here
pub fn defines_for_shader(shader: Shader) -> HashSet<&'static str> {
let mut d: HashSet<&'static str> = HashSet::new();
match shader.0 {
n if n == Shader::RGBA.0 => {
d.insert("EFFECT_RGBA");
}
n if n == Shader::MASK.0 => {
d.insert("EFFECT_MASK");
}
n if n == Shader::CLEAR.0 => {
d.insert("EFFECT_CLEAR");
}
n if n == Shader::PATH_SOLID.0 => {
d.insert("HAS_COLOR");
d.insert("PAINT_SOLID");
d.insert("EFFECT_PATH");
}
n if n == Shader::PATH_AA_SOLID.0 => {
d.insert("HAS_COLOR");
d.insert("HAS_COVERAGE");
d.insert("PAINT_SOLID");
d.insert("EFFECT_PATH_AA");
}
// PAINT_PATTERN_PLAIN gates the no-wrap branch in noesis.wgsl; each
// CLAMP / REPEAT / MIRROR_{U,V} / MIRROR variant below gates its own
// block instead.
n if n == Shader::PATH_PATTERN.0 => {
d.insert("HAS_UV0");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_PATTERN");
d.insert("PAINT_PATTERN_PLAIN");
d.insert("EFFECT_PATH");
}
n if n == Shader::PATH_AA_PATTERN.0 => {
d.insert("HAS_UV0");
d.insert("HAS_COVERAGE");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_PATTERN");
d.insert("PAINT_PATTERN_PLAIN");
d.insert("EFFECT_PATH_AA");
}
// ─── Pattern wrap variants ─────────────────────────────────────────
// Vertex format differences (all mirror the SDK's FORMAT_FOR_VERTEX):
// CLAMP → PosTex0Rect (pos + uv0 + rect)
// REPEAT+MIRROR → PosTex0RectTile (pos + uv0 + rect + tile)
// The AA twins add coverage. `HAS_RECT` / `HAS_TILE` gate the
// matching VsIn attribute declarations.
n if n == Shader::PATH_PATTERN_CLAMP.0 => {
d.insert("HAS_UV0");
d.insert("HAS_RECT");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_PATTERN");
d.insert("CLAMP_PATTERN");
d.insert("EFFECT_PATH");
}
n if n == Shader::PATH_AA_PATTERN_CLAMP.0 => {
d.insert("HAS_UV0");
d.insert("HAS_COVERAGE");
d.insert("HAS_RECT");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_PATTERN");
d.insert("CLAMP_PATTERN");
d.insert("EFFECT_PATH_AA");
}
n if n == Shader::PATH_PATTERN_REPEAT.0 => {
d.insert("HAS_UV0");
d.insert("HAS_RECT");
d.insert("HAS_TILE");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_PATTERN");
d.insert("REPEAT_PATTERN");
d.insert("EFFECT_PATH");
}
n if n == Shader::PATH_AA_PATTERN_REPEAT.0 => {
d.insert("HAS_UV0");
d.insert("HAS_COVERAGE");
d.insert("HAS_RECT");
d.insert("HAS_TILE");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_PATTERN");
d.insert("REPEAT_PATTERN");
d.insert("EFFECT_PATH_AA");
}
n if n == Shader::PATH_PATTERN_MIRROR_U.0 => {
d.insert("HAS_UV0");
d.insert("HAS_RECT");
d.insert("HAS_TILE");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_PATTERN");
d.insert("MIRRORU_PATTERN");
d.insert("EFFECT_PATH");
}
n if n == Shader::PATH_AA_PATTERN_MIRROR_U.0 => {
d.insert("HAS_UV0");
d.insert("HAS_COVERAGE");
d.insert("HAS_RECT");
d.insert("HAS_TILE");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_PATTERN");
d.insert("MIRRORU_PATTERN");
d.insert("EFFECT_PATH_AA");
}
n if n == Shader::PATH_PATTERN_MIRROR_V.0 => {
d.insert("HAS_UV0");
d.insert("HAS_RECT");
d.insert("HAS_TILE");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_PATTERN");
d.insert("MIRRORV_PATTERN");
d.insert("EFFECT_PATH");
}
n if n == Shader::PATH_AA_PATTERN_MIRROR_V.0 => {
d.insert("HAS_UV0");
d.insert("HAS_COVERAGE");
d.insert("HAS_RECT");
d.insert("HAS_TILE");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_PATTERN");
d.insert("MIRRORV_PATTERN");
d.insert("EFFECT_PATH_AA");
}
n if n == Shader::PATH_PATTERN_MIRROR.0 => {
d.insert("HAS_UV0");
d.insert("HAS_RECT");
d.insert("HAS_TILE");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_PATTERN");
d.insert("MIRROR_PATTERN");
d.insert("EFFECT_PATH");
}
n if n == Shader::PATH_AA_PATTERN_MIRROR.0 => {
d.insert("HAS_UV0");
d.insert("HAS_COVERAGE");
d.insert("HAS_RECT");
d.insert("HAS_TILE");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_PATTERN");
d.insert("MIRROR_PATTERN");
d.insert("EFFECT_PATH_AA");
}
// PAINT_LINEAR samples the `ramps` gradient texture.
n if n == Shader::PATH_LINEAR.0 => {
d.insert("HAS_UV0");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_LINEAR");
d.insert("EFFECT_PATH");
}
n if n == Shader::PATH_AA_LINEAR.0 => {
d.insert("HAS_UV0");
d.insert("HAS_COVERAGE");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_LINEAR");
d.insert("EFFECT_PATH_AA");
}
// PAINT_RADIAL samples `ramps` at a computed radius.
n if n == Shader::PATH_RADIAL.0 => {
d.insert("HAS_UV0");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_RADIAL");
d.insert("EFFECT_PATH");
}
n if n == Shader::PATH_AA_RADIAL.0 => {
d.insert("HAS_UV0");
d.insert("HAS_COVERAGE");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_RADIAL");
d.insert("EFFECT_PATH_AA");
}
// SDF text. Vertex format PosColorTex1: pos (loc 0), color (loc 1), uv1 (loc 3).
// The "paint texture" at group(2) carries the glyph atlas rather than
// a pattern/ramp; the Rust side picks the right batch slot to bind.
n if n == Shader::SDF_SOLID.0 => {
d.insert("HAS_COLOR");
d.insert("HAS_UV1");
d.insert("HAS_ST1");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_SOLID");
d.insert("EFFECT_SDF");
}
// Subpixel text. Same vertex format as SDF_SOLID (PosColorTex1) and the same glyph
// atlas at group(2); the difference is a dual-source fragment output
// (`@blend_src(0)` / `@blend_src(1)`) carrying per-channel subpixel
// coverage, composited with the `SrcOver_Dual` blend mode. Requires
// the device's `DUAL_SOURCE_BLENDING` feature; Noesis only emits these
// when `DeviceCaps::subpixel_rendering` is set (see `caps()` notes).
n if n == Shader::SDF_LCD_SOLID.0 => {
d.insert("HAS_COLOR");
d.insert("HAS_UV1");
d.insert("HAS_ST1");
d.insert("HAS_PAINT_TEXTURE");
d.insert("PAINT_SOLID");
d.insert("EFFECT_SDF_LCD");
}
// GL ref Shader.140.frag EFFECT_OPACITY block:
// fragColor = texture(image, uv1) * (opacity_ * paint.a)
// `image` is the offscreen-rendered pass of the layer being
// composited; the paint side controls the per-pixel opacity
// multiplier via its alpha (and the global `opacity` scalar via
// its uniform). HAS_IMAGE_TEXTURE pulls in the second
// texture+sampler pair the WGSL declares at group(3); HAS_UV1
// carries the sample coords for that texture (location 3).
//
// Noesis emits these when a layer composites back through an Opacity
// animation, an opacity mask, or a focus-visual fade.
n if n == Shader::OPACITY_SOLID.0 => {
d.insert("HAS_COLOR");
d.insert("HAS_UV1");
d.insert("HAS_IMAGE_TEXTURE");
d.insert("PAINT_SOLID");
d.insert("EFFECT_OPACITY");
}
n if n == Shader::OPACITY_LINEAR.0 => {
d.insert("HAS_UV0");
d.insert("HAS_UV1");
d.insert("HAS_PAINT_TEXTURE");
d.insert("HAS_IMAGE_TEXTURE");
d.insert("PAINT_LINEAR");
d.insert("EFFECT_OPACITY");
}
n if n == Shader::OPACITY_RADIAL.0 => {
d.insert("HAS_UV0");
d.insert("HAS_UV1");
d.insert("HAS_PAINT_TEXTURE");
d.insert("HAS_IMAGE_TEXTURE");
d.insert("PAINT_RADIAL");
d.insert("EFFECT_OPACITY");
}
n if n == Shader::OPACITY_PATTERN.0 => {
d.insert("HAS_UV0");
d.insert("HAS_UV1");
d.insert("HAS_PAINT_TEXTURE");
d.insert("HAS_IMAGE_TEXTURE");
d.insert("PAINT_PATTERN_PLAIN");
d.insert("EFFECT_OPACITY");
}
n if n == Shader::OPACITY_PATTERN_CLAMP.0 => {
d.insert("HAS_UV0");
d.insert("HAS_UV1");
d.insert("HAS_RECT");
d.insert("HAS_PAINT_TEXTURE");
d.insert("HAS_IMAGE_TEXTURE");
d.insert("CLAMP_PATTERN");
d.insert("EFFECT_OPACITY");
}
n if n == Shader::OPACITY_PATTERN_REPEAT.0 => {
d.insert("HAS_UV0");
d.insert("HAS_UV1");
d.insert("HAS_RECT");
d.insert("HAS_TILE");
d.insert("HAS_PAINT_TEXTURE");
d.insert("HAS_IMAGE_TEXTURE");
d.insert("REPEAT_PATTERN");
d.insert("EFFECT_OPACITY");
}
n if n == Shader::OPACITY_PATTERN_MIRROR_U.0 => {
d.insert("HAS_UV0");
d.insert("HAS_UV1");
d.insert("HAS_RECT");
d.insert("HAS_TILE");
d.insert("HAS_PAINT_TEXTURE");
d.insert("HAS_IMAGE_TEXTURE");
d.insert("MIRRORU_PATTERN");
d.insert("EFFECT_OPACITY");
}
n if n == Shader::OPACITY_PATTERN_MIRROR_V.0 => {
d.insert("HAS_UV0");
d.insert("HAS_UV1");
d.insert("HAS_RECT");
d.insert("HAS_TILE");
d.insert("HAS_PAINT_TEXTURE");
d.insert("HAS_IMAGE_TEXTURE");
d.insert("MIRRORV_PATTERN");
d.insert("EFFECT_OPACITY");
}
n if n == Shader::OPACITY_PATTERN_MIRROR.0 => {
d.insert("HAS_UV0");
d.insert("HAS_UV1");
d.insert("HAS_RECT");
d.insert("HAS_TILE");
d.insert("HAS_PAINT_TEXTURE");
d.insert("HAS_IMAGE_TEXTURE");
d.insert("MIRROR_PATTERN");
d.insert("EFFECT_OPACITY");
}
// GL ref FSHADER(DOWNSAMPLE) / FSHADER(UPSAMPLE), no PAINT. These
// form the separable-blur resolve chain Noesis runs in the offscreen
// phase. DOWNSAMPLE box-filters four taps of `pattern` (group 2) at
// VS-computed UVs (vertex shader sets the DOWNSAMPLE flag to spread
// uv0 ± uv1 into uv0..uv3). UPSAMPLE blends the lower-res `image`
// (group 3) with the same-res `pattern` (group 2) by `color.a`.
n if n == Shader::DOWNSAMPLE.0 => {
d.insert("HAS_UV0");
d.insert("HAS_UV1");
d.insert("DOWNSAMPLE");
d.insert("HAS_PAINT_TEXTURE");
d.insert("EFFECT_DOWNSAMPLE");
}
n if n == Shader::UPSAMPLE.0 => {
d.insert("HAS_COLOR");
d.insert("HAS_UV0");
d.insert("HAS_UV1");
d.insert("HAS_PAINT_TEXTURE");
d.insert("HAS_IMAGE_TEXTURE");
d.insert("EFFECT_UPSAMPLE");
}
// Drop shadow. GL ref FSHADER2(SHADOW, SOLID). Vertex format PosColorTex1Rect:
// pos, color, uv1 (layer sample coords), rect (clamp bounds). Reads
// both the layer `image` (group 3 binding 0/1) and the blurred
// `shadow` (group 3 binding 2/3), plus cbuffer1_ps (group 1 binding 1)
// for shadow color / offset / blend factor.
n if n == Shader::SHADOW.0 => {
d.insert("HAS_COLOR");
d.insert("HAS_UV1");
d.insert("HAS_RECT");
d.insert("HAS_IMAGE_TEXTURE");
d.insert("HAS_SHADOW_TEXTURE");
d.insert("HAS_CBUFFER1_PS");
d.insert("PAINT_SOLID");
d.insert("EFFECT_SHADOW");
}
// Gaussian blur resolve. GL ref FSHADER2(BLUR, SOLID). Vertex format PosColorTex1:
// pos, color, uv1. Crossfades the layer `image` with the blurred
// `shadow` by cbuffer1_ps[0].
n if n == Shader::BLUR.0 => {
d.insert("HAS_COLOR");
d.insert("HAS_UV1");
d.insert("HAS_IMAGE_TEXTURE");
d.insert("HAS_SHADOW_TEXTURE");
d.insert("HAS_CBUFFER1_PS");
d.insert("PAINT_SOLID");
d.insert("EFFECT_BLUR");
}
other => panic!(
"Shader({other}) not yet ported to noesis.wgsl. \
CUSTOM_EFFECT (52) needs user pixel-shader compilation via \
Batch.pixelShader. Extend \
shader_defines::defines_for_shader and noesis.wgsl together."
),
}
d
}