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

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 (98) hide show
  1. package/dist/dist.dev.js +1265 -362
  2. package/dist/dist.min.js +10 -9
  3. package/dist/index.cjs +419 -258
  4. package/dist/index.cjs.map +2 -2
  5. package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.d.ts +1 -1
  6. package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.d.ts.map +1 -1
  7. package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.js +5 -4
  8. package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.js.map +1 -1
  9. package/dist/passes/postprocessing/image-adjust-filters/denoise.d.ts +1 -1
  10. package/dist/passes/postprocessing/image-adjust-filters/denoise.d.ts.map +1 -1
  11. package/dist/passes/postprocessing/image-adjust-filters/denoise.js +29 -21
  12. package/dist/passes/postprocessing/image-adjust-filters/denoise.js.map +1 -1
  13. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts +1 -1
  14. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts.map +1 -1
  15. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.js +26 -32
  16. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.js.map +1 -1
  17. package/dist/passes/postprocessing/image-adjust-filters/noise.d.ts +1 -1
  18. package/dist/passes/postprocessing/image-adjust-filters/noise.d.ts.map +1 -1
  19. package/dist/passes/postprocessing/image-adjust-filters/noise.js +8 -7
  20. package/dist/passes/postprocessing/image-adjust-filters/noise.js.map +1 -1
  21. package/dist/passes/postprocessing/image-adjust-filters/sepia.d.ts +1 -1
  22. package/dist/passes/postprocessing/image-adjust-filters/sepia.d.ts.map +1 -1
  23. package/dist/passes/postprocessing/image-adjust-filters/sepia.js +10 -9
  24. package/dist/passes/postprocessing/image-adjust-filters/sepia.js.map +1 -1
  25. package/dist/passes/postprocessing/image-adjust-filters/vibrance.d.ts +1 -1
  26. package/dist/passes/postprocessing/image-adjust-filters/vibrance.d.ts.map +1 -1
  27. package/dist/passes/postprocessing/image-adjust-filters/vibrance.js +9 -8
  28. package/dist/passes/postprocessing/image-adjust-filters/vibrance.js.map +1 -1
  29. package/dist/passes/postprocessing/image-adjust-filters/vignette.d.ts +1 -1
  30. package/dist/passes/postprocessing/image-adjust-filters/vignette.d.ts.map +1 -1
  31. package/dist/passes/postprocessing/image-adjust-filters/vignette.js +9 -13
  32. package/dist/passes/postprocessing/image-adjust-filters/vignette.js.map +1 -1
  33. package/dist/passes/postprocessing/image-blur-filters/tiltshift.d.ts +2 -2
  34. package/dist/passes/postprocessing/image-blur-filters/tiltshift.d.ts.map +1 -1
  35. package/dist/passes/postprocessing/image-blur-filters/tiltshift.js +34 -16
  36. package/dist/passes/postprocessing/image-blur-filters/tiltshift.js.map +1 -1
  37. package/dist/passes/postprocessing/image-blur-filters/triangleblur.d.ts +2 -2
  38. package/dist/passes/postprocessing/image-blur-filters/triangleblur.d.ts.map +1 -1
  39. package/dist/passes/postprocessing/image-blur-filters/triangleblur.js +21 -12
  40. package/dist/passes/postprocessing/image-blur-filters/triangleblur.js.map +1 -1
  41. package/dist/passes/postprocessing/image-blur-filters/zoomblur.d.ts +2 -2
  42. package/dist/passes/postprocessing/image-blur-filters/zoomblur.d.ts.map +1 -1
  43. package/dist/passes/postprocessing/image-blur-filters/zoomblur.js +20 -11
  44. package/dist/passes/postprocessing/image-blur-filters/zoomblur.js.map +1 -1
  45. package/dist/passes/postprocessing/image-fun-filters/colorhalftone.d.ts +1 -1
  46. package/dist/passes/postprocessing/image-fun-filters/colorhalftone.d.ts.map +1 -1
  47. package/dist/passes/postprocessing/image-fun-filters/colorhalftone.js +18 -16
  48. package/dist/passes/postprocessing/image-fun-filters/colorhalftone.js.map +1 -1
  49. package/dist/passes/postprocessing/image-fun-filters/dotscreen.d.ts +1 -1
  50. package/dist/passes/postprocessing/image-fun-filters/dotscreen.js +11 -11
  51. package/dist/passes/postprocessing/image-fun-filters/edgework.d.ts +2 -2
  52. package/dist/passes/postprocessing/image-fun-filters/edgework.d.ts.map +1 -1
  53. package/dist/passes/postprocessing/image-fun-filters/edgework.js +83 -12
  54. package/dist/passes/postprocessing/image-fun-filters/edgework.js.map +1 -1
  55. package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.d.ts +1 -1
  56. package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.d.ts.map +1 -1
  57. package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.js +33 -21
  58. package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.js.map +1 -1
  59. package/dist/passes/postprocessing/image-fun-filters/ink.d.ts +1 -1
  60. package/dist/passes/postprocessing/image-fun-filters/ink.d.ts.map +1 -1
  61. package/dist/passes/postprocessing/image-fun-filters/ink.js +24 -15
  62. package/dist/passes/postprocessing/image-fun-filters/ink.js.map +1 -1
  63. package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts +1 -1
  64. package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts.map +1 -1
  65. package/dist/passes/postprocessing/image-fun-filters/magnify.js +16 -11
  66. package/dist/passes/postprocessing/image-fun-filters/magnify.js.map +1 -1
  67. package/dist/passes/postprocessing/image-warp-filters/bulgepinch.d.ts +2 -2
  68. package/dist/passes/postprocessing/image-warp-filters/bulgepinch.d.ts.map +1 -1
  69. package/dist/passes/postprocessing/image-warp-filters/bulgepinch.js +24 -10
  70. package/dist/passes/postprocessing/image-warp-filters/bulgepinch.js.map +1 -1
  71. package/dist/passes/postprocessing/image-warp-filters/swirl.d.ts +2 -2
  72. package/dist/passes/postprocessing/image-warp-filters/swirl.d.ts.map +1 -1
  73. package/dist/passes/postprocessing/image-warp-filters/swirl.js +18 -13
  74. package/dist/passes/postprocessing/image-warp-filters/swirl.js.map +1 -1
  75. package/dist/passes/postprocessing/image-warp-filters/warp.d.ts +1 -1
  76. package/dist/passes/postprocessing/image-warp-filters/warp.d.ts.map +1 -1
  77. package/dist/passes/postprocessing/image-warp-filters/warp.js +9 -4
  78. package/dist/passes/postprocessing/image-warp-filters/warp.js.map +1 -1
  79. package/package.json +2 -2
  80. package/src/passes/postprocessing/image-adjust-filters/brightnesscontrast.ts +5 -4
  81. package/src/passes/postprocessing/image-adjust-filters/denoise.ts +31 -23
  82. package/src/passes/postprocessing/image-adjust-filters/huesaturation.ts +28 -34
  83. package/src/passes/postprocessing/image-adjust-filters/noise.ts +8 -7
  84. package/src/passes/postprocessing/image-adjust-filters/sepia.ts +10 -9
  85. package/src/passes/postprocessing/image-adjust-filters/vibrance.ts +9 -8
  86. package/src/passes/postprocessing/image-adjust-filters/vignette.ts +9 -13
  87. package/src/passes/postprocessing/image-blur-filters/tiltshift.ts +36 -18
  88. package/src/passes/postprocessing/image-blur-filters/triangleblur.ts +21 -12
  89. package/src/passes/postprocessing/image-blur-filters/zoomblur.ts +21 -12
  90. package/src/passes/postprocessing/image-fun-filters/colorhalftone.ts +18 -16
  91. package/src/passes/postprocessing/image-fun-filters/dotscreen.ts +11 -11
  92. package/src/passes/postprocessing/image-fun-filters/edgework.ts +84 -13
  93. package/src/passes/postprocessing/image-fun-filters/hexagonalpixelate.ts +36 -24
  94. package/src/passes/postprocessing/image-fun-filters/ink.ts +24 -15
  95. package/src/passes/postprocessing/image-fun-filters/magnify.ts +16 -11
  96. package/src/passes/postprocessing/image-warp-filters/bulgepinch.ts +24 -10
  97. package/src/passes/postprocessing/image-warp-filters/swirl.ts +18 -13
  98. package/src/passes/postprocessing/image-warp-filters/warp.ts +9 -4
