@luma.gl/effects 9.3.0-alpha.4 → 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 (101) hide show
  1. package/dist/dist.dev.js +1934 -415
  2. package/dist/dist.min.js +6 -6
  3. package/dist/index.cjs +736 -285
  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 -6
  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.d.ts.map +1 -1
  15. package/dist/passes/postprocessing/image-adjust-filters/denoise.js +32 -24
  16. package/dist/passes/postprocessing/image-adjust-filters/denoise.js.map +1 -1
  17. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts +1 -1
  18. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts.map +1 -1
  19. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.js +25 -32
  20. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.js.map +1 -1
  21. package/dist/passes/postprocessing/image-adjust-filters/noise.d.ts +1 -1
  22. package/dist/passes/postprocessing/image-adjust-filters/noise.d.ts.map +1 -1
  23. package/dist/passes/postprocessing/image-adjust-filters/noise.js +9 -8
  24. package/dist/passes/postprocessing/image-adjust-filters/noise.js.map +1 -1
  25. package/dist/passes/postprocessing/image-adjust-filters/sepia.d.ts +1 -1
  26. package/dist/passes/postprocessing/image-adjust-filters/sepia.d.ts.map +1 -1
  27. package/dist/passes/postprocessing/image-adjust-filters/sepia.js +11 -10
  28. package/dist/passes/postprocessing/image-adjust-filters/sepia.js.map +1 -1
  29. package/dist/passes/postprocessing/image-adjust-filters/vibrance.d.ts +1 -1
  30. package/dist/passes/postprocessing/image-adjust-filters/vibrance.js +9 -9
  31. package/dist/passes/postprocessing/image-adjust-filters/vignette.d.ts +1 -1
  32. package/dist/passes/postprocessing/image-adjust-filters/vignette.d.ts.map +1 -1
  33. package/dist/passes/postprocessing/image-adjust-filters/vignette.js +10 -14
  34. package/dist/passes/postprocessing/image-adjust-filters/vignette.js.map +1 -1
  35. package/dist/passes/postprocessing/image-blur-filters/tiltshift.d.ts +2 -2
  36. package/dist/passes/postprocessing/image-blur-filters/tiltshift.d.ts.map +1 -1
  37. package/dist/passes/postprocessing/image-blur-filters/tiltshift.js +35 -17
  38. package/dist/passes/postprocessing/image-blur-filters/tiltshift.js.map +1 -1
  39. package/dist/passes/postprocessing/image-blur-filters/triangleblur.d.ts +2 -2
  40. package/dist/passes/postprocessing/image-blur-filters/triangleblur.d.ts.map +1 -1
  41. package/dist/passes/postprocessing/image-blur-filters/triangleblur.js +26 -17
  42. package/dist/passes/postprocessing/image-blur-filters/triangleblur.js.map +1 -1
  43. package/dist/passes/postprocessing/image-blur-filters/zoomblur.d.ts +2 -2
  44. package/dist/passes/postprocessing/image-blur-filters/zoomblur.d.ts.map +1 -1
  45. package/dist/passes/postprocessing/image-blur-filters/zoomblur.js +21 -12
  46. package/dist/passes/postprocessing/image-blur-filters/zoomblur.js.map +1 -1
  47. package/dist/passes/postprocessing/image-fun-filters/colorhalftone.d.ts +1 -1
  48. package/dist/passes/postprocessing/image-fun-filters/colorhalftone.d.ts.map +1 -1
  49. package/dist/passes/postprocessing/image-fun-filters/colorhalftone.js +19 -17
  50. package/dist/passes/postprocessing/image-fun-filters/colorhalftone.js.map +1 -1
  51. package/dist/passes/postprocessing/image-fun-filters/dotscreen.d.ts +1 -1
  52. package/dist/passes/postprocessing/image-fun-filters/dotscreen.js +11 -11
  53. package/dist/passes/postprocessing/image-fun-filters/edgework.d.ts +2 -2
  54. package/dist/passes/postprocessing/image-fun-filters/edgework.d.ts.map +1 -1
  55. package/dist/passes/postprocessing/image-fun-filters/edgework.js +84 -13
  56. package/dist/passes/postprocessing/image-fun-filters/edgework.js.map +1 -1
  57. package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.d.ts +1 -1
  58. package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.d.ts.map +1 -1
  59. package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.js +34 -22
  60. package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.js.map +1 -1
  61. package/dist/passes/postprocessing/image-fun-filters/ink.d.ts +1 -1
  62. package/dist/passes/postprocessing/image-fun-filters/ink.d.ts.map +1 -1
  63. package/dist/passes/postprocessing/image-fun-filters/ink.js +25 -16
  64. package/dist/passes/postprocessing/image-fun-filters/ink.js.map +1 -1
  65. package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts +1 -1
  66. package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts.map +1 -1
  67. package/dist/passes/postprocessing/image-fun-filters/magnify.js +22 -12
  68. package/dist/passes/postprocessing/image-fun-filters/magnify.js.map +1 -1
  69. package/dist/passes/postprocessing/image-warp-filters/bulgepinch.d.ts +3 -3
  70. package/dist/passes/postprocessing/image-warp-filters/bulgepinch.d.ts.map +1 -1
  71. package/dist/passes/postprocessing/image-warp-filters/bulgepinch.js +27 -13
  72. package/dist/passes/postprocessing/image-warp-filters/bulgepinch.js.map +1 -1
  73. package/dist/passes/postprocessing/image-warp-filters/swirl.d.ts +3 -3
  74. package/dist/passes/postprocessing/image-warp-filters/swirl.d.ts.map +1 -1
  75. package/dist/passes/postprocessing/image-warp-filters/swirl.js +20 -15
  76. package/dist/passes/postprocessing/image-warp-filters/swirl.js.map +1 -1
  77. package/dist/passes/postprocessing/image-warp-filters/warp.d.ts +1 -1
  78. package/dist/passes/postprocessing/image-warp-filters/warp.d.ts.map +1 -1
  79. package/dist/passes/postprocessing/image-warp-filters/warp.js +9 -4
  80. package/dist/passes/postprocessing/image-warp-filters/warp.js.map +1 -1
  81. package/package.json +3 -3
  82. package/src/passes/postprocessing/fxaa/fxaa.ts +288 -0
  83. package/src/passes/postprocessing/image-adjust-filters/brightnesscontrast.ts +5 -6
  84. package/src/passes/postprocessing/image-adjust-filters/denoise.ts +34 -26
  85. package/src/passes/postprocessing/image-adjust-filters/huesaturation.ts +27 -34
  86. package/src/passes/postprocessing/image-adjust-filters/noise.ts +9 -8
  87. package/src/passes/postprocessing/image-adjust-filters/sepia.ts +11 -10
  88. package/src/passes/postprocessing/image-adjust-filters/vibrance.ts +9 -9
  89. package/src/passes/postprocessing/image-adjust-filters/vignette.ts +10 -14
  90. package/src/passes/postprocessing/image-blur-filters/tiltshift.ts +37 -19
  91. package/src/passes/postprocessing/image-blur-filters/triangleblur.ts +26 -17
  92. package/src/passes/postprocessing/image-blur-filters/zoomblur.ts +22 -13
  93. package/src/passes/postprocessing/image-fun-filters/colorhalftone.ts +19 -17
  94. package/src/passes/postprocessing/image-fun-filters/dotscreen.ts +11 -11
  95. package/src/passes/postprocessing/image-fun-filters/edgework.ts +85 -14
  96. package/src/passes/postprocessing/image-fun-filters/hexagonalpixelate.ts +38 -26
  97. package/src/passes/postprocessing/image-fun-filters/ink.ts +25 -16
  98. package/src/passes/postprocessing/image-fun-filters/magnify.ts +22 -12
  99. package/src/passes/postprocessing/image-warp-filters/bulgepinch.ts +27 -13
  100. package/src/passes/postprocessing/image-warp-filters/swirl.ts +20 -15
  101. package/src/passes/postprocessing/image-warp-filters/warp.ts +9 -4
