@luma.gl/effects 9.3.0-alpha.6 → 9.3.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dist/dist.dev.js +983 -223
  2. package/dist/dist.min.js +5 -5
  3. package/dist/index.cjs +340 -50
  4. package/dist/index.cjs.map +3 -3
  5. package/dist/passes/postprocessing/fxaa/fxaa.d.ts +1 -0
  6. package/dist/passes/postprocessing/fxaa/fxaa.d.ts.map +1 -1
  7. package/dist/passes/postprocessing/fxaa/fxaa.js +287 -0
  8. package/dist/passes/postprocessing/fxaa/fxaa.js.map +1 -1
  9. package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.d.ts +1 -1
  10. package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.d.ts.map +1 -1
  11. package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.js +5 -7
  12. package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.js.map +1 -1
  13. package/dist/passes/postprocessing/image-adjust-filters/denoise.d.ts +2 -2
  14. package/dist/passes/postprocessing/image-adjust-filters/denoise.js +4 -4
  15. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts +1 -1
  16. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts.map +1 -1
  17. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.js +9 -10
  18. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.js.map +1 -1
  19. package/dist/passes/postprocessing/image-adjust-filters/noise.d.ts +1 -1
  20. package/dist/passes/postprocessing/image-adjust-filters/noise.js +1 -1
  21. package/dist/passes/postprocessing/image-adjust-filters/sepia.d.ts +1 -1
  22. package/dist/passes/postprocessing/image-adjust-filters/sepia.js +1 -1
  23. package/dist/passes/postprocessing/image-adjust-filters/vibrance.d.ts +1 -1
  24. package/dist/passes/postprocessing/image-adjust-filters/vibrance.d.ts.map +1 -1
  25. package/dist/passes/postprocessing/image-adjust-filters/vibrance.js +3 -4
  26. package/dist/passes/postprocessing/image-adjust-filters/vibrance.js.map +1 -1
  27. package/dist/passes/postprocessing/image-adjust-filters/vignette.d.ts +1 -1
  28. package/dist/passes/postprocessing/image-adjust-filters/vignette.js +1 -1
  29. package/dist/passes/postprocessing/image-blur-filters/tiltshift.d.ts +1 -1
  30. package/dist/passes/postprocessing/image-blur-filters/tiltshift.js +1 -1
  31. package/dist/passes/postprocessing/image-blur-filters/triangleblur.d.ts +1 -1
  32. package/dist/passes/postprocessing/image-blur-filters/triangleblur.js +6 -6
  33. package/dist/passes/postprocessing/image-blur-filters/zoomblur.d.ts +1 -1
  34. package/dist/passes/postprocessing/image-blur-filters/zoomblur.js +1 -1
  35. package/dist/passes/postprocessing/image-fun-filters/colorhalftone.d.ts +1 -1
  36. package/dist/passes/postprocessing/image-fun-filters/colorhalftone.js +1 -1
  37. package/dist/passes/postprocessing/image-fun-filters/dotscreen.d.ts +1 -1
  38. package/dist/passes/postprocessing/image-fun-filters/dotscreen.js +1 -1
  39. package/dist/passes/postprocessing/image-fun-filters/edgework.d.ts +1 -1
  40. package/dist/passes/postprocessing/image-fun-filters/edgework.js +1 -1
  41. package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.d.ts +1 -1
  42. package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.js +1 -1
  43. package/dist/passes/postprocessing/image-fun-filters/ink.d.ts +1 -1
  44. package/dist/passes/postprocessing/image-fun-filters/ink.js +1 -1
  45. package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts +1 -1
  46. package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts.map +1 -1
  47. package/dist/passes/postprocessing/image-fun-filters/magnify.js +8 -3
  48. package/dist/passes/postprocessing/image-fun-filters/magnify.js.map +1 -1
  49. package/dist/passes/postprocessing/image-warp-filters/bulgepinch.d.ts +2 -2
  50. package/dist/passes/postprocessing/image-warp-filters/bulgepinch.js +3 -3
  51. package/dist/passes/postprocessing/image-warp-filters/swirl.d.ts +2 -2
  52. package/dist/passes/postprocessing/image-warp-filters/swirl.js +3 -3
  53. package/package.json +3 -3
  54. package/src/passes/postprocessing/fxaa/fxaa.ts +288 -0
  55. package/src/passes/postprocessing/image-adjust-filters/brightnesscontrast.ts +5 -7
  56. package/src/passes/postprocessing/image-adjust-filters/denoise.ts +4 -4
  57. package/src/passes/postprocessing/image-adjust-filters/huesaturation.ts +9 -10
  58. package/src/passes/postprocessing/image-adjust-filters/noise.ts +1 -1
  59. package/src/passes/postprocessing/image-adjust-filters/sepia.ts +1 -1
  60. package/src/passes/postprocessing/image-adjust-filters/vibrance.ts +3 -4
  61. package/src/passes/postprocessing/image-adjust-filters/vignette.ts +1 -1
  62. package/src/passes/postprocessing/image-blur-filters/tiltshift.ts +1 -1
  63. package/src/passes/postprocessing/image-blur-filters/triangleblur.ts +6 -6
  64. package/src/passes/postprocessing/image-blur-filters/zoomblur.ts +1 -1
  65. package/src/passes/postprocessing/image-fun-filters/colorhalftone.ts +1 -1
  66. package/src/passes/postprocessing/image-fun-filters/dotscreen.ts +1 -1
  67. package/src/passes/postprocessing/image-fun-filters/edgework.ts +1 -1
  68. package/src/passes/postprocessing/image-fun-filters/hexagonalpixelate.ts +1 -1
  69. package/src/passes/postprocessing/image-fun-filters/ink.ts +1 -1
  70. package/src/passes/postprocessing/image-fun-filters/magnify.ts +8 -3
  71. package/src/passes/postprocessing/image-warp-filters/bulgepinch.ts +3 -3
  72. package/src/passes/postprocessing/image-warp-filters/swirl.ts +3 -3