package/dist/index.cjs CHANGED
@@ -55,13 +55,14 @@ var source = (
55
55
  @group(0) @binding(1) var<uniform> brightnessContrast : brightnessContrastUniforms;
56
56
 
57
57
  fn brightnessContrast_filterColor_ext(color: vec4f, texSize: vec2<f32>, texCoords: vec2<f32>) -> vec4f {
58
- color.rgb += brightnessContrast.brightness;
58
+ var result = color;
59
+ result.rgb += vec3f(brightnessContrast.brightness);
59
60
  if (brightnessContrast.contrast > 0.0) {
60
- color.rgb = (color.rgb - 0.5) / (1.0 - brightnessContrast.contrast) + 0.5;
61
+ result.rgb = (result.rgb - vec3f(0.5)) / (1.0 - brightnessContrast.contrast) + vec3f(0.5);
61
62
  } else {
62
- color.rgb = (color.rgb - 0.5) * (1.0 + brightnessContrast.contrast) + 0.5;
63
+ result.rgb = (result.rgb - vec3f(0.5)) * (1.0 + brightnessContrast.contrast) + vec3f(0.5);
63
64
  }
64
- return vec4f(1.0, 0.0, 0.0, 1.0);
65
+ return result;
65
66
  }
66
67
  `
67
68
  );
@@ -110,33 +111,41 @@ var brightnessContrast = {
110
111
  // dist/passes/postprocessing/image-adjust-filters/denoise.js
111
112
  var source2 = (
112
113
  /* wgsl */
113
- `
114
- struct denoiseUniforms {
115
- strength: f32
114
+ `struct denoiseUniforms {
115
+ strength: f32,
116
116
  };
117
117
 
118
- @group(0), @binding(1) var<uniform> denoise: denoiseUniforms;
119
-
120
- fn denoise_sampleColor(source: sampler2D, texSize: vec2<f32>, texCoord: vec2<f32>) -> vec4<f32> {
121
- let adjustedExponent: f32 = 3. + 200. * pow(1. - denoise.strength, 4.);
122
- let center: vec4<f32> = sample_texture(BUFFER_source, texCoord);
123
- var color: vec4<f32> = vec4<f32>(0.);
124
- var total: f32 = 0.;
125
-
126
- for (var x: f32 = -4.; x <= 4.; x = x + (1.)) {
127
-
128
- for (var y: f32 = -4.; y <= 4.; y = y + (1.)) {
129
- let offsetColor: vec4<f32> = sample_texture(BUFFER_source, texCoord + vec2<f32>(x, y) / texSize);
130
- var weight: f32 = 1. - abs(dot(offsetColor.rgb - center.rgb, vec3<f32>(0.25)));
131
- weight = pow(weight, adjustedExponent);
132
- color = color + (offsetColor * weight);
133
- total = total + (weight);
134
- }
135
-
136
- }
118
+ @group(0) @binding(1) var<uniform> denoise: denoiseUniforms;
119
+
120
+ fn denoise_sampleColor(
121
+ sourceTexture: texture_2d<f32>,
122
+ sourceTextureSampler: sampler,
123
+ texSize: vec2f,
124
+ texCoord: vec2f
125
+ ) -> vec4f {
126
+ let adjustedExponent = 3.0 + 200.0 * pow(1.0 - denoise.strength, 4.0);
127
+ let center = textureSample(sourceTexture, sourceTextureSampler, texCoord);
128
+ var color = vec4f(0.0);
129
+ var total = 0.0;
130
+
131
+ for (var x = -4.0; x <= 4.0; x += 1.0) {
132
+ for (var y = -4.0; y <= 4.0; y += 1.0) {
133
+ let offsetColor = textureSample(
134
+ sourceTexture,
135
+ sourceTextureSampler,
136
+ texCoord + vec2f(x, y) / texSize
137
+ );
138
+ let weight = pow(
139
+ 1.0 - abs(dot(offsetColor.rgb - center.rgb, vec3f(0.25))),
140
+ adjustedExponent
141
+ );
142
+ color += offsetColor * weight;
143
+ total += weight;
144
+ }
145
+ }
137
146
 
138
- return color / total;
139
- }
147
+ return color / total;
148
+ }
140
149
  `
141
150
  );
142
151
  var fs2 = (
@@ -184,45 +193,39 @@ var denoise = {
184
193
  // dist/passes/postprocessing/image-adjust-filters/huesaturation.js
185
194
  var source3 = (
186
195
  /* wgsl */
187
- `
188
- struct hueSaturationUniforms {
196
+ `struct hueSaturationUniforms {
189
197
  hue: f32,
190
198
  saturation: f32,
191
199
  };
192
200
 
193
- @group(0), @binding(1) var<uniform> hueSaturation: hueSaturationUniforms;
194
-
195
- fn hueSaturation_filterColor(color: vec4<f32>) -> vec4<f32> {
196
- let angle: f32 = hueSaturation.hue * 3.1415927;
197
- let s: f32 = sin(angle);
198
- let c: f32 = cos(angle);
199
- let weights: vec3<f32> = (vec3<f32>(2. * c, -sqrt(3.) * s - c, sqrt(3.) * s - c) + 1.) / 3.;
200
- let len: f32 = length(color.rgb);
201
- var colorrgb = color.rgb;
202
- colorrgb = vec3<f32>(dot(color.rgb, weights.xyz), dot(color.rgb, weights.zxy), dot(color.rgb, weights.yzx));
203
- color.r = colorrgb.x;
204
- color.g = colorrgb.y;
205
- color.b = colorrgb.z;
206
- let average: f32 = (color.r + color.g + color.b) / 3.;
207
- if (hueSaturation.saturation > 0.) {
208
- var colorrgb = color.rgb;
209
- colorrgb = color.rgb + ((average - color.rgb) * (1. - 1. / (1.001 - hueSaturation.saturation)));
210
- color.r = colorrgb.x;
211
- color.g = colorrgb.y;
212
- color.b = colorrgb.z;
213
- } else {
214
- var colorrgb = color.rgb;
215
- colorrgb = color.rgb + ((average - color.rgb) * -hueSaturation.saturation);
216
- color.r = colorrgb.x;
217
- color.g = colorrgb.y;
218
- color.b = colorrgb.z;
219
- }
220
- return color;
221
- }
201
+ @group(0) @binding(1) var<uniform> hueSaturation: hueSaturationUniforms;
222
202
 
223
- fn hueSaturation_filterColor_ext(color: vec4<f32>, texSize: vec2<f32>, texCoord: vec2<f32>) -> vec4<f32> {
224
- return hueSaturation_filterColor(color);
225
- }
203
+ fn hueSaturation_filterColor(color: vec4f) -> vec4f {
204
+ let angle = hueSaturation.hue * 3.14159265;
205
+ let s = sin(angle);
206
+ let c = cos(angle);
207
+ let weights = (vec3f(2.0 * c, -sqrt(3.0) * s - c, sqrt(3.0) * s - c) + vec3f(1.0)) / 3.0;
208
+
209
+ var result = color;
210
+ result.rgb = vec3f(
211
+ dot(result.rgb, weights.xyz),
212
+ dot(result.rgb, weights.zxy),
213
+ dot(result.rgb, weights.yzx)
214
+ );
215
+
216
+ let average = (result.r + result.g + result.b) / 3.0;
217
+ if (hueSaturation.saturation > 0.0) {
218
+ result.rgb += (vec3f(average) - result.rgb) * (1.0 - 1.0 / (1.001 - hueSaturation.saturation));
219
+ } else {
220
+ result.rgb += (vec3f(average) - result.rgb) * (-hueSaturation.saturation);
221
+ }
222
+
223
+ return result;
224
+ }
225
+
226
+ fn hueSaturation_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) -> vec4f {
227
+ return hueSaturation_filterColor(color);
228
+ }
226
229
  `
227
230
  );
228
231
  var fs3 = (
@@ -280,7 +283,7 @@ var hueSaturation = {
280
283
  var source4 = (
281
284
  /* wgsl */
282
285
  `struct noiseUniforms {
283
- amount: f32
286
+ amount: f32,
284
287
  };
285
288
 
286
289
  @group(0) @binding(1) var<uniform> noise: noiseUniforms;
@@ -290,12 +293,13 @@ fn rand(co: vec2f) -> f32 {
290
293
  }
291
294
 
292
295
  fn noise_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) -> vec4f {
293
- let diff: f32 = (rand(texCoord) - 0.5) * noise.amount;
294
- color.r = color.r + (diff);
295
- color.g = color.g + (diff);
296
- color.b = color.b + (diff);
297
- return color;
298
- }
296
+ let diff = (rand(texCoord) - 0.5) * noise.amount;
297
+ var result = color;
298
+ result.r += diff;
299
+ result.g += diff;
300
+ result.b += diff;
301
+ return result;
302
+ }
299
303
  `
300
304
  );
301
305
  var fs4 = (
@@ -336,25 +340,26 @@ var noise = {
336
340
  var source5 = (
337
341
  /* wgsl */
338
342
  `struct sepiaUniforms {
339
- amount: f32
343
+ amount: f32,
340
344
  };
341
345
 
342
346
  @group(0) @binding(1) var<uniform> sepia: sepiaUniforms;
343
347
 
344
348
  fn sepia_filterColor(color: vec4f) -> vec4f {
345
- let r: f32 = color.r;
346
- let g: f32 = color.g;
347
- let b: f32 = color.b;
349
+ let r = color.r;
350
+ let g = color.g;
351
+ let b = color.b;
348
352
 
349
- color.r =
353
+ var result = color;
354
+ result.r =
350
355
  min(1.0, (r * (1.0 - (0.607 * sepia.amount))) + (g * (0.769 * sepia.amount)) + (b * (0.189 * sepia.amount)));
351
- color.g = min(1.0, (r * 0.349 * sepia.amount) + (g * (1.0 - (0.314 * sepia.amount))) + (b * 0.168 * sepia.amount));
352
- color.b = min(1.0, (r * 0.272 * sepia.amount) + (g * 0.534 * sepia.amount) + (b * (1.0 - (0.869 * sepia.amount))));
356
+ result.g = min(1.0, (r * 0.349 * sepia.amount) + (g * (1.0 - (0.314 * sepia.amount))) + (b * 0.168 * sepia.amount));
357
+ result.b = min(1.0, (r * 0.272 * sepia.amount) + (g * 0.534 * sepia.amount) + (b * (1.0 - (0.869 * sepia.amount))));
353
358
 
354
- return color;
359
+ return result;
355
360
  }
356
361
 
357
- vec4 sepia_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
362
+ fn sepia_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) -> vec4f {
358
363
  return sepia_filterColor(color);
359
364
  }