@@ -6,42 +6,50 @@ import type {ShaderPass} from '@luma.gl/shadertools';
6
6
 
7
7
  // Do a 9x9 bilateral box filter
8
8
  const source = /* wgsl */ `\
9
-
10
9
  struct denoiseUniforms {
11
- strength: f32
10
+ strength: f32,
12
11
  };
13
12
 
14
- @group(0), @binding(1) var<uniform> denoise: denoiseUniforms;
15
-
16
- fn denoise_sampleColor(source: sampler2D, texSize: vec2<f32>, texCoord: vec2<f32>) -> vec4<f32> {
17
- let adjustedExponent: f32 = 3. + 200. * pow(1. - denoise.strength, 4.);
18
- let center: vec4<f32> = sample_texture(BUFFER_source, texCoord);
19
- var color: vec4<f32> = vec4<f32>(0.);
20
- var total: f32 = 0.;
21
-
22
- for (var x: f32 = -4.; x <= 4.; x = x + (1.)) {
23
-
24
- for (var y: f32 = -4.; y <= 4.; y = y + (1.)) {
25
- let offsetColor: vec4<f32> = sample_texture(BUFFER_source, texCoord + vec2<f32>(x, y) / texSize);
26
- var weight: f32 = 1. - abs(dot(offsetColor.rgb - center.rgb, vec3<f32>(0.25)));
27
- weight = pow(weight, adjustedExponent);
28
- color = color + (offsetColor * weight);
29
- total = total + (weight);
30
- }
31
-
32
- }
13
+ @group(0) @binding(auto) var<uniform> denoise: denoiseUniforms;
14
+
15
+ fn denoise_sampleColor(
16
+ sourceTexture: texture_2d<f32>,
17
+ sourceTextureSampler: sampler,
18
+ texSize: vec2f,
19
+ texCoord: vec2f
20
+ ) -> vec4f {
21
+ let adjustedExponent = 3.0 + 200.0 * pow(1.0 - denoise.strength, 4.0);
22
+ let center = textureSample(sourceTexture, sourceTextureSampler, texCoord);
23
+ var color = vec4f(0.0);
24
+ var total = 0.0;
25
+
26
+ for (var x = -4.0; x <= 4.0; x += 1.0) {
27
+ for (var y = -4.0; y <= 4.0; y += 1.0) {
28
+ let offsetColor = textureSample(
29
+ sourceTexture,
30
+ sourceTextureSampler,
31
+ texCoord + vec2f(x, y) / texSize
32
+ );
33
+ let weight = pow(
34
+ 1.0 - abs(dot(offsetColor.rgb - center.rgb, vec3f(0.25))),
35
+ adjustedExponent
36
+ );
37
+ color += offsetColor * weight;
38
+ total += weight;
39
+ }
40
+ }
33
41
 
34
- return color / total;
35
- }
42
+ return color / total;
43
+ }
36
44
  `;