@@ -97,6 +97,293 @@ import type {ShaderPass} from '@luma.gl/shadertools';
97
97
  // _ = the highest digit is directly related to style
98
98
  //
99
99
 
100
+ const source = /* wgsl */ `\
101
+ fn fxaaSat(value: f32) -> f32 {
102
+ return clamp(value, 0.0, 1.0);
103
+ }
104
+
105
+ fn fxaaTexTop(
106
+ sourceTexture: texture_2d<f32>,
107
+ sourceTextureSampler: sampler,
108
+ texCoord: vec2f
109
+ ) -> vec4f {
110
+ return textureSampleLevel(sourceTexture, sourceTextureSampler, texCoord, 0.0);
111
+ }
112
+
113
+ fn fxaaTexOff(
114
+ sourceTexture: texture_2d<f32>,
115
+ sourceTextureSampler: sampler,
116
+ texCoord: vec2f,
117
+ offset: vec2f,
118
+ reciprocalFrame: vec2f
119
+ ) -> vec4f {
120
+ return textureSampleLevel(
121
+ sourceTexture,
122
+ sourceTextureSampler,
123
+ texCoord + offset * reciprocalFrame,
124
+ 0.0
125
+ );
126
+ }
127
+
128
+ fn fxaaLuma(color: vec4f) -> f32 {
129
+ return dot(color.rgb, vec3f(0.2126, 0.7152, 0.0722));
130
+ }
131
+
132
+ fn fxaaGetQualityStep(stepIndex: u32) -> f32 {
133
+ switch (stepIndex) {
134
+ case 0u: {
135
+ return 1.0;
136
+ }
137
+ case 1u: {
138
+ return 1.5;
139
+ }
140
+ case 2u: {
141
+ return 2.0;
142
+ }
143
+ case 3u: {
144
+ return 2.0;
145
+ }
146
+ case 4u: {
147
+ return 2.0;
148
+ }
149
+ case 5u: {
150
+ return 2.0;
151
+ }
152
+ case 6u: {
153
+ return 2.0;
154
+ }
155
+ case 7u: {
156
+ return 2.0;
157
+ }
158
+ case 8u: {
159
+ return 2.0;
160
+ }
161
+ case 9u: {
162
+ return 2.0;
163
+ }
164
+ case 10u: {
165
+ return 4.0;
166
+ }
167
+ default: {
168
+ return 8.0;
169
+ }
170
+ }
171
+ }
172
+
173
+ fn fxaaPixelShader(
174
+ texCoord: vec2f,
175
+ sourceTexture: texture_2d<f32>,
176
+ sourceTextureSampler: sampler,
177
+ reciprocalFrame: vec2f,
178
+ qualitySubpix: f32,
179
+ qualityEdgeThreshold: f32,
180
+ qualityEdgeThresholdMin: f32
181
+ ) -> vec4f {
182
+ var posM = texCoord;
183
+ let rgbyM = fxaaTexTop(sourceTexture, sourceTextureSampler, posM);
184
+ let lumaM = rgbyM.g;
185
+ var lumaS = fxaaLuma(
186
+ fxaaTexOff(sourceTexture, sourceTextureSampler, posM, vec2f(0.0, 1.0), reciprocalFrame)
187
+ );
188
+ let lumaE = fxaaLuma(
189
+ fxaaTexOff(sourceTexture, sourceTextureSampler, posM, vec2f(1.0, 0.0), reciprocalFrame)
190
+ );
191
+ var lumaN = fxaaLuma(
192
+ fxaaTexOff(sourceTexture, sourceTextureSampler, posM, vec2f(0.0, -1.0), reciprocalFrame)
193
+ );
194
+ let lumaW = fxaaLuma(
195
+ fxaaTexOff(sourceTexture, sourceTextureSampler, posM, vec2f(-1.0, 0.0), reciprocalFrame)
196
+ );
197
+
198
+ let maxSM = max(lumaS, lumaM);
199
+ let minSM = min(lumaS, lumaM);
200
+ let maxESM = max(lumaE, maxSM);
201
+ let minESM = min(lumaE, minSM);
202
+ let maxWN = max(lumaN, lumaW);
203
+ let minWN = min(lumaN, lumaW);
204
+ let rangeMax = max(maxWN, maxESM);
205
+ let rangeMin = min(minWN, minESM);
206
+ let rangeMaxScaled = rangeMax * qualityEdgeThreshold;
207
+ let range = rangeMax - rangeMin;
208
+ let rangeMaxClamped = max(qualityEdgeThresholdMin, rangeMaxScaled);
209
+ if (range < rangeMaxClamped) {
210
+ return rgbyM;
211
+ }
212
+
213
+ let lumaNW = fxaaLuma(
214
+ fxaaTexOff(sourceTexture, sourceTextureSampler, posM, vec2f(-1.0, -1.0), reciprocalFrame)
215
+ );
216
+ let lumaSE = fxaaLuma(
217
+ fxaaTexOff(sourceTexture, sourceTextureSampler, posM, vec2f(1.0, 1.0), reciprocalFrame)
218
+ );
219
+ let lumaNE = fxaaLuma(
220
+ fxaaTexOff(sourceTexture, sourceTextureSampler, posM, vec2f(1.0, -1.0), reciprocalFrame)
221
+ );
222
+ let lumaSW = fxaaLuma(
223
+ fxaaTexOff(sourceTexture, sourceTextureSampler, posM, vec2f(-1.0, 1.0), reciprocalFrame)
224
+ );
225
+
226
+ let lumaNS = lumaN + lumaS;
227
+ let lumaWE = lumaW + lumaE;
228
+ let subpixReciprocalRange = 1.0 / range;
229
+ let subpixNSWE = lumaNS + lumaWE;
230
+ let edgeHorizontal1 = -2.0 * lumaM + lumaNS;
231
+ let edgeVertical1 = -2.0 * lumaM + lumaWE;
232
+
233
+ let lumaNESE = lumaNE + lumaSE;
234
+ let lumaNWNE = lumaNW + lumaNE;
235
+ let edgeHorizontal2 = -2.0 * lumaE + lumaNESE;
236
+ let edgeVertical2 = -2.0 * lumaN + lumaNWNE;
237
+
238
+ let lumaNWSW = lumaNW + lumaSW;
239
+ let lumaSWSE = lumaSW + lumaSE;
240
+ let edgeHorizontal4 = abs(edgeHorizontal1) * 2.0 + abs(edgeHorizontal2);
241
+ let edgeVertical4 = abs(edgeVertical1) * 2.0 + abs(edgeVertical2);
242
+ let edgeHorizontal3 = -2.0 * lumaW + lumaNWSW;
243
+ let edgeVertical3 = -2.0 * lumaS + lumaSWSE;
244
+ let edgeHorizontal = abs(edgeHorizontal3) + edgeHorizontal4;
245
+ let edgeVertical = abs(edgeVertical3) + edgeVertical4;
246
+
247
+ let subpixNWSWNESE = lumaNWSW + lumaNESE;
248
+ let horizontalSpan = edgeHorizontal >= edgeVertical;
249
+ var lengthSign = reciprocalFrame.x;
250
+ let subpixA = subpixNSWE * 2.0 + subpixNWSWNESE;
251
+ if (!horizontalSpan) {
252
+ lumaN = lumaW;
253
+ lumaS = lumaE;
254
+ }
255
+ if (horizontalSpan) {
256
+ lengthSign = reciprocalFrame.y;
257
+ }
258
+ let subpixB = subpixA * (1.0 / 12.0) - lumaM;
259
+
260
+ let gradientN = lumaN - lumaM;
261
+ let gradientS = lumaS - lumaM;
262
+ var lumaNN = lumaN + lumaM;
263
+ let lumaSS = lumaS + lumaM;
264
+ let pairN = abs(gradientN) >= abs(gradientS);
265
+ let gradient = max(abs(gradientN), abs(gradientS));
266
+ if (pairN) {
267
+ lengthSign = -lengthSign;
268
+ }
269
+ let subpixC = fxaaSat(abs(subpixB) * subpixReciprocalRange);
270
+
271
+ var posB = posM;
272
+ var offNP = vec2f(0.0);
273
+ if (horizontalSpan) {
274
+ offNP = vec2f(reciprocalFrame.x, 0.0);
275
+ posB.y += lengthSign * 0.5;
276
+ } else {
277
+ offNP = vec2f(0.0, reciprocalFrame.y);
278
+ posB.x += lengthSign * 0.5;
279
+ }
280
+
281
+ var posN = posB - offNP * fxaaGetQualityStep(0u);
282
+ var posP = posB + offNP * fxaaGetQualityStep(0u);
283
+ let subpixD = -2.0 * subpixC + 3.0;
284
+ var lumaEndN = fxaaLuma(fxaaTexTop(sourceTexture, sourceTextureSampler, posN));
285
+ let subpixE = subpixC * subpixC;
286
+ var lumaEndP = fxaaLuma(fxaaTexTop(sourceTexture, sourceTextureSampler, posP));
287
+
288
+ if (!pairN) {
289
+ lumaNN = lumaSS;
290
+ }
291
+ let gradientScaled = gradient * 0.25;
292
+ let lumaMM = lumaM - lumaNN * 0.5;
293
+ let subpixF = subpixD * subpixE;
294
+ let lumaMoreThanZero = lumaMM < 0.0;
295
+
296
+ lumaEndN -= lumaNN * 0.5;
297
+ lumaEndP -= lumaNN * 0.5;
298
+ var doneN = abs(lumaEndN) >= gradientScaled;
299
+ var doneP = abs(lumaEndP) >= gradientScaled;
300
+ var doneNP = !doneN || !doneP;
301
+ var qualityStepIndex = 1u;
302
+ loop {
303
+ if (!(doneNP && qualityStepIndex < 12u)) {
304
+ break;
305
+ }
306
+
307
+ let qualityStep = fxaaGetQualityStep(qualityStepIndex);
308
+ if (!doneN) {
309
+ posN -= offNP * qualityStep;
310
+ }
311
+ if (!doneP) {
312
+ posP += offNP * qualityStep;
313
+ }
314
+
315
+ qualityStepIndex += 1u;
316
+ if (qualityStepIndex >= 12u) {
317
+ break;
318
+ }
319
+
320
+ if (!doneN) {
321
+ lumaEndN = fxaaLuma(fxaaTexTop(sourceTexture, sourceTextureSampler, posN));
322
+ lumaEndN -= lumaNN * 0.5;
323
+ doneN = abs(lumaEndN) >= gradientScaled;
324
+ }
325
+ if (!doneP) {
326
+ lumaEndP = fxaaLuma(fxaaTexTop(sourceTexture, sourceTextureSampler, posP));
327
+ lumaEndP -= lumaNN * 0.5;
328
+ doneP = abs(lumaEndP) >= gradientScaled;
329
+ }
330
+
331
+ doneNP = !doneN || !doneP;
332
+ }
333
+
334
+ var dstN = posM.x - posN.x;
335
+ var dstP = posP.x - posM.x;
336
+ if (!horizontalSpan) {
337
+ dstN = posM.y - posN.y;
338
+ dstP = posP.y - posM.y;
339
+ }
340
+
341
+ let goodSpanN = (lumaEndN < 0.0) != lumaMoreThanZero;
342
+ let spanLength = dstP + dstN;
343
+ let goodSpanP = (lumaEndP < 0.0) != lumaMoreThanZero;
344
+ let spanLengthReciprocal = 1.0 / spanLength;
345
+
346
+ let directionN = dstN < dstP;
347
+ let dst = min(dstN, dstP);
348
+ let goodSpan = select(goodSpanP, goodSpanN, directionN);
349
+ let subpixG = subpixF * subpixF;
350
+ let pixelOffset = dst * -spanLengthReciprocal + 0.5;
351
+ let subpixH = subpixG * qualitySubpix;
352
+
353
+ let pixelOffsetGood = select(0.0, pixelOffset, goodSpan);
354
+ let pixelOffsetSubpix = max(pixelOffsetGood, subpixH);
355
+ if (!horizontalSpan) {
356
+ posM.x += pixelOffsetSubpix * lengthSign;
357
+ }
358
+ if (horizontalSpan) {
359
+ posM.y += pixelOffsetSubpix * lengthSign;
360
+ }
361
+
362
+ return fxaaTexTop(sourceTexture, sourceTextureSampler, posM);
363
+ }
364
+
365
+ fn fxaa_sampleColor(
366
+ sourceTexture: texture_2d<f32>,
367
+ sourceTextureSampler: sampler,
368
+ texSize: vec2f,
369
+ texCoord: vec2f
370
+ ) -> vec4f {
371
+ let qualitySubpix = 0.5;
372
+ let qualityEdgeThreshold = 0.125;
373
+ let qualityEdgeThresholdMin = 0.0833;
374
+
375
+ return fxaaPixelShader(
376
+ texCoord,
377
+ sourceTexture,
378
+ sourceTextureSampler,
379
+ vec2f(1.0) / texSize,
380
+ qualitySubpix,
381
+ qualityEdgeThreshold,
382
+ qualityEdgeThresholdMin
383
+ );
384
+ }
385
+ `;
386
+
100
387
  const fs = /* glsl */ `
101
388
  #define FXAA_QUALITY_PRESET 29
102
389
 
@@ -688,6 +975,7 @@ export type FXAAUniforms = {};
688
975
  export const fxaa = {
689
976
  name: 'fxaa',
690
977
  propTypes: {},
978
+ source,
691
979
  fs,
692
980
  passes: [{sampler: true}],
693
981
  getUniforms: props => props
@@ -10,18 +10,16 @@ struct brightnessContrastUniforms {
10
10
  contrast: f32
11
11
  };
12
12
 
13
- // Binding 0:1 is reserved for shader passes
14
- @group(0) @binding(1) var<uniform> brightnessContrast : brightnessContrastUniforms;
13
+ @group(0) @binding(auto) var<uniform> brightnessContrast : brightnessContrastUniforms;
15
14
 
16
15
  fn brightnessContrast_filterColor_ext(color: vec4f, texSize: vec2<f32>, texCoords: vec2<f32>) -> vec4f {
17
- var result = color;
18
- result.rgb += vec3f(brightnessContrast.brightness);
16
+ var resultRgb = color.rgb + vec3f(brightnessContrast.brightness);
19
17
  if (brightnessContrast.contrast > 0.0) {
20
- result.rgb = (result.rgb - vec3f(0.5)) / (1.0 - brightnessContrast.contrast) + vec3f(0.5);
18
+ resultRgb = (resultRgb - vec3f(0.5)) / (1.0 - brightnessContrast.contrast) + vec3f(0.5);
21
19
  } else {
22
- result.rgb = (result.rgb - vec3f(0.5)) * (1.0 + brightnessContrast.contrast) + vec3f(0.5);
20
+ resultRgb = (resultRgb - vec3f(0.5)) * (1.0 + brightnessContrast.contrast) + vec3f(0.5);
23
21
  }
24
- return result;
22
+ return vec4f(resultRgb, color.a);
25
23
  }
26
24
  `;