360
365
  `
@@ -402,20 +407,21 @@ var sepia = {
402
407
  var source6 = (
403
408
  /* wgsl */
404
409
  `struct vibranceUniforms {
405
- amount: f32
410
+ amount: f32,
406
411
  };
407
412
 
408
413
  @group(0) @binding(1) var<uniform> vibrance: vibranceUniforms;
409
414
 
410
- fn vibrance_filterColor(vec4f color) -> vec4f {
411
- let average: f32 = (color.r + color.g + color.b) / 3.0;
412
- let mx: f32 = max(color.r, max(color.g, color.b));
413
- let amt: f32 = (mx - average) * (-vibrance.amount * 3.0);
414
- color.rgb = mix(color.rgb, vec3(mx), amt);
415
- return color;
415
+ fn vibrance_filterColor(color: vec4f) -> vec4f {
416
+ let average = (color.r + color.g + color.b) / 3.0;
417
+ let mx = max(color.r, max(color.g, color.b));
418
+ let amt = (mx - average) * (-vibrance.amount * 3.0);
419
+ var result = color;
420
+ result.rgb = mix(result.rgb, vec3f(mx), amt);
421
+ return result;
416
422
  }
417
423
 
418
- vec4 vibrance_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
424
+ fn vibrance_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) -> vec4f {
419
425
  return vibrance_filterColor(color);
420
426
  }
421
427
  `
@@ -459,23 +465,19 @@ var source7 = (
459
465
  /* wgsl */
460
466
  `struct vignetteUniforms {
461
467
  radius: f32,
462
- amount: f32
468
+ amount: f32,
463
469
  };
464
470
 
465
471
  @group(0) @binding(1) var<uniform> vignette: vignetteUniforms;
466
472
 