37
45
 
38
46
  const fs = /* glsl */ `\
39
- uniform dedenoiseUniforms {
47
+ uniform denoiseUniforms {
40
48
  float strength;
41
49
  } denoise;
42
50
 
43
- vec4 dedenoise_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
44
- 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.);
45
53
 
46
54
  vec4 center = texture(source, texCoord);
47
55
  vec4 color = vec4(0.0);
@@ -5,45 +5,38 @@
5
5
  import type {ShaderPass} from '@luma.gl/shadertools';
6
6
 
7
7
  const source = /* wgsl */ `\
8
-
9
8
  struct hueSaturationUniforms {
10
9
  hue: f32,
11
10
  saturation: f32,
12
11
  };
13
12
 
14
- @group(0), @binding(1) var<uniform> hueSaturation: hueSaturationUniforms;
15
-
16
- fn hueSaturation_filterColor(color: vec4<f32>) -> vec4<f32> {
17
- let angle: f32 = hueSaturation.hue * 3.1415927;
18
- let s: f32 = sin(angle);
19
- let c: f32 = cos(angle);
20
- let weights: vec3<f32> = (vec3<f32>(2. * c, -sqrt(3.) * s - c, sqrt(3.) * s - c) + 1.) / 3.;
21
- let len: f32 = length(color.rgb);
22
- var colorrgb = color.rgb;
23
- colorrgb = vec3<f32>(dot(color.rgb, weights.xyz), dot(color.rgb, weights.zxy), dot(color.rgb, weights.yzx));
24
- color.r = colorrgb.x;
25
- color.g = colorrgb.y;
26
- color.b = colorrgb.z;
27
- let average: f32 = (color.r + color.g + color.b) / 3.;
28
- if (hueSaturation.saturation > 0.) {
29
- var colorrgb = color.rgb;
30
- colorrgb = color.rgb + ((average - color.rgb) * (1. - 1. / (1.001 - hueSaturation.saturation)));
31
- color.r = colorrgb.x;
32
- color.g = colorrgb.y;
33
- color.b = colorrgb.z;
34
- } else {
35
- var colorrgb = color.rgb;
36
- colorrgb = color.rgb + ((average - color.rgb) * -hueSaturation.saturation);
37
- color.r = colorrgb.x;
38
- color.g = colorrgb.y;
39
- color.b = colorrgb.z;
40
- }
41
- return color;
42
- }
43
-
44
- fn hueSaturation_filterColor_ext(color: vec4<f32>, texSize: vec2<f32>, texCoord: vec2<f32>) -> vec4<f32> {
45
- return hueSaturation_filterColor(color);
46
- }
13
+ @group(0) @binding(auto) var<uniform> hueSaturation: hueSaturationUniforms;
14
+
15
+ fn hueSaturation_filterColor(color: vec4f) -> vec4f {
16
+ let angle = hueSaturation.hue * 3.14159265;
17
+ let s = sin(angle);
18
+ let c = cos(angle);
19
+ let weights = (vec3f(2.0 * c, -sqrt(3.0) * s - c, sqrt(3.0) * s - c) + vec3f(1.0)) / 3.0;
20
+
21
+ var resultRgb = vec3f(
22
+ dot(color.rgb, weights.xyz),
23
+ dot(color.rgb, weights.zxy),
24
+ dot(color.rgb, weights.yzx)
25
+ );
26
+
27
+ let average = (resultRgb.r + resultRgb.g + resultRgb.b) / 3.0;
28
+ if (hueSaturation.saturation > 0.0) {
29
+ resultRgb += (vec3f(average) - resultRgb) * (1.0 - 1.0 / (1.001 - hueSaturation.saturation));
30
+ } else {
31
+ resultRgb += (vec3f(average) - resultRgb) * (-hueSaturation.saturation);
32
+ }
33
+
34
+ return vec4f(resultRgb, color.a);
35
+ }
36
+
37
+ fn hueSaturation_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) -> vec4f {
38
+ return hueSaturation_filterColor(color);
39
+ }
47
40
  `;
48
41
 
49
42
  const fs = /* glsl */ `\