27
25
 
@@ -10,7 +10,7 @@ struct denoiseUniforms {
10
10
  strength: f32,
11
11
  };
12
12
 
13
- @group(0) @binding(1) var<uniform> denoise: denoiseUniforms;
13
+ @group(0) @binding(auto) var<uniform> denoise: denoiseUniforms;
14
14
 
15
15
  fn denoise_sampleColor(
16
16
  sourceTexture: texture_2d<f32>,
@@ -44,12 +44,12 @@ fn denoise_sampleColor(
44
44
  `;
45
45
 
46
46
  const fs = /* glsl */ `\
47
- uniform dedenoiseUniforms {
47
+ uniform denoiseUniforms {
48
48
  float strength;
49
49
  } denoise;
50
50
 
51
- vec4 dedenoise_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
52
- float adjustedExponent = 3. + 200. * pow(1. - noise.strength, 4.);
51
+ vec4 denoise_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
52
+ float adjustedExponent = 3. + 200. * pow(1. - denoise.strength, 4.);
53
53
 
54
54
  vec4 center = texture(source, texCoord);
55
55
  vec4 color = vec4(0.0);
@@ -10,7 +10,7 @@ struct hueSaturationUniforms {
10
10
  saturation: f32,
11
11
  };
12
12
 
13
- @group(0) @binding(1) var<uniform> hueSaturation: hueSaturationUniforms;
13
+ @group(0) @binding(auto) var<uniform> hueSaturation: hueSaturationUniforms;
14
14
 
15
15
  fn hueSaturation_filterColor(color: vec4f) -> vec4f {
16
16
  let angle = hueSaturation.hue * 3.14159265;
@@ -18,21 +18,20 @@ fn hueSaturation_filterColor(color: vec4f) -> vec4f {
18
18
  let c = cos(angle);
19
19
  let weights = (vec3f(2.0 * c, -sqrt(3.0) * s - c, sqrt(3.0) * s - c) + vec3f(1.0)) / 3.0;
20
20
 
21
- var result = color;
22
- result.rgb = vec3f(
23
- dot(result.rgb, weights.xyz),
24
- dot(result.rgb, weights.zxy),
25
- dot(result.rgb, weights.yzx)
21
+ var resultRgb = vec3f(
22
+ dot(color.rgb, weights.xyz),
23
+ dot(color.rgb, weights.zxy),
24
+ dot(color.rgb, weights.yzx)
26
25
  );
27
26
 
28
- let average = (result.r + result.g + result.b) / 3.0;
27
+ let average = (resultRgb.r + resultRgb.g + resultRgb.b) / 3.0;
29
28
  if (hueSaturation.saturation > 0.0) {
30
- result.rgb += (vec3f(average) - result.rgb) * (1.0 - 1.0 / (1.001 - hueSaturation.saturation));
29
+ resultRgb += (vec3f(average) - resultRgb) * (1.0 - 1.0 / (1.001 - hueSaturation.saturation));
31
30
  } else {
32
- result.rgb += (vec3f(average) - result.rgb) * (-hueSaturation.saturation);
31
+ resultRgb += (vec3f(average) - resultRgb) * (-hueSaturation.saturation);
33
32
  }
34
33
 
35
- return result;
34
+ return vec4f(resultRgb, color.a);
36
35
  }
37
36
 
38
37
  fn hueSaturation_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) -> vec4f {
@@ -9,7 +9,7 @@ struct noiseUniforms {
9
9
  amount: f32,
10
10
  };
11
11
 
12
- @group(0) @binding(1) var<uniform> noise: noiseUniforms;
12
+ @group(0) @binding(auto) var<uniform> noise: noiseUniforms;
13
13
 
14
14
  fn rand(co: vec2f) -> f32 {
15
15
  return fract(sin(dot(co.xy, vec2f(12.9898, 78.233))) * 43758.547);
@@ -9,7 +9,7 @@ struct sepiaUniforms {
9
9
  amount: f32,
10
10
  };
11
11
 
12
- @group(0) @binding(1) var<uniform> sepia: sepiaUniforms;
12
+ @group(0) @binding(auto) var<uniform> sepia: sepiaUniforms;
13
13
 
14
14
  fn sepia_filterColor(color: vec4f) -> vec4f {
15
15
  let r = color.r;
@@ -9,15 +9,14 @@ struct vibranceUniforms {
9
9
  amount: f32,
10
10
  };
11
11
 
12
- @group(0) @binding(1) var<uniform> vibrance: vibranceUniforms;
12
+ @group(0) @binding(auto) var<uniform> vibrance: vibranceUniforms;
13
13
 
14
14
  fn vibrance_filterColor(color: vec4f) -> vec4f {
15
15
  let average = (color.r + color.g + color.b) / 3.0;
16
16
  let mx = max(color.r, max(color.g, color.b));
17
17
  let amt = (mx - average) * (-vibrance.amount * 3.0);
18
- var result = color;
19
- result.rgb = mix(result.rgb, vec3f(mx), amt);
20
- return result;
18
+ let resultRgb = mix(color.rgb, vec3f(mx), amt);
19
+ return vec4f(resultRgb, color.a);
21
20
  }
22
21
 
23
22
  fn vibrance_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) -> vec4f {
@@ -10,7 +10,7 @@ struct vignetteUniforms {
10
10
  amount: f32,
11
11
  };
12
12
 
13
- @group(0) @binding(1) var<uniform> vignette: vignetteUniforms;
13
+ @group(0) @binding(auto) var<uniform> vignette: vignetteUniforms;
14
14
 
15
15
  fn vignette_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) -> vec4f {
16
16
  let dist = distance(texCoord, vec2f(0.5, 0.5));
@@ -14,7 +14,7 @@ struct tiltShiftUniforms {
14
14
  invert: u32,
15
15
  };
16
16
 
17
- @group(0) @binding(1) var<uniform> tiltShift: tiltShiftUniforms;
17
+ @group(0) @binding(auto) var<uniform> tiltShift: tiltShiftUniforms;
18
18
 
19
19
  fn tiltShift_getDelta(texSize: vec2f) -> vec2f {
20
20
  let vector = normalize((tiltShift.end - tiltShift.start) * texSize);
@@ -11,7 +11,7 @@ struct triangleBlurUniforms {
11
11
  delta: vec2f,
12
12
  };
13
13
 
14
- @group(0) @binding(1) var<uniform> triangleBlur: triangleBlurUniforms;
14
+ @group(0) @binding(auto) var<uniform> triangleBlur: triangleBlurUniforms;
15
15
 
16
16
  fn triangleBlur_sampleColor(
17
17
  sourceTexture: texture_2d<f32>,
@@ -30,25 +30,25 @@ fn triangleBlur_sampleColor(
30
30
  for (var t = -30.0; t <= 30.0; t += 1.0) {
31
31
  let percent = (t + offset - 0.5) / 30.0;
32
32
  let weight = 1.0 - abs(percent);
33
- var offsetColor = textureSample(
33
+ let offsetColor = textureSample(
34
34
  sourceTexture,
35
35
  sourceTextureSampler,
36
36
  texCoord + adjustedDelta * percent
37
37
  );
38
38
 
39
39
  /* switch to pre-multiplied alpha to correctly blur transparent images */
40
- offsetColor.rgb *= offsetColor.a;
40
+ let premultipliedOffsetColor = vec4f(offsetColor.rgb * vec3f(offsetColor.a), offsetColor.a);
41
41
 
42
- color += offsetColor * weight;
42
+ color += premultipliedOffsetColor * weight;
43
43
  total += weight;
44
44
  }
45
45
 
46
46
  color /= total;
47
47
 
48
48
  /* switch back from pre-multiplied alpha */
49
- color.rgb /= color.a + 0.00001;
49
+ let unpremultipliedRgb = color.rgb / vec3f(color.a + 0.00001);
50
50
 
51
- return color;
51
+ return vec4f(unpremultipliedRgb, color.a);
52
52
  }
53
53
  `;
54
54
 
@@ -11,7 +11,7 @@ struct zoomBlurUniforms {
11
11
  strength: f32,
12
12
  };
13
13
 
14
- @group(0) @binding(1) var<uniform> zoomBlur : zoomBlurUniforms;
14
+ @group(0) @binding(auto) var<uniform> zoomBlur : zoomBlurUniforms;
15
15
 
16
16
 
17
17
  fn zoomBlur_sampleColor(
@@ -11,7 +11,7 @@ struct colorHalftoneUniforms {
11
11
  size: f32,
12
12
  };
13
13
 
14
- @group(0) @binding(1) var<uniform> colorHalftone: colorHalftoneUniforms;
14
+ @group(0) @binding(auto) var<uniform> colorHalftone: colorHalftoneUniforms;
15
15
 
16
16
  fn pattern(angle: f32, scale: f32, texSize: vec2f, texCoord: vec2f) -> f32 {
17
17
  let s = sin(angle);
@@ -11,7 +11,7 @@ struct dotScreenUniforms {
11
11
  size: f32,
12
12
  };
13
13
 
14
- @group(0) @binding(1) var<uniform> dotScreen: dotScreenUniforms;
14
+ @group(0) @binding(auto) var<uniform> dotScreen: dotScreenUniforms;
15
15
 
16
16
  fn pattern(texSize: vec2f, texCoord: vec2f) -> f32 {
17
17
  let scale = 3.1415 / dotScreen.size;
@@ -11,7 +11,7 @@ struct edgeWorkUniforms {
11
11
  mode: u32,
12
12
  };
13
13
 
14
- @group(0) @binding(1) var<uniform> edgeWork: edgeWorkUniforms;
14
+ @group(0) @binding(auto) var<uniform> edgeWork: edgeWorkUniforms;
15
15
 
16
16
  fn edgeWork_sampleColorRGB(
17
17
  sourceTexture: texture_2d<f32>,
@@ -10,7 +10,7 @@ struct hexagonalPixelateUniforms {
10
10
  scale: f32,
11
11
  };
12
12
 
13
- @group(0) @binding(1) var<uniform> hexagonalPixelate: hexagonalPixelateUniforms;
13
+ @group(0) @binding(auto) var<uniform> hexagonalPixelate: hexagonalPixelateUniforms;
14
14
 
15
15
  fn hexagonalPixelate_sampleColor(
16
16
  sourceTexture: texture_2d<f32>,
@@ -9,7 +9,7 @@ struct inkUniforms {
9
9
  strength: f32,
10
10
  };
11
11
 
12
- @group(0) @binding(1) var<uniform> ink: inkUniforms;
12
+ @group(0) @binding(auto) var<uniform> ink: inkUniforms;
13
13
 
14
14
  fn ink_sampleColor(
15
15
  sourceTexture: texture_2d<f32>,
@@ -13,7 +13,7 @@ struct magnifyUniforms {
13
13
  borderColor: vec4f,
14
14
  };
15
15
 
16
- @group(0) @binding(1) var<uniform> magnify: magnifyUniforms;
16
+ @group(0) @binding(auto) var<uniform> magnify: magnifyUniforms;
17
17
 
18
18
  fn magnify_sampleColor(
19
19
  sourceTexture: texture_2d<f32>,
@@ -24,13 +24,18 @@ fn magnify_sampleColor(
24
24
  let pos = vec2f(magnify.screenXY.x, 1.0 - magnify.screenXY.y);
25
25
  let dist = distance(texCoord * texSize, pos * texSize);
26
26
  if (dist < magnify.radiusPixels) {
27
- return textureSample(sourceTexture, sourceTextureSampler, (texCoord - pos) / magnify.zoom + pos);
27
+ return textureSampleLevel(
28
+ sourceTexture,
29
+ sourceTextureSampler,
30
+ (texCoord - pos) / magnify.zoom + pos,
31
+ 0.0
32
+ );
28
33
  }
29
34
 
30
35
  if (dist <= magnify.radiusPixels + magnify.borderWidthPixels) {
31
36
  return magnify.borderColor;
32
37
  }
33
- return textureSample(sourceTexture, sourceTextureSampler, texCoord);
38
+ return textureSampleLevel(sourceTexture, sourceTextureSampler, texCoord, 0.0);
34
39
  }
35
40
  `;
36
41
 
@@ -7,12 +7,12 @@ import {warp} from './warp';
7
7
 
8
8
  const source = /* wgsl */ `\
9
9
  struct bulgePinchUniforms {
10
+ center: vec2f,
10
11
  radius: f32,
11
12
  strength: f32,
12
- center: vec2f,
13
13
  };
14
14
 
15
- @group(0) @binding(1) var<uniform> bulgePinch: bulgePinchUniforms;
15
+ @group(0) @binding(auto) var<uniform> bulgePinch: bulgePinchUniforms;
16
16
 
17
17
  fn bulgePinch_warp(coordIn: vec2f, texCenter: vec2f) -> vec2f {
18
18
  var coord = coordIn - texCenter;
@@ -52,9 +52,9 @@ fn bulgePinch_sampleColor(
52
52
 
53
53
  const fs = /* glsl */ `\
54
54
  uniform bulgePinchUniforms {
55
+ vec2 center;
55
56
  float radius;
56
57
  float strength;
57
- vec2 center;
58
58
  } bulgePinch;
59
59
 
60
60
  vec2 bulgePinch_warp(vec2 coord, vec2 texCenter) {
@@ -7,12 +7,12 @@ import {warp} from './warp';
7
7
 
8
8
  const source = /* wgsl */ `\
9
9
  struct swirlUniforms {
10
+ center: vec2f,
10
11
  radius: f32,
11
12
  angle: f32,
12
- center: vec2f,
13
13
  };
14
14
 
15
- @group(0) @binding(1) var<uniform> swirl: swirlUniforms;
15
+ @group(0) @binding(auto) var<uniform> swirl: swirlUniforms;
16
16
 
17
17
  fn swirl_warp(coordIn: vec2f, texCenter: vec2f) -> vec2f {
18
18
  var coord = coordIn - texCenter;
@@ -45,9 +45,9 @@ fn swirl_sampleColor(
45
45
 
46
46
  const fs = /* glsl */ `\
47
47
  uniform swirlUniforms {
48
+ vec2 center;
48
49
  float radius;
49
50
  float angle;
50
- vec2 center;
51
51
  } swirl;
52
52
 
53
53
  vec2 swirl_warp(vec2 coord, vec2 texCenter) {