467
- fn vibrance_filterColor(color: vec4f) -> vec4f {
468
- let average: f32 = (color.r + color.g + color.b) / 3.0;
469
- let mx: f32 = max(color.r, max(color.g, color.b));
470
- let amt: f32 = (mx - average) * (-vibrance.amount * 3.0);
471
- color.rgb = mix(color.rgb, vec3f(mx), amt);
472
- return color;
473
- }
474
-
475
- fn vignette_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) ->vec4f {
476
- let dist: f32 = distance(texCoord, vec2f(0.5, 0.5));
477
- let ratio: f32 = smoothstep(0.8, vignette.radius * 0.799, dist * (vignette.amount + vignette.radius));
478
- return color.rgba * ratio + (1.0 - ratio)*vec4f(0.0, 0.0, 0.0, 1.0);
473
+ fn vignette_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) -> vec4f {
474
+ let dist = distance(texCoord, vec2f(0.5, 0.5));
475
+ let ratio = smoothstep(
476
+ 0.8,
477
+ vignette.radius * 0.799,
478
+ dist * (vignette.amount + vignette.radius)
479
+ );
480
+ return color * ratio + vec4f(0.0, 0.0, 0.0, 1.0) * (1.0 - ratio);
479
481
  }
480
482
  `
481
483
  );
@@ -518,7 +520,7 @@ var vignette = {
518
520
  var import_shadertools = require("@luma.gl/shadertools");
519
521
  var source8 = (
520
522
  /* wgsl */
521
- `uniform tiltShiftUniforms {
523
+ `struct tiltShiftUniforms {
522
524
  blurRadius: f32,
523
525
  gradientRadius: f32,
524
526
  start: vec2f,
@@ -528,32 +530,50 @@ var source8 = (
528
530
 
529
531
  @group(0) @binding(1) var<uniform> tiltShift: tiltShiftUniforms;
530
532
 
531
- fn tiltShift_getDelta(vec2 texSize) -> vec2f {
532
- vec2 vector = normalize((tiltShift.end - tiltShift.start) * texSize);
533
- return tiltShift.invert ? vec2(-vector.y, vector.x) : vector;
533
+ fn tiltShift_getDelta(texSize: vec2f) -> vec2f {
534
+ let vector = normalize((tiltShift.end - tiltShift.start) * texSize);
535
+ return select(vector, vec2f(-vector.y, vector.x), tiltShift.invert != 0u);
534
536
  }
535
537
 
536
- fn tiltShift_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) -> vec4f {
537
- vec4 color = vec4(0.0);
538
- float total = 0.0;
538
+ fn tiltShift_sampleColor(
539
+ sourceTexture: texture_2d<f32>,
540
+ sourceTextureSampler: sampler,
541
+ texSize: vec2f,
542
+ texCoord: vec2f
543
+ ) -> vec4f {
544
+ var color = vec4f(0.0);
545
+ var total = 0.0;
539
546
 
540
547
  /* randomize the lookup values to hide the fixed number of samples */
541
- float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
548
+ let offset = random(vec3f(12.9898, 78.233, 151.7182), 0.0);
542
549
 
543
- vec2 normal = normalize(vec2((tiltShift.start.y - tiltShift.end.y) * texSize.y, (tiltShift.end.x - tiltShift.start.x) * texSize.x));
544
- float radius = smoothstep(0.0, 1.0,
545
- abs(dot(texCoord * texSize - tiltShift.start * texSize, normal)) / tiltShift.gradientRadius) * tiltShift.blurRadius;
546
-
547
- for (float t = -30.0; t <= 30.0; t++) {
548
- float percent = (t + offset - 0.5) / 30.0;
549
- float weight = 1.0 - abs(percent);
550
- vec4 offsetColor = texture(source, texCoord + tiltShift_getDelta(texSize) / texSize * percent * radius);
550
+ let normal = normalize(
551
+ vec2f(
552
+ (tiltShift.start.y - tiltShift.end.y) * texSize.y,
553
+ (tiltShift.end.x - tiltShift.start.x) * texSize.x
554
+ )
555
+ );
556
+ let radius =
557
+ smoothstep(
558
+ 0.0,
559
+ 1.0,
560
+ abs(dot(texCoord * texSize - tiltShift.start * texSize, normal)) / tiltShift.gradientRadius
561
+ ) * tiltShift.blurRadius;
562
+
563
+ for (var t = -30.0; t <= 30.0; t += 1.0) {
564
+ let percent = (t + offset - 0.5) / 30.0;
565
+ let weight = 1.0 - abs(percent);
566
+ let offsetColor = textureSample(
567
+ sourceTexture,
568
+ sourceTextureSampler,
569
+ texCoord + tiltShift_getDelta(texSize) / texSize * percent * radius
570
+ );
551
571
 
552
572
  color += offsetColor * weight;
553
573
  total += weight;
554
574
  }
555
575
 
556
- color = color / total;
576
+ color /= total;
557
577
  return color;
558
578
  }
559
579
  `
@@ -628,26 +648,35 @@ var tiltShift = {
628
648
  var import_shadertools2 = require("@luma.gl/shadertools");
629
649
  var source9 = (
630
650
  /* wgsl */
631
- `uniform triangleBlurUniforms {
651
+ `struct triangleBlurUniforms {
632
652
  radius: f32,
633
653
  delta: vec2f,
634
- }
654
+ };
635
655
 
636
656
  @group(0) @binding(1) var<uniform> triangleBlur: triangleBlurUniforms;
637
657
 
638
- vec4 triangleBlur_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
639
- vec2 adjustedDelta = triangleBlur.delta * triangleBlur.radius / texSize;
658
+ fn triangleBlur_sampleColor(
659
+ sourceTexture: texture_2d<f32>,
660
+ sourceTextureSampler: sampler,
661
+ texSize: vec2f,
662
+ texCoord: vec2f
663
+ ) -> vec4f {
664
+ let adjustedDelta = triangleBlur.delta * triangleBlur.radius / texSize;
640
665
 
641
- vec4 color = vec4(0.0);
642
- float total = 0.0;
666
+ var color = vec4f(0.0);
667
+ var total = 0.0;
643
668
 
644
669
  /* randomize the lookup values to hide the fixed number of samples */
645
- float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
646
-
647
- for (float t = -30.0; t <= 30.0; t++) {
648
- float percent = (t + offset - 0.5) / 30.0;
649
- float weight = 1.0 - abs(percent);
650
- vec4 offsetColor = texture(source, texCoord + adjustedDelta * percent);
670
+ let offset = random(vec3f(12.9898, 78.233, 151.7182), 0.0);
671
+
672
+ for (var t = -30.0; t <= 30.0; t += 1.0) {
673
+ let percent = (t + offset - 0.5) / 30.0;
674
+ let weight = 1.0 - abs(percent);
675
+ var offsetColor = textureSample(
676
+ sourceTexture,
677
+ sourceTextureSampler,
678
+ texCoord + adjustedDelta * percent
679
+ );
651
680
 
652
681
  /* switch to pre-multiplied alpha to correctly blur transparent images */
653
682
  offsetColor.rgb *= offsetColor.a;
@@ -656,7 +685,7 @@ vec4 triangleBlur_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
656
685
  total += weight;
657
686
  }
658
687
 
659
- color = color / total;
688
+ color /= total;
660
689
 
661
690
  /* switch back from pre-multiplied alpha */
662
691
  color.rgb /= color.a + 0.00001;
@@ -728,7 +757,7 @@ var import_shadertools3 = require("@luma.gl/shadertools");
728
757
  var source10 = (
729
758
  /* wgsl */
730
759
  `
731
- uniform zoomBlurUniforms {
760
+ struct zoomBlurUniforms {
732
761
  center: vec2f,
733
762
  strength: f32,
734
763
  };
@@ -736,23 +765,32 @@ uniform zoomBlurUniforms {
736
765
  @group(0) @binding(1) var<uniform> zoomBlur : zoomBlurUniforms;
737
766
 
738
767
 
739
- fn zoomBlur_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) -> vec4f {
740
- vec4 color = vec4(0.0);
741
- float total = 0.0;
742
- vec2 toCenter = zoomBlur.center * texSize - texCoord * texSize;
768
+ fn zoomBlur_sampleColor(
769
+ sourceTexture: texture_2d<f32>,
770
+ sourceTextureSampler: sampler,
771
+ texSize: vec2f,
772
+ texCoord: vec2f
773
+ ) -> vec4f {
774
+ var color = vec4f(0.0);
775
+ var total = 0.0;
776
+ let toCenter = zoomBlur.center * texSize - texCoord * texSize;
743
777
 
744
778
  /* randomize the lookup values to hide the fixed number of samples */
745
- float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
746
-
747
- for (float t = 0.0; t <= 40.0; t++) {
748
- float percent = (t + offset) / 40.0;
749
- float weight = 4.0 * (percent - percent * percent);
750
- vec4 offsetColor = texture(source, texCoord + toCenter * percent * zoomBlur.strength / texSize);
779
+ let offset = random(vec3f(12.9898, 78.233, 151.7182), 0.0);
780
+
781
+ for (var t = 0.0; t <= 40.0; t += 1.0) {
782
+ let percent = (t + offset) / 40.0;
783
+ let weight = 4.0 * (percent - percent * percent);
784
+ let offsetColor = textureSample(
785
+ sourceTexture,
786
+ sourceTextureSampler,
787
+ texCoord + toCenter * percent * zoomBlur.strength / texSize
788
+ );
751
789
  color += offsetColor * weight;
752
790
  total += weight;
753
791
  }
754
792
 
755
- color = color / total;
793
+ color /= total;
756
794
  return color;
757
795
  }
758
796
  `
@@ -810,38 +848,40 @@ var source11 = (
810
848
  `struct colorHalftoneUniforms {
811
849
  center: vec2f,
812
850
  angle: f32,
813
- size: f32.
851
+ size: f32,
814
852
  };
815
853
 
816
854
  @group(0) @binding(1) var<uniform> colorHalftone: colorHalftoneUniforms;
817
855
 
818
856
  fn pattern(angle: f32, scale: f32, texSize: vec2f, texCoord: vec2f) -> f32 {
819
- let s: f32 = sin(angle), c = cos(angle);
820
- let tex: vec2f = texCoord * texSize - colorHalftone.center * texSize;
821
- let point: vec2f = vec2(
822
- c * tex.x - s * tex.y,
823
- s * tex.x + c * tex.y
857
+ let s = sin(angle);
858
+ let c = cos(angle);
859
+ let tex = texCoord * texSize - colorHalftone.center * texSize;
860
+ let point = vec2f(
861
+ c * tex.x - s * tex.y,
862
+ s * tex.x + c * tex.y
824
863
  ) * scale;
825
864
  return (sin(point.x) * sin(point.y)) * 4.0;
826
865
  }
827
866
 
828
- fn colorHalftone_filterColor_ext(vec4f color, vec2f texSize, vec2f texCoord) -> vec4f {
829
- let scale: f32 = 3.1514 / colorHalftone.size;
830
- let cmy: vec3f = 1.0 - color.rgb;
831
- let k: f32 = min(cmy.x, min(cmy.y, cmy.z));
867
+ fn colorHalftone_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) -> vec4f {
868
+ let scale = 3.1514 / colorHalftone.size;
869
+ var cmy = vec3f(1.0) - color.rgb;
870
+ var k = min(cmy.x, min(cmy.y, cmy.z));
871
+ let safeDenominator = max(1.0 - k, 0.00001);
832
872
 
833
- cmy = (cmy - k) / (1.0 - k);
873
+ cmy = (cmy - vec3f(k)) / safeDenominator;
834
874
  cmy = clamp(
835
- cmy * 10.0 - 3.0 + vec3(
875
+ cmy * 10.0 - vec3f(3.0) + vec3f(
836
876
  pattern(colorHalftone.angle + 0.26179, scale, texSize, texCoord),
837
- pattern(colorHalftone.angle + 1.30899, scale, texSize, texCoord),
877
+ pattern(colorHalftone.angle + 1.30899, scale, texSize, texCoord),
838
878
  pattern(colorHalftone.angle, scale, texSize, texCoord)
839
879
  ),
840
- 0.0,
841
- 1.0
880
+ vec3f(0.0),
881
+ vec3f(1.0)
842
882
  );
843
883
  k = clamp(k * 10.0 - 5.0 + pattern(colorHalftone.angle + 0.78539, scale, texSize, texCoord), 0.0, 1.0);
844
- return vec4(1.0 - cmy - k, color.a);
884
+ return vec4f(vec3f(1.0) - cmy - vec3f(k), color.a);
845
885
  }
846
886
  `
847
887
  );
@@ -905,29 +945,29 @@ var colorHalftone = {
905
945
  // dist/passes/postprocessing/image-fun-filters/dotscreen.js
906
946
  var source12 = (
907
947
  /* wgsl */
908
- `uniform dotScreenUniforms {
948
+ `struct dotScreenUniforms {
909
949
  center: vec2f,
910
950
  angle: f32,
911
951
  size: f32,
912
952
  };
913
953
 
914
- @group(0) @binding(1) dotScreen: dotScreenUniforms;
954
+ @group(0) @binding(1) var<uniform> dotScreen: dotScreenUniforms;
915
955
 
916
956
  fn pattern(texSize: vec2f, texCoord: vec2f) -> f32 {
917
- let scale: f32 = 3.1415 / dotScreen.size;
918
-
919
- let s: f32 = sin(dotScreen.angle), c = cos(dotScreen.angle);
920
- tex: vec2f = texCoord * texSize - dotScreen.center * texSize;
921
- point = vec2f(
922
- c: * tex.x - s * tex.y,
957
+ let scale = 3.1415 / dotScreen.size;
958
+ let s = sin(dotScreen.angle);
959
+ let c = cos(dotScreen.angle);
960
+ let tex = texCoord * texSize - dotScreen.center * texSize;
961
+ let point = vec2f(
962
+ c * tex.x - s * tex.y,
923
963
  s * tex.x + c * tex.y
924
964
  ) * scale;
925
965
  return (sin(point.x) * sin(point.y)) * 4.0;
926
966
  }
927
967
 
928
- fn dotScreen_filterColor_ext(vec4 color, texSize: vec2f, texCoord: vec2f) -> vec4f {
929
- let average: f32 = (color.r + color.g + color.b) / 3.0;
930
- return vec4(vec3(average * 10.0 - 5.0 + pattern(texSize, texCoord)), color.a);
968
+ fn dotScreen_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) -> vec4f {
969
+ let average = (color.r + color.g + color.b) / 3.0;
970
+ return vec4f(vec3f(average * 10.0 - 5.0 + pattern(texSize, texCoord)), color.a);
931
971
  }
932
972
  `
933
973
  );
@@ -982,25 +1022,35 @@ var source13 = (
982
1022
  /* wgsl */
983
1023
  `struct edgeWorkUniforms {
984
1024
  radius: f32,
985
- int mode: uint32,
1025
+ mode: u32,
986
1026
  };
987
1027
 
988
1028
  @group(0) @binding(1) var<uniform> edgeWork: edgeWorkUniforms;
989
1029
 
990
- fn edgeWork_sampleColorRGB(sampler2D source, vec2 texSize, vec2 texCoord, vec2 delta) -> vec4f {
991
- vec2 relativeDelta = edgeWork.radius * delta / texSize;
1030
+ fn edgeWork_sampleColorRGB(
1031
+ sourceTexture: texture_2d<f32>,
1032
+ sourceTextureSampler: sampler,
1033
+ texSize: vec2f,
1034
+ texCoord: vec2f,
1035
+ delta: vec2f
1036
+ ) -> vec4f {
1037
+ let relativeDelta = edgeWork.radius * delta / texSize;
992
1038
 
993
- vec2 color = vec2(0.0);
994
- vec2 total = vec2(0.0);
1039
+ var color = vec2f(0.0);
1040
+ var total = vec2f(0.0);
995
1041
 
996
1042
  /* randomize the lookup values to hide the fixed number of samples */
997
- float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
998
-
999
- for (float t = -30.0; t <= 30.0; t++) {
1000
- float percent = (t + offset - 0.5) / 30.0;
1001
- float weight = 1.0 - abs(percent);
1002
- vec3 sampleColor = texture(source, texCoord + relativeDelta * percent).rgb;
1003
- float average = (sampleColor.r + sampleColor.g + sampleColor.b) / 3.0;
1043
+ let offset = random(vec3f(12.9898, 78.233, 151.7182), 0.0);
1044
+
1045
+ for (var t = -30.0; t <= 30.0; t += 1.0) {
1046
+ let percent = (t + offset - 0.5) / 30.0;
1047
+ var weight = 1.0 - abs(percent);
1048
+ let sampleColor = textureSample(
1049
+ sourceTexture,
1050
+ sourceTextureSampler,
1051
+ texCoord + relativeDelta * percent
1052
+ ).rgb;
1053
+ let average = (sampleColor.r + sampleColor.g + sampleColor.b) / 3.0;
1004
1054
  color.x += average * weight;
1005
1055
  total.x += weight;
1006
1056
  if (abs(t) < 15.0) {
@@ -1009,7 +1059,68 @@ fn edgeWork_sampleColorRGB(sampler2D source, vec2 texSize, vec2 texCoord, vec2 d
1009
1059
  total.y += weight;
1010
1060
  }
1011
1061
  }
1012
- return vec4(color / total, 0.0, 1.0);
1062
+ return vec4f(color / total, 0.0, 1.0);
1063
+ }
1064
+
1065
+ fn edgeWork_sampleColorXY(
1066
+ sourceTexture: texture_2d<f32>,
1067
+ sourceTextureSampler: sampler,
1068
+ texSize: vec2f,
1069
+ texCoord: vec2f,
1070
+ delta: vec2f
1071
+ ) -> vec4f {
1072
+ let relativeDelta = edgeWork.radius * delta / texSize;
1073
+
1074
+ var color = vec2f(0.0);
1075
+ var total = vec2f(0.0);
1076
+
1077
+ /* randomize the lookup values to hide the fixed number of samples */
1078
+ let offset = random(vec3f(12.9898, 78.233, 151.7182), 0.0);
1079
+
1080
+ for (var t = -30.0; t <= 30.0; t += 1.0) {
1081
+ let percent = (t + offset - 0.5) / 30.0;
1082
+ var weight = 1.0 - abs(percent);
1083
+ let sampleColor = textureSample(
1084
+ sourceTexture,
1085
+ sourceTextureSampler,
1086
+ texCoord + relativeDelta * percent
1087
+ ).xy;
1088
+ color.x += sampleColor.x * weight;
1089
+ total.x += weight;
1090
+ if (abs(t) < 15.0) {
1091
+ weight = weight * 2.0 - 1.0;
1092
+ color.y += sampleColor.y * weight;
1093
+ total.y += weight;
1094
+ }
1095
+ }
1096
+
1097
+ let c = clamp(10000.0 * (color.y / total.y - color.x / total.x) + 0.5, 0.0, 1.0);
1098
+ return vec4f(c, c, c, 1.0);
1099
+ }
1100
+
1101
+ fn edgeWork_sampleColor(
1102
+ sourceTexture: texture_2d<f32>,
1103
+ sourceTextureSampler: sampler,
1104
+ texSize: vec2f,
1105
+ texCoord: vec2f
1106
+ ) -> vec4f {
1107
+ if (edgeWork.mode == 0u) {
1108
+ return edgeWork_sampleColorRGB(
1109
+ sourceTexture,
1110
+ sourceTextureSampler,
1111
+ texSize,
1112
+ texCoord,
1113
+ vec2f(1.0, 0.0)
1114
+ );
1115
+ }
1116
+
1117
+ return edgeWork_sampleColorXY(
1118
+ sourceTexture,
1119
+ sourceTextureSampler,
1120
+ texSize,
1121
+ texCoord,
1122
+ vec2f(0.0, 1.0)
1123
+ );
1013
1124
  }
1014
1125
  `
1015
1126
  );
@@ -1118,42 +1229,54 @@ var source14 = (
1118
1229
 
1119
1230
  @group(0) @binding(1) var<uniform> hexagonalPixelate: hexagonalPixelateUniforms;
1120
1231
 
1121
- fn hexagonalPixelate_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) -> vec4f {
1122
- vec2 tex = (texCoord * texSize - hexagonalPixelate.center * texSize) / hexagonalPixelate.scale;
1232
+ fn hexagonalPixelate_sampleColor(
1233
+ sourceTexture: texture_2d<f32>,
1234
+ sourceTextureSampler: sampler,
1235
+ texSize: vec2f,
1236
+ texCoord: vec2f
1237
+ ) -> vec4f {
1238
+ var tex = (texCoord * texSize - hexagonalPixelate.center * texSize) / hexagonalPixelate.scale;
1123
1239
  tex.y /= 0.866025404;
1124
1240
  tex.x -= tex.y * 0.5;
1125
1241
 
1126
- vec2 a;
1242
+ var a = vec2f(0.0);
1127
1243
  if (tex.x + tex.y - floor(tex.x) - floor(tex.y) < 1.0) {
1128
- a = vec2(floor(tex.x), floor(tex.y));
1244
+ a = vec2f(floor(tex.x), floor(tex.y));
1245
+ } else {
1246
+ a = vec2f(ceil(tex.x), ceil(tex.y));
1129
1247
  }
1130
- else a = vec2(ceil(tex.x), ceil(tex.y));
1131
- vec2 b = vec2(ceil(tex.x), floor(tex.y));
1132
- vec2 c = vec2(floor(tex.x), ceil(tex.y));
1133
-
1134
- vec3 TEX = vec3(tex.x, tex.y, 1.0 - tex.x - tex.y);
1135
- vec3 A = vec3(a.x, a.y, 1.0 - a.x - a.y);
1136
- vec3 B = vec3(b.x, b.y, 1.0 - b.x - b.y);
1137
- vec3 C = vec3(c.x, c.y, 1.0 - c.x - c.y);
1138
-
1139
- float alen = length(TEX - A);
1140
- float blen = length(TEX - B);
1141
- float clen = length(TEX - C);
1142
-
1143
- vec2 choice;
1144
- if (alen < blen) {
1145
- if (alen < clen) choice = a;
1146
- else choice = c;
1248
+ let b = vec2f(ceil(tex.x), floor(tex.y));
1249
+ let c = vec2f(floor(tex.x), ceil(tex.y));
1250
+
1251
+ let texBarycentric = vec3f(tex.x, tex.y, 1.0 - tex.x - tex.y);
1252
+ let aBarycentric = vec3f(a.x, a.y, 1.0 - a.x - a.y);
1253
+ let bBarycentric = vec3f(b.x, b.y, 1.0 - b.x - b.y);
1254
+ let cBarycentric = vec3f(c.x, c.y, 1.0 - c.x - c.y);
1255
+
1256
+ let aLength = length(texBarycentric - aBarycentric);
1257
+ let bLength = length(texBarycentric - bBarycentric);
1258
+ let cLength = length(texBarycentric - cBarycentric);
1259
+
1260
+ var choice = vec2f(0.0);
1261
+ if (aLength < bLength) {
1262
+ if (aLength < cLength) {
1263
+ choice = a;
1264
+ } else {
1265
+ choice = c;
1266
+ }
1147
1267
  } else {
1148
- if (blen < clen) choice = b;
1149
- else choice = c;
1268
+ if (bLength < cLength) {
1269
+ choice = b;
1270
+ } else {
1271
+ choice = c;
1272
+ }
1150
1273
  }
1151
1274
 
1152
1275
  choice.x += choice.y * 0.5;
1153
1276
  choice.y *= 0.866025404;
1154
1277
  choice *= hexagonalPixelate.scale / texSize;
1155
1278
 
1156
- return texture(source, choice + hexagonalPixelate.center);
1279
+ return textureSample(sourceTexture, sourceTextureSampler, choice + hexagonalPixelate.center);
1157
1280
  }
1158
1281
  `
1159
1282
  );
@@ -1223,23 +1346,32 @@ var hexagonalPixelate = {
1223
1346
  // dist/passes/postprocessing/image-fun-filters/ink.js
1224
1347
  var source15 = (
1225
1348
  /* wgsl */
1226
- `uniform inkUniforms {
1349
+ `struct inkUniforms {
1227
1350
  strength: f32,
1228
1351
  };
1229
1352
 
1230
1353
  @group(0) @binding(1) var<uniform> ink: inkUniforms;
1231
1354
 
1232
- fn ink_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) -> vec4f {
1233
- vec2 dx = vec2(1.0 / texSize.x, 0.0);
1234
- vec2 dy = vec2(0.0, 1.0 / texSize.y);
1235
- vec4 color = texture(source, texCoord);
1236
- float bigTotal = 0.0;
1237
- float smallTotal = 0.0;
1238
- vec3 bigAverage = vec3(0.0);
1239
- vec3 smallAverage = vec3(0.0);
1240
- for (float x = -2.0; x <= 2.0; x += 1.0) {
1241
- for (float y = -2.0; y <= 2.0; y += 1.0) {
1242
- vec3 offsetColor = texture(source, texCoord + dx * x + dy * y).rgb;
1355
+ fn ink_sampleColor(
1356
+ sourceTexture: texture_2d<f32>,
1357
+ sourceTextureSampler: sampler,
1358
+ texSize: vec2f,
1359
+ texCoord: vec2f
1360
+ ) -> vec4f {
1361
+ let dx = vec2f(1.0 / texSize.x, 0.0);
1362
+ let dy = vec2f(0.0, 1.0 / texSize.y);
1363
+ let color = textureSample(sourceTexture, sourceTextureSampler, texCoord);
1364
+ var bigTotal = 0.0;
1365
+ var smallTotal = 0.0;
1366
+ var bigAverage = vec3f(0.0);
1367
+ var smallAverage = vec3f(0.0);
1368
+ for (var x = -2.0; x <= 2.0; x += 1.0) {
1369
+ for (var y = -2.0; y <= 2.0; y += 1.0) {
1370
+ let offsetColor = textureSample(
1371
+ sourceTexture,
1372
+ sourceTextureSampler,
1373
+ texCoord + dx * x + dy * y
1374
+ ).rgb;
1243
1375
  bigAverage += offsetColor;
1244
1376
  bigTotal += 1.0;
1245
1377
  if (abs(x) + abs(y) < 2.0) {
@@ -1248,9 +1380,9 @@ fn ink_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) -> vec4f {
1248
1380
  }
1249
1381
  }
1250
1382
  }
1251
- vec3 edge = max(vec3(0.0), bigAverage / bigTotal - smallAverage / smallTotal);
1252
- float power = ink.strength * ink.strength * ink.strength * ink.strength * ink.strength;
1253
- return vec4(color.rgb - dot(edge, edge) * power * 100000.0, color.a);
1383
+ let edge = max(vec3f(0.0), bigAverage / bigTotal - smallAverage / smallTotal);
1384
+ let power = ink.strength * ink.strength * ink.strength * ink.strength * ink.strength;
1385
+ return vec4f(color.rgb - vec3f(dot(edge, edge) * power * 100000.0), color.a);
1254
1386
  }
1255
1387
  `
1256
1388
  );
@@ -1303,27 +1435,32 @@ var ink = {
1303
1435
  // dist/passes/postprocessing/image-fun-filters/magnify.js
1304
1436
  var source16 = (
1305
1437
  /* wgsl */
1306
- `uniform magnifyUniforms {
1307
- screenXY: vec2f;
1308
- radiusPixels: f32;
1309
- zoom: f32;
1310
- borderWidthPixels: f32;
1311
- borderColor: vec4f;
1438
+ `struct magnifyUniforms {
1439
+ screenXY: vec2f,
1440
+ radiusPixels: f32,
1441
+ zoom: f32,
1442
+ borderWidthPixels: f32,
1443
+ borderColor: vec4f,
1312
1444
  };
1313
1445
 
1314
1446
  @group(0) @binding(1) var<uniform> magnify: magnifyUniforms;
1315
1447
 
1316
- fn magnify_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) -> vec4f {
1317
- vec2 pos = vec2(magnify.screenXY.x, 1.0 - magnify.screenXY.y);
1318
- float dist = distance(texCoord * texSize, pos * texSize);
1448
+ fn magnify_sampleColor(
1449
+ sourceTexture: texture_2d<f32>,
1450
+ sourceTextureSampler: sampler,
1451
+ texSize: vec2f,
1452
+ texCoord: vec2f
1453
+ ) -> vec4f {
1454
+ let pos = vec2f(magnify.screenXY.x, 1.0 - magnify.screenXY.y);
1455
+ let dist = distance(texCoord * texSize, pos * texSize);
1319
1456
  if (dist < magnify.radiusPixels) {
1320
- return texture(source, (texCoord - pos) / magnify.zoom + pos);
1457
+ return textureSample(sourceTexture, sourceTextureSampler, (texCoord - pos) / magnify.zoom + pos);
1321
1458
  }
1322
1459
 
1323
1460
  if (dist <= magnify.radiusPixels + magnify.borderWidthPixels) {
1324
1461
  return magnify.borderColor;
1325
1462
  }
1326
- return texture(source, texCoord);
1463
+ return textureSample(sourceTexture, sourceTextureSampler, texCoord);
1327
1464
  }
1328
1465
  `
1329
1466
  );
@@ -1376,10 +1513,15 @@ var magnify = {
1376
1513
  // dist/passes/postprocessing/image-warp-filters/warp.js
1377
1514
  var source17 = (
1378
1515
  /* wgsl */
1379
- `vec4 warp_sampleColor(sampler2D source, vec2 texSize, vec2 coord) {
1380
- vec4 color = texture(source, coord / texSize);
1381
- vec2 clampedCoord = clamp(coord, vec2(0.0), texSize);
1382
- if (coord != clampedCoord) {
1516
+ `fn warp_sampleColor(
1517
+ sourceTexture: texture_2d<f32>,
1518
+ sourceTextureSampler: sampler,
1519
+ texSize: vec2f,
1520
+ coord: vec2f
1521
+ ) -> vec4f {
1522
+ var color = textureSample(sourceTexture, sourceTextureSampler, coord / texSize);
1523
+ let clampedCoord = clamp(coord, vec2f(0.0), texSize);
1524
+ if (any(coord != clampedCoord)) {
1383
1525
  /* fade to transparent if we are outside the image */
1384
1526
  color.a *= max(0.0, 1.0 - length(coord - clampedCoord));
1385
1527
  }
@@ -1410,7 +1552,7 @@ var warp = {
1410
1552
  // dist/passes/postprocessing/image-warp-filters/bulgepinch.js
1411
1553
  var source18 = (
1412
1554
  /* wgsl */
1413
- `uniform bulgePinchUniforms {
1555
+ `struct bulgePinchUniforms {
1414
1556
  radius: f32,
1415
1557
  strength: f32,
1416
1558
  center: vec2f,
@@ -1418,25 +1560,39 @@ var source18 = (
1418
1560
 
1419
1561
  @group(0) @binding(1) var<uniform> bulgePinch: bulgePinchUniforms;
1420
1562
 
1421
- fn bulgePinch_warp(vec2 coord, vec2 texCenter) -> vec2f {
1422
- coord -= texCenter;
1423
- float distance = length(coord);
1563
+ fn bulgePinch_warp(coordIn: vec2f, texCenter: vec2f) -> vec2f {
1564
+ var coord = coordIn - texCenter;
1565
+ let distance = length(coord);
1424
1566
  if (distance < bulgePinch.radius) {
1425
- float percent = distance / bulgePinch.radius;
1567
+ let percent = distance / bulgePinch.radius;
1568
+ let safeDistance = max(distance, 0.00001);
1426
1569
  if (bulgePinch.strength > 0.0) {
1427
- coord *= mix(1.0, smoothstep(0.0, bulgePinch.radius / distance, percent), bulgePinch.strength * 0.75);
1570
+ coord *= mix(
1571
+ 1.0,
1572
+ smoothstep(0.0, bulgePinch.radius / safeDistance, percent),
1573
+ bulgePinch.strength * 0.75
1574
+ );
1428
1575
  } else {
1429
- coord *= mix(1.0, pow(percent, 1.0 + bulgePinch.strength * 0.75) * bulgePinch.radius / distance, 1.0 - percent);
1576
+ coord *= mix(
1577
+ 1.0,
1578
+ pow(percent, 1.0 + bulgePinch.strength * 0.75) * bulgePinch.radius / safeDistance,
1579
+ 1.0 - percent
1580
+ );
1430
1581
  }
1431
1582
  }
1432
1583
  coord += texCenter;
1433
1584
  return coord;
1434
1585
  }
1435
1586
 
1436
- fn bulgePinch_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) -> vec4f {
1437
- vec2 coord = texCoord * texSize;
1587
+ fn bulgePinch_sampleColor(
1588
+ sourceTexture: texture_2d<f32>,
1589
+ sourceTextureSampler: sampler,
1590
+ texSize: vec2f,
1591
+ texCoord: vec2f
1592
+ ) -> vec4f {
1593
+ var coord = texCoord * texSize;
1438
1594
  coord = bulgePinch_warp(coord, bulgePinch.center * texSize);
1439
- return warp_sampleColor(source, texSize, coord);
1595
+ return warp_sampleColor(sourceTexture, sourceTextureSampler, texSize, coord);
1440
1596
  }
1441
1597
  `
1442
1598
  );
@@ -1494,23 +1650,23 @@ var bulgePinch = {
1494
1650
  // dist/passes/postprocessing/image-warp-filters/swirl.js
1495
1651
  var source19 = (
1496
1652
  /* wgsl */
1497
- `uniform swirlUniforms {
1653
+ `struct swirlUniforms {
1498
1654
  radius: f32,
1499
1655
  angle: f32,
1500
1656
  center: vec2f,
1501
1657
  };
1502
1658
 
1503
- @group(0) @binding(1) swirl: swirlUniforms;
1659
+ @group(0) @binding(1) var<uniform> swirl: swirlUniforms;
1504
1660
 
1505
- fn swirl_warp(vec2 coord, vec2 texCenter) -> vec2f {
1506
- coord -= texCenter;
1507
- float distance = length(coord);
1661
+ fn swirl_warp(coordIn: vec2f, texCenter: vec2f) -> vec2f {
1662
+ var coord = coordIn - texCenter;
1663
+ let distance = length(coord);
1508
1664
  if (distance < swirl.radius) {
1509
- float percent = (swirl.radius - distance) / swirl.radius;
1510
- float theta = percent * percent * swirl.angle;
1511
- float s = sin(theta);
1512
- float c = cos(theta);
1513
- coord = vec2(
1665
+ let percent = (swirl.radius - distance) / swirl.radius;
1666
+ let theta = percent * percent * swirl.angle;
1667
+ let s = sin(theta);
1668
+ let c = cos(theta);
1669
+ coord = vec2f(
1514
1670
  coord.x * c - coord.y * s,
1515
1671
  coord.x * s + coord.y * c
1516
1672
  );
@@ -1519,10 +1675,15 @@ fn swirl_warp(vec2 coord, vec2 texCenter) -> vec2f {
1519
1675
  return coord;
1520
1676
  }
1521
1677
 
1522
- fn swirl_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) -> vec4f {
1523
- vec2 coord = texCoord * texSize;
1678
+ fn swirl_sampleColor(
1679
+ sourceTexture: texture_2d<f32>,
1680
+ sourceTextureSampler: sampler,
1681
+ texSize: vec2f,
1682
+ texCoord: vec2f
1683
+ ) -> vec4f {
1684
+ var coord = texCoord * texSize;
1524
1685
  coord = swirl_warp(coord, swirl.center * texSize);
1525
- return warp_sampleColor(source, texSize, coord);
1686
+ return warp_sampleColor(sourceTexture, sourceTextureSampler, texSize, coord);
1526
1687
  }
1527
1688
  `
1528
1689
  );