@@ -6,22 +6,23 @@ import type {ShaderPass} from '@luma.gl/shadertools';
6
6
 
7
7
  const source = /* wgsl */ `\
8
8
  struct noiseUniforms {
9
- amount: f32
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);
16
16
  }
17
17
 
18
18
  fn noise_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) -> vec4f {
19
- let diff: f32 = (rand(texCoord) - 0.5) * noise.amount;
20
- color.r = color.r + (diff);
21
- color.g = color.g + (diff);
22
- color.b = color.b + (diff);
23
- return color;
24
- }
19
+ let diff = (rand(texCoord) - 0.5) * noise.amount;
20
+ var result = color;
21
+ result.r += diff;
22
+ result.g += diff;
23
+ result.b += diff;
24
+ return result;
25
+ }
25
26
  `;
26
27
 
27
28
  const fs = /* glsl */ `\
@@ -6,25 +6,26 @@ import type {ShaderPass} from '@luma.gl/shadertools';
6
6
 
7
7
  const source = /* wgsl */ `\
8
8
  struct sepiaUniforms {
9
- amount: f32
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
- let r: f32 = color.r;
16
- let g: f32 = color.g;
17
- let b: f32 = color.b;
15
+ let r = color.r;
16
+ let g = color.g;
17
+ let b = color.b;
18
18
 
19
- color.r =
19
+ var result = color;
20
+ result.r =
20
21
  min(1.0, (r * (1.0 - (0.607 * sepia.amount))) + (g * (0.769 * sepia.amount)) + (b * (0.189 * sepia.amount)));
21
- color.g = min(1.0, (r * 0.349 * sepia.amount) + (g * (1.0 - (0.314 * sepia.amount))) + (b * 0.168 * sepia.amount));
22
- color.b = min(1.0, (r * 0.272 * sepia.amount) + (g * 0.534 * sepia.amount) + (b * (1.0 - (0.869 * sepia.amount))));
22
+ result.g = min(1.0, (r * 0.349 * sepia.amount) + (g * (1.0 - (0.314 * sepia.amount))) + (b * 0.168 * sepia.amount));
23
+ result.b = min(1.0, (r * 0.272 * sepia.amount) + (g * 0.534 * sepia.amount) + (b * (1.0 - (0.869 * sepia.amount))));
23
24
 
24
- return color;
25
+ return result;
25
26
  }
26
27
 
27
- vec4 sepia_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
28
+ fn sepia_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) -> vec4f {
28
29
  return sepia_filterColor(color);
29
30
  }
30
31
  `;
@@ -6,20 +6,20 @@ import type {ShaderPass} from '@luma.gl/shadertools';
6
6
 
7
7
  const source = /* wgsl */ `\
8
8
  struct vibranceUniforms {
9
- amount: f32
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
- fn vibrance_filterColor(vec4f color) -> vec4f {
15
- let average: f32 = (color.r + color.g + color.b) / 3.0;
16
- let mx: f32 = max(color.r, max(color.g, color.b));
17
- let amt: f32 = (mx - average) * (-vibrance.amount * 3.0);
18
- color.rgb = mix(color.rgb, vec3(mx), amt);
19
- return color;
14
+ fn vibrance_filterColor(color: vec4f) -> vec4f {
15
+ let average = (color.r + color.g + color.b) / 3.0;
16
+ let mx = max(color.r, max(color.g, color.b));
17
+ let amt = (mx - average) * (-vibrance.amount * 3.0);
18
+ let resultRgb = mix(color.rgb, vec3f(mx), amt);
19
+ return vec4f(resultRgb, color.a);
20
20
  }
21
21
 
22
- vec4 vibrance_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
22
+ fn vibrance_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) -> vec4f {
23
23
  return vibrance_filterColor(color);
24
24
  }
25
25
  `;
@@ -7,23 +7,19 @@ import type {ShaderPass} from '@luma.gl/shadertools';
7
7
  const source = /* wgsl */ `\
8
8
  struct vignetteUniforms {
9
9
  radius: f32,
10
- amount: f32
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
- fn vibrance_filterColor(color: vec4f) -> vec4f {
16
- let average: f32 = (color.r + color.g + color.b) / 3.0;
17
- let mx: f32 = max(color.r, max(color.g, color.b));
18
- let amt: f32 = (mx - average) * (-vibrance.amount * 3.0);
19
- color.rgb = mix(color.rgb, vec3f(mx), amt);
20
- return color;
21
- }
22
-
23
- fn vignette_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) ->vec4f {
24
- let dist: f32 = distance(texCoord, vec2f(0.5, 0.5));
25
- let ratio: f32 = smoothstep(0.8, vignette.radius * 0.799, dist * (vignette.amount + vignette.radius));
26
- return color.rgba * ratio + (1.0 - ratio)*vec4f(0.0, 0.0, 0.0, 1.0);
15
+ fn vignette_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) -> vec4f {
16
+ let dist = distance(texCoord, vec2f(0.5, 0.5));
17
+ let ratio = smoothstep(
18
+ 0.8,
19
+ vignette.radius * 0.799,
20
+ dist * (vignette.amount + vignette.radius)
21
+ );
22
+ return color * ratio + vec4f(0.0, 0.0, 0.0, 1.0) * (1.0 - ratio);
27
23
  }
28
24
  `;
29
25
 
@@ -6,7 +6,7 @@ import type {ShaderPass} from '@luma.gl/shadertools';
6
6
  import {random} from '@luma.gl/shadertools';
7
7
 
8
8
  const source = /* wgsl */ `\
9
- uniform tiltShiftUniforms {
9
+ struct tiltShiftUniforms {
10
10
  blurRadius: f32,
11
11
  gradientRadius: f32,
12
12
  start: vec2f,
@@ -14,34 +14,52 @@ uniform 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
- fn tiltShift_getDelta(vec2 texSize) -> vec2f {
20
- vec2 vector = normalize((tiltShift.end - tiltShift.start) * texSize);
21
- return tiltShift.invert ? vec2(-vector.y, vector.x) : vector;
19
+ fn tiltShift_getDelta(texSize: vec2f) -> vec2f {
20
+ let vector = normalize((tiltShift.end - tiltShift.start) * texSize);
21
+ return select(vector, vec2f(-vector.y, vector.x), tiltShift.invert != 0u);
22
22
  }
23
23
 
24
- fn tiltShift_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) -> vec4f {
25
- vec4 color = vec4(0.0);
26
- float total = 0.0;
24
+ fn tiltShift_sampleColor(
25
+ sourceTexture: texture_2d<f32>,
26
+ sourceTextureSampler: sampler,
27
+ texSize: vec2f,
28
+ texCoord: vec2f
29
+ ) -> vec4f {
30
+ var color = vec4f(0.0);
31
+ var total = 0.0;
27
32
 
28
33
  /* randomize the lookup values to hide the fixed number of samples */
29
- float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
30
-
31
- vec2 normal = normalize(vec2((tiltShift.start.y - tiltShift.end.y) * texSize.y, (tiltShift.end.x - tiltShift.start.x) * texSize.x));
32
- float radius = smoothstep(0.0, 1.0,
33
- abs(dot(texCoord * texSize - tiltShift.start * texSize, normal)) / tiltShift.gradientRadius) * tiltShift.blurRadius;
34
-
35
- for (float t = -30.0; t <= 30.0; t++) {
36
- float percent = (t + offset - 0.5) / 30.0;
37
- float weight = 1.0 - abs(percent);
38
- vec4 offsetColor = texture(source, texCoord + tiltShift_getDelta(texSize) / texSize * percent * radius);
34
+ let offset = random(vec3f(12.9898, 78.233, 151.7182), 0.0);
35
+
36
+ let normal = normalize(
37
+ vec2f(
38
+ (tiltShift.start.y - tiltShift.end.y) * texSize.y,
39
+ (tiltShift.end.x - tiltShift.start.x) * texSize.x
40
+ )
41
+ );
42
+ let radius =
43
+ smoothstep(
44
+ 0.0,
45
+ 1.0,
46
+ abs(dot(texCoord * texSize - tiltShift.start * texSize, normal)) / tiltShift.gradientRadius
47
+ ) * tiltShift.blurRadius;
48
+
49
+ for (var t = -30.0; t <= 30.0; t += 1.0) {
50
+ let percent = (t + offset - 0.5) / 30.0;
51
+ let weight = 1.0 - abs(percent);
52
+ let offsetColor = textureSample(
53
+ sourceTexture,
54
+ sourceTextureSampler,
55
+ texCoord + tiltShift_getDelta(texSize) / texSize * percent * radius
56
+ );
39
57
 
40
58
  color += offsetColor * weight;
41
59
  total += weight;
42
60
  }
43
61
 
44
- color = color / total;
62
+ color /= total;
45
63
  return color;
46
64
  }
47
65
  `;
@@ -6,40 +6,49 @@ import type {ShaderPass} from '@luma.gl/shadertools';
6
6
  import {random} from '@luma.gl/shadertools';
7
7
 
8
8
  const source = /* wgsl */ `\
9
- uniform triangleBlurUniforms {
9
+ struct triangleBlurUniforms {
10
10
  radius: f32,
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
- vec4 triangleBlur_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
17
- vec2 adjustedDelta = triangleBlur.delta * triangleBlur.radius / texSize;
16
+ fn triangleBlur_sampleColor(
17
+ sourceTexture: texture_2d<f32>,
18
+ sourceTextureSampler: sampler,
19
+ texSize: vec2f,
20
+ texCoord: vec2f
21
+ ) -> vec4f {
22
+ let adjustedDelta = triangleBlur.delta * triangleBlur.radius / texSize;
18
23
 
19
- vec4 color = vec4(0.0);
20
- float total = 0.0;
24
+ var color = vec4f(0.0);
25
+ var total = 0.0;
21
26
 
22
27
  /* randomize the lookup values to hide the fixed number of samples */
23
- float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
28
+ let offset = random(vec3f(12.9898, 78.233, 151.7182), 0.0);
24
29
 
25
- for (float t = -30.0; t <= 30.0; t++) {
26
- float percent = (t + offset - 0.5) / 30.0;
27
- float weight = 1.0 - abs(percent);
28
- vec4 offsetColor = texture(source, texCoord + adjustedDelta * percent);
30
+ for (var t = -30.0; t <= 30.0; t += 1.0) {
31
+ let percent = (t + offset - 0.5) / 30.0;
32
+ let weight = 1.0 - abs(percent);
33
+ let offsetColor = textureSample(
34
+ sourceTexture,
35
+ sourceTextureSampler,
36
+ texCoord + adjustedDelta * percent
37
+ );
29
38
 
30
39
  /* switch to pre-multiplied alpha to correctly blur transparent images */
31
- offsetColor.rgb *= offsetColor.a;
40
+ let premultipliedOffsetColor = vec4f(offsetColor.rgb * vec3f(offsetColor.a), offsetColor.a);
32
41
 
33
- color += offsetColor * weight;
42
+ color += premultipliedOffsetColor * weight;
34
43
  total += weight;
35
44
  }
36
45
 
37
- color = color / total;
46
+ color /= total;
38
47
 
39
48
  /* switch back from pre-multiplied alpha */
40
- color.rgb /= color.a + 0.00001;
49
+ let unpremultipliedRgb = color.rgb / vec3f(color.a + 0.00001);
41
50
 
42
- return color;
51
+ return vec4f(unpremultipliedRgb, color.a);
43
52
  }
44
53
  `;
45
54
 
@@ -6,31 +6,40 @@ import type {ShaderPass} from '@luma.gl/shadertools';
6
6
  import {random} from '@luma.gl/shadertools';
7
7
 
8
8
  const source = /* wgsl */ `
9
- uniform zoomBlurUniforms {
9
+ struct zoomBlurUniforms {
10
10
  center: vec2f,
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
- fn zoomBlur_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) -> vec4f {
18
- vec4 color = vec4(0.0);
19
- float total = 0.0;
20
- vec2 toCenter = zoomBlur.center * texSize - texCoord * texSize;
17
+ fn zoomBlur_sampleColor(
18
+ sourceTexture: texture_2d<f32>,
19
+ sourceTextureSampler: sampler,
20
+ texSize: vec2f,
21
+ texCoord: vec2f
22
+ ) -> vec4f {
23
+ var color = vec4f(0.0);
24
+ var total = 0.0;
25
+ let toCenter = zoomBlur.center * texSize - texCoord * texSize;
21
26
 
22
27
  /* randomize the lookup values to hide the fixed number of samples */
23
- float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
24
-
25
- for (float t = 0.0; t <= 40.0; t++) {
26
- float percent = (t + offset) / 40.0;
27
- float weight = 4.0 * (percent - percent * percent);
28
- vec4 offsetColor = texture(source, texCoord + toCenter * percent * zoomBlur.strength / texSize);
28
+ let offset = random(vec3f(12.9898, 78.233, 151.7182), 0.0);
29
+
30
+ for (var t = 0.0; t <= 40.0; t += 1.0) {
31
+ let percent = (t + offset) / 40.0;
32
+ let weight = 4.0 * (percent - percent * percent);
33
+ let offsetColor = textureSample(
34
+ sourceTexture,
35
+ sourceTextureSampler,
36
+ texCoord + toCenter * percent * zoomBlur.strength / texSize
37
+ );
29
38
  color += offsetColor * weight;
30
39
  total += weight;
31
40
  }
32
41
 
33
- color = color / total;
42
+ color /= total;
34
43
  return color;
35
44
  }
36
45
  `;
@@ -8,38 +8,40 @@ const source = /* wgsl */ `\
8
8
  struct colorHalftoneUniforms {
9
9
  center: vec2f,
10
10
  angle: f32,
11
- size: f32.
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
- let s: f32 = sin(angle), c = cos(angle);
18
- let tex: vec2f = texCoord * texSize - colorHalftone.center * texSize;
19
- let point: vec2f = vec2(
20
- c * tex.x - s * tex.y,
21
- s * tex.x + c * tex.y
17
+ let s = sin(angle);
18
+ let c = cos(angle);
19
+ let tex = texCoord * texSize - colorHalftone.center * texSize;
20
+ let point = vec2f(
21
+ c * tex.x - s * tex.y,
22
+ s * tex.x + c * tex.y
22
23
  ) * scale;
23
24
  return (sin(point.x) * sin(point.y)) * 4.0;
24
25
  }
25
26
 
26
- fn colorHalftone_filterColor_ext(vec4f color, vec2f texSize, vec2f texCoord) -> vec4f {
27
- let scale: f32 = 3.1514 / colorHalftone.size;
28
- let cmy: vec3f = 1.0 - color.rgb;
29
- let k: f32 = min(cmy.x, min(cmy.y, cmy.z));
27
+ fn colorHalftone_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) -> vec4f {
28
+ let scale = 3.1514 / colorHalftone.size;
29
+ var cmy = vec3f(1.0) - color.rgb;
30
+ var k = min(cmy.x, min(cmy.y, cmy.z));
31
+ let safeDenominator = max(1.0 - k, 0.00001);
30
32
 
31
- cmy = (cmy - k) / (1.0 - k);
33
+ cmy = (cmy - vec3f(k)) / safeDenominator;
32
34
  cmy = clamp(
33
- cmy * 10.0 - 3.0 + vec3(
35
+ cmy * 10.0 - vec3f(3.0) + vec3f(
34
36
  pattern(colorHalftone.angle + 0.26179, scale, texSize, texCoord),
35
- pattern(colorHalftone.angle + 1.30899, scale, texSize, texCoord),
37
+ pattern(colorHalftone.angle + 1.30899, scale, texSize, texCoord),
36
38
  pattern(colorHalftone.angle, scale, texSize, texCoord)
37
39
  ),
38
- 0.0,
39
- 1.0
40
+ vec3f(0.0),
41
+ vec3f(1.0)
40
42
  );
41
43
  k = clamp(k * 10.0 - 5.0 + pattern(colorHalftone.angle + 0.78539, scale, texSize, texCoord), 0.0, 1.0);
42
- return vec4(1.0 - cmy - k, color.a);
44
+ return vec4f(vec3f(1.0) - cmy - vec3f(k), color.a);
43
45
  }
44
46
  `;
45
47
 
@@ -5,29 +5,29 @@
5
5
  import type {ShaderPass} from '@luma.gl/shadertools';
6
6
 
7
7
  const source = /* wgsl */ `\
8
- uniform dotScreenUniforms {
8
+ struct dotScreenUniforms {
9
9
  center: vec2f,
10
10
  angle: f32,
11
11
  size: f32,
12
12
  };
13
13
 
14
- @group(0) @binding(1) dotScreen: dotScreenUniforms;
14
+ @group(0) @binding(auto) var<uniform> dotScreen: dotScreenUniforms;
15
15
 
16
16
  fn pattern(texSize: vec2f, texCoord: vec2f) -> f32 {
17
- let scale: f32 = 3.1415 / dotScreen.size;
18
-
19
- let s: f32 = sin(dotScreen.angle), c = cos(dotScreen.angle);
20
- tex: vec2f = texCoord * texSize - dotScreen.center * texSize;
21
- point = vec2f(
22
- c: * tex.x - s * tex.y,
17
+ let scale = 3.1415 / dotScreen.size;
18
+ let s = sin(dotScreen.angle);
19
+ let c = cos(dotScreen.angle);
20
+ let tex = texCoord * texSize - dotScreen.center * texSize;
21
+ let point = vec2f(
22
+ c * tex.x - s * tex.y,
23
23
  s * tex.x + c * tex.y
24
24
  ) * scale;
25
25
  return (sin(point.x) * sin(point.y)) * 4.0;
26
26
  }
27
27
 
28
- fn dotScreen_filterColor_ext(vec4 color, texSize: vec2f, texCoord: vec2f) -> vec4f {
29
- let average: f32 = (color.r + color.g + color.b) / 3.0;
30
- return vec4(vec3(average * 10.0 - 5.0 + pattern(texSize, texCoord)), color.a);
28
+ fn dotScreen_filterColor_ext(color: vec4f, texSize: vec2f, texCoord: vec2f) -> vec4f {
29
+ let average = (color.r + color.g + color.b) / 3.0;
30
+ return vec4f(vec3f(average * 10.0 - 5.0 + pattern(texSize, texCoord)), color.a);
31
31
  }
32
32
  `;
33
33