@flighthq/effects-wgpu 0.1.0 → 0.2.1-next.410.a23f189

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 (256) hide show
  1. package/dist/index.d.ts +17 -10
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +17 -10
  4. package/dist/index.js.map +1 -1
  5. package/dist/wgpuBevelEffect.d.ts +4 -0
  6. package/dist/wgpuBevelEffect.d.ts.map +1 -0
  7. package/dist/wgpuBevelEffect.js +124 -0
  8. package/dist/wgpuBevelEffect.js.map +1 -0
  9. package/dist/wgpuBloomEffect.d.ts.map +1 -1
  10. package/dist/wgpuBloomEffect.js +9 -8
  11. package/dist/wgpuBloomEffect.js.map +1 -1
  12. package/dist/wgpuBlurEffect.d.ts +8 -0
  13. package/dist/wgpuBlurEffect.d.ts.map +1 -0
  14. package/dist/wgpuBlurEffect.js +70 -0
  15. package/dist/wgpuBlurEffect.js.map +1 -0
  16. package/dist/wgpuBokehDepthOfFieldEffect.d.ts.map +1 -1
  17. package/dist/wgpuBokehDepthOfFieldEffect.js +2 -2
  18. package/dist/wgpuBokehDepthOfFieldEffect.js.map +1 -1
  19. package/dist/wgpuCameraMotionBlurEffect.d.ts.map +1 -1
  20. package/dist/wgpuCameraMotionBlurEffect.js +2 -2
  21. package/dist/wgpuCameraMotionBlurEffect.js.map +1 -1
  22. package/dist/wgpuChromaticAberrationEffect.d.ts.map +1 -1
  23. package/dist/wgpuChromaticAberrationEffect.js +2 -2
  24. package/dist/wgpuChromaticAberrationEffect.js.map +1 -1
  25. package/dist/wgpuColorLutPass.d.ts +3 -0
  26. package/dist/wgpuColorLutPass.d.ts.map +1 -0
  27. package/dist/wgpuColorLutPass.js +144 -0
  28. package/dist/wgpuColorLutPass.js.map +1 -0
  29. package/dist/wgpuColorMatrixPass.d.ts +3 -0
  30. package/dist/wgpuColorMatrixPass.d.ts.map +1 -0
  31. package/dist/wgpuColorMatrixPass.js +51 -0
  32. package/dist/wgpuColorMatrixPass.js.map +1 -0
  33. package/dist/wgpuConvolutionEffect.d.ts +5 -0
  34. package/dist/wgpuConvolutionEffect.d.ts.map +1 -0
  35. package/dist/wgpuConvolutionEffect.js +108 -0
  36. package/dist/wgpuConvolutionEffect.js.map +1 -0
  37. package/dist/wgpuCrtEffect.d.ts.map +1 -1
  38. package/dist/wgpuCrtEffect.js +2 -2
  39. package/dist/wgpuCrtEffect.js.map +1 -1
  40. package/dist/wgpuDirectionalBlurEffect.d.ts.map +1 -1
  41. package/dist/wgpuDirectionalBlurEffect.js +2 -2
  42. package/dist/wgpuDirectionalBlurEffect.js.map +1 -1
  43. package/dist/wgpuDisplacementEffect.d.ts.map +1 -1
  44. package/dist/wgpuDisplacementEffect.js +2 -2
  45. package/dist/wgpuDisplacementEffect.js.map +1 -1
  46. package/dist/wgpuDitherEffect.d.ts.map +1 -1
  47. package/dist/wgpuDitherEffect.js +2 -2
  48. package/dist/wgpuDitherEffect.js.map +1 -1
  49. package/dist/wgpuDropShadowEffect.d.ts +4 -0
  50. package/dist/wgpuDropShadowEffect.d.ts.map +1 -0
  51. package/dist/wgpuDropShadowEffect.js +50 -0
  52. package/dist/wgpuDropShadowEffect.js.map +1 -0
  53. package/dist/wgpuEffectBlitShader.d.ts +17 -0
  54. package/dist/wgpuEffectBlitShader.d.ts.map +1 -0
  55. package/dist/wgpuEffectBlitShader.js +97 -0
  56. package/dist/wgpuEffectBlitShader.js.map +1 -0
  57. package/dist/wgpuEffectBoxBlur.d.ts +15 -0
  58. package/dist/wgpuEffectBoxBlur.d.ts.map +1 -0
  59. package/dist/wgpuEffectBoxBlur.js +106 -0
  60. package/dist/wgpuEffectBoxBlur.js.map +1 -0
  61. package/dist/wgpuEffectGradientRamp.d.ts +17 -0
  62. package/dist/wgpuEffectGradientRamp.d.ts.map +1 -0
  63. package/dist/wgpuEffectGradientRamp.js +89 -0
  64. package/dist/wgpuEffectGradientRamp.js.map +1 -0
  65. package/dist/wgpuEffectPass.d.ts +42 -0
  66. package/dist/wgpuEffectPass.d.ts.map +1 -0
  67. package/dist/wgpuEffectPass.js +271 -0
  68. package/dist/wgpuEffectPass.js.map +1 -0
  69. package/dist/wgpuEffectProgramCache.d.ts +2 -2
  70. package/dist/wgpuEffectProgramCache.d.ts.map +1 -1
  71. package/dist/wgpuEffectProgramCache.js +5 -5
  72. package/dist/wgpuEffectProgramCache.js.map +1 -1
  73. package/dist/wgpuEffectTintShader.d.ts +8 -0
  74. package/dist/wgpuEffectTintShader.d.ts.map +1 -0
  75. package/dist/wgpuEffectTintShader.js +109 -0
  76. package/dist/wgpuEffectTintShader.js.map +1 -0
  77. package/dist/wgpuFilmGrainEffect.d.ts.map +1 -1
  78. package/dist/wgpuFilmGrainEffect.js +2 -2
  79. package/dist/wgpuFilmGrainEffect.js.map +1 -1
  80. package/dist/wgpuFxaaEffect.d.ts.map +1 -1
  81. package/dist/wgpuFxaaEffect.js +2 -2
  82. package/dist/wgpuFxaaEffect.js.map +1 -1
  83. package/dist/wgpuGlitchEffect.d.ts.map +1 -1
  84. package/dist/wgpuGlitchEffect.js +2 -2
  85. package/dist/wgpuGlitchEffect.js.map +1 -1
  86. package/dist/wgpuGodRaysEffect.d.ts.map +1 -1
  87. package/dist/wgpuGodRaysEffect.js +2 -2
  88. package/dist/wgpuGodRaysEffect.js.map +1 -1
  89. package/dist/wgpuGradientBevelEffect.d.ts +4 -0
  90. package/dist/wgpuGradientBevelEffect.d.ts.map +1 -0
  91. package/dist/wgpuGradientBevelEffect.js +191 -0
  92. package/dist/wgpuGradientBevelEffect.js.map +1 -0
  93. package/dist/wgpuGradientGlowEffect.d.ts +4 -0
  94. package/dist/wgpuGradientGlowEffect.d.ts.map +1 -0
  95. package/dist/wgpuGradientGlowEffect.js +103 -0
  96. package/dist/wgpuGradientGlowEffect.js.map +1 -0
  97. package/dist/wgpuHalftoneEffect.d.ts.map +1 -1
  98. package/dist/wgpuHalftoneEffect.js +2 -2
  99. package/dist/wgpuHalftoneEffect.js.map +1 -1
  100. package/dist/wgpuInnerGlowEffect.d.ts +4 -0
  101. package/dist/wgpuInnerGlowEffect.d.ts.map +1 -0
  102. package/dist/wgpuInnerGlowEffect.js +50 -0
  103. package/dist/wgpuInnerGlowEffect.js.map +1 -0
  104. package/dist/wgpuInnerShadowEffect.d.ts +4 -0
  105. package/dist/wgpuInnerShadowEffect.d.ts.map +1 -0
  106. package/dist/wgpuInnerShadowEffect.js +55 -0
  107. package/dist/wgpuInnerShadowEffect.js.map +1 -0
  108. package/dist/wgpuKuwaharaEffect.d.ts.map +1 -1
  109. package/dist/wgpuKuwaharaEffect.js +2 -2
  110. package/dist/wgpuKuwaharaEffect.js.map +1 -1
  111. package/dist/wgpuLensDirtEffect.d.ts.map +1 -1
  112. package/dist/wgpuLensDirtEffect.js +2 -2
  113. package/dist/wgpuLensDirtEffect.js.map +1 -1
  114. package/dist/wgpuLensDistortionEffect.d.ts.map +1 -1
  115. package/dist/wgpuLensDistortionEffect.js +2 -2
  116. package/dist/wgpuLensDistortionEffect.js.map +1 -1
  117. package/dist/wgpuLensFlareEffect.d.ts.map +1 -1
  118. package/dist/wgpuLensFlareEffect.js +2 -2
  119. package/dist/wgpuLensFlareEffect.js.map +1 -1
  120. package/dist/wgpuMedianEffect.d.ts +5 -0
  121. package/dist/wgpuMedianEffect.d.ts.map +1 -0
  122. package/dist/wgpuMedianEffect.js +74 -0
  123. package/dist/wgpuMedianEffect.js.map +1 -0
  124. package/dist/wgpuMotionBlurEffect.d.ts.map +1 -1
  125. package/dist/wgpuMotionBlurEffect.js +6 -7
  126. package/dist/wgpuMotionBlurEffect.js.map +1 -1
  127. package/dist/wgpuOuterGlowEffect.d.ts +4 -0
  128. package/dist/wgpuOuterGlowEffect.d.ts.map +1 -0
  129. package/dist/wgpuOuterGlowEffect.js +46 -0
  130. package/dist/wgpuOuterGlowEffect.js.map +1 -0
  131. package/dist/wgpuOutlineEffect.d.ts.map +1 -1
  132. package/dist/wgpuOutlineEffect.js +2 -2
  133. package/dist/wgpuOutlineEffect.js.map +1 -1
  134. package/dist/wgpuPixelateEffect.d.ts.map +1 -1
  135. package/dist/wgpuPixelateEffect.js +2 -2
  136. package/dist/wgpuPixelateEffect.js.map +1 -1
  137. package/dist/wgpuPosterizeEffect.d.ts.map +1 -1
  138. package/dist/wgpuPosterizeEffect.js +2 -2
  139. package/dist/wgpuPosterizeEffect.js.map +1 -1
  140. package/dist/wgpuRadialBlurEffect.d.ts.map +1 -1
  141. package/dist/wgpuRadialBlurEffect.js +2 -2
  142. package/dist/wgpuRadialBlurEffect.js.map +1 -1
  143. package/dist/wgpuRenderEffectPipeline.d.ts +2 -2
  144. package/dist/wgpuRenderEffectPipeline.d.ts.map +1 -1
  145. package/dist/wgpuRenderEffectPipeline.js +74 -15
  146. package/dist/wgpuRenderEffectPipeline.js.map +1 -1
  147. package/dist/wgpuRenderEffectRegistrants.d.ts +1 -0
  148. package/dist/wgpuRenderEffectRegistrants.d.ts.map +1 -1
  149. package/dist/wgpuRenderEffectRegistrants.js +39 -28
  150. package/dist/wgpuRenderEffectRegistrants.js.map +1 -1
  151. package/dist/wgpuScanlinesEffect.d.ts.map +1 -1
  152. package/dist/wgpuScanlinesEffect.js +2 -2
  153. package/dist/wgpuScanlinesEffect.js.map +1 -1
  154. package/dist/wgpuScreenSpaceFogEffect.d.ts.map +1 -1
  155. package/dist/wgpuScreenSpaceFogEffect.js +2 -2
  156. package/dist/wgpuScreenSpaceFogEffect.js.map +1 -1
  157. package/dist/wgpuSharpenEffect.d.ts.map +1 -1
  158. package/dist/wgpuSharpenEffect.js +2 -2
  159. package/dist/wgpuSharpenEffect.js.map +1 -1
  160. package/dist/wgpuSketchEffect.d.ts.map +1 -1
  161. package/dist/wgpuSketchEffect.js +2 -2
  162. package/dist/wgpuSketchEffect.js.map +1 -1
  163. package/dist/wgpuSmaaEffect.d.ts.map +1 -1
  164. package/dist/wgpuSmaaEffect.js +2 -2
  165. package/dist/wgpuSmaaEffect.js.map +1 -1
  166. package/dist/wgpuSsaoEffect.d.ts.map +1 -1
  167. package/dist/wgpuSsaoEffect.js +2 -2
  168. package/dist/wgpuSsaoEffect.js.map +1 -1
  169. package/dist/wgpuSsrEffect.d.ts.map +1 -1
  170. package/dist/wgpuSsrEffect.js +2 -2
  171. package/dist/wgpuSsrEffect.js.map +1 -1
  172. package/dist/wgpuTaaEffect.d.ts.map +1 -1
  173. package/dist/wgpuTaaEffect.js +2 -2
  174. package/dist/wgpuTaaEffect.js.map +1 -1
  175. package/dist/wgpuTiltShiftEffect.d.ts.map +1 -1
  176. package/dist/wgpuTiltShiftEffect.js +2 -2
  177. package/dist/wgpuTiltShiftEffect.js.map +1 -1
  178. package/dist/wgpuToneMapEffect.d.ts.map +1 -1
  179. package/dist/wgpuToneMapEffect.js +2 -2
  180. package/dist/wgpuToneMapEffect.js.map +1 -1
  181. package/dist/wgpuVignetteEffect.d.ts.map +1 -1
  182. package/dist/wgpuVignetteEffect.js +2 -2
  183. package/dist/wgpuVignetteEffect.js.map +1 -1
  184. package/dist/wgpuWhiteBalanceEffect.d.ts.map +1 -1
  185. package/dist/wgpuWhiteBalanceEffect.js +2 -2
  186. package/dist/wgpuWhiteBalanceEffect.js.map +1 -1
  187. package/package.json +11 -7
  188. package/src/wgpuBevelEffect.test.ts +13 -0
  189. package/src/wgpuBlurEffect.test.ts +19 -0
  190. package/src/wgpuColorLutPass.test.ts +7 -0
  191. package/src/wgpuColorMatrixPass.test.ts +7 -0
  192. package/src/wgpuConvolutionEffect.test.ts +13 -0
  193. package/src/wgpuDropShadowEffect.test.ts +109 -0
  194. package/src/wgpuEffectBlitShader.test.ts +23 -0
  195. package/src/wgpuEffectBoxBlur.test.ts +75 -0
  196. package/src/wgpuEffectGradientRamp.test.ts +7 -0
  197. package/src/wgpuEffectPass.test.ts +51 -0
  198. package/src/wgpuEffectTintShader.test.ts +66 -0
  199. package/src/wgpuGradientBevelEffect.test.ts +13 -0
  200. package/src/wgpuGradientGlowEffect.test.ts +13 -0
  201. package/src/wgpuInnerGlowEffect.test.ts +137 -0
  202. package/src/wgpuInnerShadowEffect.test.ts +137 -0
  203. package/src/wgpuMedianEffect.test.ts +13 -0
  204. package/src/wgpuOuterGlowEffect.test.ts +108 -0
  205. package/src/wgpuRenderEffectPipeline.test.ts +2 -0
  206. package/src/wgpuRenderEffectRegistrants.test.ts +25 -14
  207. package/dist/wgpuBrightnessContrastEffect.d.ts +0 -4
  208. package/dist/wgpuBrightnessContrastEffect.d.ts.map +0 -1
  209. package/dist/wgpuBrightnessContrastEffect.js +0 -29
  210. package/dist/wgpuBrightnessContrastEffect.js.map +0 -1
  211. package/dist/wgpuChannelMixerEffect.d.ts +0 -4
  212. package/dist/wgpuChannelMixerEffect.d.ts.map +0 -1
  213. package/dist/wgpuChannelMixerEffect.js +0 -34
  214. package/dist/wgpuChannelMixerEffect.js.map +0 -1
  215. package/dist/wgpuColorGradeEffect.d.ts +0 -4
  216. package/dist/wgpuColorGradeEffect.d.ts.map +0 -1
  217. package/dist/wgpuColorGradeEffect.js +0 -52
  218. package/dist/wgpuColorGradeEffect.js.map +0 -1
  219. package/dist/wgpuExposureEffect.d.ts +0 -4
  220. package/dist/wgpuExposureEffect.d.ts.map +0 -1
  221. package/dist/wgpuExposureEffect.js +0 -28
  222. package/dist/wgpuExposureEffect.js.map +0 -1
  223. package/dist/wgpuGrayscaleEffect.d.ts +0 -4
  224. package/dist/wgpuGrayscaleEffect.d.ts.map +0 -1
  225. package/dist/wgpuGrayscaleEffect.js +0 -27
  226. package/dist/wgpuGrayscaleEffect.js.map +0 -1
  227. package/dist/wgpuHueSaturationEffect.d.ts +0 -4
  228. package/dist/wgpuHueSaturationEffect.d.ts.map +0 -1
  229. package/dist/wgpuHueSaturationEffect.js +0 -75
  230. package/dist/wgpuHueSaturationEffect.js.map +0 -1
  231. package/dist/wgpuInvertEffect.d.ts +0 -4
  232. package/dist/wgpuInvertEffect.d.ts.map +0 -1
  233. package/dist/wgpuInvertEffect.js +0 -26
  234. package/dist/wgpuInvertEffect.js.map +0 -1
  235. package/dist/wgpuLiftGammaGainEffect.d.ts +0 -4
  236. package/dist/wgpuLiftGammaGainEffect.d.ts.map +0 -1
  237. package/dist/wgpuLiftGammaGainEffect.js +0 -51
  238. package/dist/wgpuLiftGammaGainEffect.js.map +0 -1
  239. package/dist/wgpuLookupTableGradeEffect.d.ts +0 -4
  240. package/dist/wgpuLookupTableGradeEffect.d.ts.map +0 -1
  241. package/dist/wgpuLookupTableGradeEffect.js +0 -30
  242. package/dist/wgpuLookupTableGradeEffect.js.map +0 -1
  243. package/dist/wgpuSepiaEffect.d.ts +0 -4
  244. package/dist/wgpuSepiaEffect.d.ts.map +0 -1
  245. package/dist/wgpuSepiaEffect.js +0 -31
  246. package/dist/wgpuSepiaEffect.js.map +0 -1
  247. package/src/wgpuBrightnessContrastEffect.test.ts +0 -16
  248. package/src/wgpuChannelMixerEffect.test.ts +0 -13
  249. package/src/wgpuColorGradeEffect.test.ts +0 -13
  250. package/src/wgpuExposureEffect.test.ts +0 -13
  251. package/src/wgpuGrayscaleEffect.test.ts +0 -13
  252. package/src/wgpuHueSaturationEffect.test.ts +0 -13
  253. package/src/wgpuInvertEffect.test.ts +0 -13
  254. package/src/wgpuLiftGammaGainEffect.test.ts +0 -13
  255. package/src/wgpuLookupTableGradeEffect.test.ts +0 -16
  256. package/src/wgpuSepiaEffect.test.ts +0 -13
@@ -0,0 +1,97 @@
1
+ import { createWgpuEffectPipeline, drawWgpuEffectPass } from './wgpuEffectPass';
2
+ // Blits a texture at a UV offset. Out-of-bounds samples produce transparent output.
3
+ const BLIT_OFFSET_WGSL = /* wgsl */ `
4
+ struct Uniforms {
5
+ offset : vec2f,
6
+ _pad : vec2f,
7
+ }
8
+ @group(0) @binding(0) var<uniform> uni : Uniforms;
9
+ @group(1) @binding(0) var tex : texture_2d<f32>;
10
+ @group(1) @binding(1) var smp : sampler;
11
+
12
+ @fragment
13
+ fn fs_main(@location(0) uv : vec2f) -> @location(0) vec4f {
14
+ let shifted = uv + uni.offset;
15
+ if (shifted.x < 0.0 || shifted.x > 1.0 || shifted.y < 0.0 || shifted.y > 1.0) {
16
+ return vec4f(0.0);
17
+ }
18
+ return textureSampleLevel(tex, smp, shifted, 0.0);
19
+ }`;
20
+ // Pass-through blit. Minimal uniform struct required by the pipeline layout.
21
+ const BLIT_WGSL = /* wgsl */ `
22
+ struct Uniforms { _u : f32, _pad0 : f32, _pad1 : f32, _pad2 : f32, }
23
+ @group(0) @binding(0) var<uniform> uni : Uniforms;
24
+ @group(1) @binding(0) var tex : texture_2d<f32>;
25
+ @group(1) @binding(1) var smp : sampler;
26
+
27
+ @fragment
28
+ fn fs_main(@location(0) uv : vec2f) -> @location(0) vec4f {
29
+ return textureSampleLevel(tex, smp, uv, 0.0);
30
+ }`;
31
+ // Emits source alpha for a destination-out erase pass; blend state supplies the coverage operator.
32
+ const ERASE_WGSL = /* wgsl */ `
33
+ struct Uniforms { _u : f32, _pad0 : f32, _pad1 : f32, _pad2 : f32, }
34
+ @group(0) @binding(0) var<uniform> uni : Uniforms;
35
+ @group(1) @binding(0) var tex : texture_2d<f32>;
36
+ @group(1) @binding(1) var smp : sampler;
37
+
38
+ @fragment
39
+ fn fs_main(@location(0) uv : vec2f) -> @location(0) vec4f {
40
+ let a = textureSampleLevel(tex, smp, uv, 0.0).a;
41
+ return vec4f(0.0, 0.0, 0.0, a);
42
+ }`;
43
+ /**
44
+ * Blits source into dest at a pixel offset (dx, dy in screen-space Y-down).
45
+ * Pixels sampling outside the source bounds produce transparent output.
46
+ *
47
+ * The offset matches the Gl path exactly — (-dx/w, +dy/h). The shader samples `uv + offset`, so a
48
+ * screen-space shift of (+dx,+dy) needs offset (-dx, +dy): the +dy is NOT negated for Wgpu. Wgpu's UV
49
+ * y=0 is top (opposite Gl's bottom-origin) but Wgpu render-target textures are also stored top-down, so
50
+ * the two inversions cancel. A previous extra Y negation put the shadow on the wrong side of the source
51
+ * (it landed up-left instead of down-right) — caught by filter-drop-shadow-parity.
52
+ */
53
+ export function applyWgpuEffectBlitOffsetPass(state, source, dest, dx, dy) {
54
+ const pipeline = getWgpuBlitOffsetShader(state);
55
+ drawWgpuEffectPass(state, source, dest, pipeline, (f32) => {
56
+ f32[0] = -dx / source.width;
57
+ f32[1] = dy / source.height;
58
+ });
59
+ }
60
+ /** Blits source directly into dest without modification. */
61
+ export function applyWgpuEffectBlitPass(state, source, dest) {
62
+ const pipeline = getWgpuBlitShader(state);
63
+ drawWgpuEffectPass(state, source, dest, pipeline, () => { });
64
+ }
65
+ /** Erases dest by the source alpha mask, equivalent to destination-out compositing. */
66
+ export function applyWgpuEffectErasePass(state, source, dest) {
67
+ const pipeline = getWgpuEraseShader(state);
68
+ drawWgpuEffectPass(state, source, dest, pipeline, () => { });
69
+ }
70
+ function getWgpuBlitOffsetShader(state) {
71
+ let p = blitOffsetPipelines.get(state);
72
+ if (p === undefined) {
73
+ p = createWgpuEffectPipeline(state, BLIT_OFFSET_WGSL);
74
+ blitOffsetPipelines.set(state, p);
75
+ }
76
+ return p;
77
+ }
78
+ function getWgpuBlitShader(state) {
79
+ let p = blitPipelines.get(state);
80
+ if (p === undefined) {
81
+ p = createWgpuEffectPipeline(state, BLIT_WGSL);
82
+ blitPipelines.set(state, p);
83
+ }
84
+ return p;
85
+ }
86
+ function getWgpuEraseShader(state) {
87
+ let p = erasePipelines.get(state);
88
+ if (p === undefined) {
89
+ p = createWgpuEffectPipeline(state, ERASE_WGSL, 'erase');
90
+ erasePipelines.set(state, p);
91
+ }
92
+ return p;
93
+ }
94
+ const blitOffsetPipelines = new WeakMap();
95
+ const blitPipelines = new WeakMap();
96
+ const erasePipelines = new WeakMap();
97
+ //# sourceMappingURL=wgpuEffectBlitShader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wgpuEffectBlitShader.js","sourceRoot":"","sources":["../src/wgpuEffectBlitShader.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE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AS,uBAAuB,CAAC,KAAsB;IACrD,IAAI,CAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACvC,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;QACpB,CAAC,GAAG,wBAAwB,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;QACtD,mBAAmB,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAsB;IAC/C,IAAI,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjC,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;QACpB,CAAC,GAAG,wBAAwB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QAC/C,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAsB;IAChD,IAAI,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;QACpB,CAAC,GAAG,wBAAwB,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;QACzD,cAAc,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAAuC,CAAC;AAC/E,MAAM,aAAa,GAAG,IAAI,OAAO,EAAuC,CAAC;AACzE,MAAM,cAAc,GAAG,IAAI,OAAO,EAAuC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { WgpuRenderState, WgpuRenderTarget } from '@flighthq/types';
2
+ /**
3
+ * Applies a separable box blur to `source`, writing to `dest`. `blurX`/`blurY` are
4
+ * the target Gaussian standard deviations; `passes` is the number of box passes per
5
+ * axis (more passes converge on a Gaussian — see `computeBoxBlurPassRadius`). A box
6
+ * blur is cheap and right for soft spreads. `temp` is a caller-provided ping-pong
7
+ * scratch target distinct from both `source` and `dest`.
8
+ */
9
+ export declare function applyWgpuEffectBoxBlur(state: WgpuRenderState, source: WgpuRenderTarget, dest: WgpuRenderTarget, temp: WgpuRenderTarget, options: Readonly<{
10
+ blurX?: number;
11
+ blurY?: number;
12
+ passes?: number;
13
+ edgeColor?: readonly [number, number, number, number];
14
+ }>): void;
15
+ //# sourceMappingURL=wgpuEffectBoxBlur.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wgpuEffectBoxBlur.d.ts","sourceRoot":"","sources":["../src/wgpuEffectBoxBlur.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AA8CzE;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,eAAe,EACtB,MAAM,EAAE,gBAAgB,EACxB,IAAI,EAAE,gBAAgB,EACtB,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,QAAQ,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CACvD,CAAC,GACD,IAAI,CA2BN"}
@@ -0,0 +1,106 @@
1
+ import { computeBoxBlurPassRadius } from '@flighthq/effects';
2
+ import { createWgpuEffectPipeline, drawWgpuEffectPass } from './wgpuEffectPass';
3
+ // Uniforms layout:
4
+ // offset 0: texelSize (vec2f)
5
+ // offset 8: direction (vec2f)
6
+ // offset 16: edgeColor (vec4f)
7
+ // offset 32: radius (f32)
8
+ // offset 36: useEdgeColor (f32)
9
+ // offset 40-47: padding
10
+ const BOX_BLUR_WGSL = /* wgsl */ `
11
+ struct Uniforms {
12
+ texelSize : vec2f,
13
+ direction : vec2f,
14
+ edgeColor : vec4f,
15
+ radius : f32,
16
+ useEdgeColor : f32,
17
+ _pad0 : f32, _pad1 : f32,
18
+ }
19
+ @group(0) @binding(0) var<uniform> uni : Uniforms;
20
+ @group(1) @binding(0) var tex : texture_2d<f32>;
21
+ @group(1) @binding(1) var smp : sampler;
22
+
23
+ fn sampleBlur(uv : vec2f) -> vec4f {
24
+ if (uni.useEdgeColor > 0.5 && (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0)) {
25
+ return uni.edgeColor;
26
+ }
27
+ return textureSampleLevel(tex, smp, uv, 0.0);
28
+ }
29
+
30
+ @fragment
31
+ fn fs_main(@location(0) uv : vec2f) -> @location(0) vec4f {
32
+ let r = i32(uni.radius);
33
+ if (r == 0) { return sampleBlur(uv); }
34
+ var sum = vec4f(0.0);
35
+ let count = f32(2 * r + 1);
36
+ for (var i = -r; i <= r; i++) {
37
+ sum += sampleBlur(uv + f32(i) * uni.texelSize * uni.direction);
38
+ }
39
+ return sum / count;
40
+ }`;
41
+ /**
42
+ * Applies a separable box blur to `source`, writing to `dest`. `blurX`/`blurY` are
43
+ * the target Gaussian standard deviations; `passes` is the number of box passes per
44
+ * axis (more passes converge on a Gaussian — see `computeBoxBlurPassRadius`). A box
45
+ * blur is cheap and right for soft spreads. `temp` is a caller-provided ping-pong
46
+ * scratch target distinct from both `source` and `dest`.
47
+ */
48
+ export function applyWgpuEffectBoxBlur(state, source, dest, temp, options) {
49
+ const passes = Math.max(1, Math.round(options.passes ?? 1));
50
+ const blurX = options.blurX ?? 4;
51
+ const blurY = options.blurY ?? 4;
52
+ const edgeColor = options.edgeColor;
53
+ let read = source;
54
+ let write = temp;
55
+ for (let pass = 0; pass < passes; pass++) {
56
+ const radiusX = computeBoxBlurPassRadius(blurX, passes, pass);
57
+ if (radiusX > 0) {
58
+ applyBoxBlurPass(state, read, write, radiusX, 1, 0, edgeColor);
59
+ read = write;
60
+ write = write === temp ? dest : temp;
61
+ }
62
+ const radiusY = computeBoxBlurPassRadius(blurY, passes, pass);
63
+ if (radiusY > 0) {
64
+ applyBoxBlurPass(state, read, write, radiusY, 0, 1, edgeColor);
65
+ read = write;
66
+ write = write === temp ? dest : temp;
67
+ }
68
+ }
69
+ if (read !== dest) {
70
+ applyBoxBlurPass(state, read, dest, 0, 0, 0, undefined);
71
+ }
72
+ }
73
+ function applyBoxBlurPass(state, source, dest, radius, dirX, dirY, edgeColor) {
74
+ const pipeline = getBoxBlurPipeline(state);
75
+ drawWgpuEffectPass(state, source, dest, pipeline, (f32) => {
76
+ f32[0] = 1 / source.width;
77
+ f32[1] = 1 / source.height;
78
+ f32[2] = dirX;
79
+ f32[3] = dirY;
80
+ if (edgeColor === undefined) {
81
+ f32[4] = 0;
82
+ f32[5] = 0;
83
+ f32[6] = 0;
84
+ f32[7] = 0;
85
+ f32[9] = 0;
86
+ }
87
+ else {
88
+ f32[4] = edgeColor[0];
89
+ f32[5] = edgeColor[1];
90
+ f32[6] = edgeColor[2];
91
+ f32[7] = edgeColor[3];
92
+ f32[9] = 1;
93
+ }
94
+ f32[8] = radius;
95
+ });
96
+ }
97
+ function getBoxBlurPipeline(state) {
98
+ let p = boxBlurPipelines.get(state);
99
+ if (p === undefined) {
100
+ p = createWgpuEffectPipeline(state, BOX_BLUR_WGSL, 'replace');
101
+ boxBlurPipelines.set(state, p);
102
+ }
103
+ return p;
104
+ }
105
+ const boxBlurPipelines = new WeakMap();
106
+ //# sourceMappingURL=wgpuEffectBoxBlur.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wgpuEffectBoxBlur.js","sourceRoot":"","sources":["../src/wgpuEffectBoxBlur.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAI7D,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,kB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AG,CAAC,CAAC;QACb,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YACtB,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YACtB,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YACtB,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YACtB,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACb,CAAC;QACD,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAsB;IAChD,IAAI,CAAC,GAAG,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;QACpB,CAAC,GAAG,wBAAwB,CAAC,KAAK,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;QAC9D,gBAAgB,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAAuC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { WgpuRenderState } from '@flighthq/types';
2
+ /**
3
+ * Returns a cached 256-entry RGBA gradient ramp texture for the given stops,
4
+ * building it on first use and reusing it on later calls with the same stops.
5
+ * The texture is owned by the render state and lives for its lifetime — callers
6
+ * must NOT destroy it. This is the form recipes should use: a recipe runs inside
7
+ * the frame's command encoder and does not control submit timing, so it cannot
8
+ * safely `destroy()` a per-call texture (the encoder still references it at
9
+ * submit, which discards the whole frame). Caching also avoids a per-frame
10
+ * allocation. Distinct stop sets get distinct textures, so multiple gradient
11
+ * recipes in one frame never alias each other's ramp.
12
+ *
13
+ * `ratios` are in byte scale [0,255]. Colors are packed RGB integers.
14
+ * `alphas` are in [0,1].
15
+ */
16
+ export declare function getWgpuEffectGradientRampTexture(state: WgpuRenderState, colors: ReadonlyArray<number>, alphas: ReadonlyArray<number>, ratios: ReadonlyArray<number>): GPUTexture;
17
+ //# sourceMappingURL=wgpuEffectGradientRamp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wgpuEffectGradientRamp.d.ts","sourceRoot":"","sources":["../src/wgpuEffectGradientRamp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,eAAe,EACtB,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,EAC7B,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,EAC7B,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,GAC5B,UAAU,CAaZ"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Returns a cached 256-entry RGBA gradient ramp texture for the given stops,
3
+ * building it on first use and reusing it on later calls with the same stops.
4
+ * The texture is owned by the render state and lives for its lifetime — callers
5
+ * must NOT destroy it. This is the form recipes should use: a recipe runs inside
6
+ * the frame's command encoder and does not control submit timing, so it cannot
7
+ * safely `destroy()` a per-call texture (the encoder still references it at
8
+ * submit, which discards the whole frame). Caching also avoids a per-frame
9
+ * allocation. Distinct stop sets get distinct textures, so multiple gradient
10
+ * recipes in one frame never alias each other's ramp.
11
+ *
12
+ * `ratios` are in byte scale [0,255]. Colors are packed RGB integers.
13
+ * `alphas` are in [0,1].
14
+ */
15
+ export function getWgpuEffectGradientRampTexture(state, colors, alphas, ratios) {
16
+ let cache = rampCaches.get(state);
17
+ if (cache === undefined) {
18
+ cache = new Map();
19
+ rampCaches.set(state, cache);
20
+ }
21
+ const key = `${colors.join(',')}|${alphas.join(',')}|${ratios.join(',')}`;
22
+ let texture = cache.get(key);
23
+ if (texture === undefined) {
24
+ texture = createWgpuEffectGradientRampTexture(state, colors, alphas, ratios);
25
+ cache.set(key, texture);
26
+ }
27
+ return texture;
28
+ }
29
+ function buildRampData(colors, alphas, ratios) {
30
+ const out = new Uint8ClampedArray(256 * 4);
31
+ if (colors.length === 0)
32
+ return out;
33
+ for (let i = 0; i < 256; i++) {
34
+ const t = i;
35
+ let r = 0, g = 0, b = 0, a = 0;
36
+ if (t <= ratios[0]) {
37
+ const c = colors[0];
38
+ r = (c >> 16) & 0xff;
39
+ g = (c >> 8) & 0xff;
40
+ b = c & 0xff;
41
+ a = Math.round(alphas[0] * 255);
42
+ }
43
+ else if (t >= ratios[ratios.length - 1]) {
44
+ const c = colors[colors.length - 1];
45
+ r = (c >> 16) & 0xff;
46
+ g = (c >> 8) & 0xff;
47
+ b = c & 0xff;
48
+ a = Math.round(alphas[alphas.length - 1] * 255);
49
+ }
50
+ else {
51
+ for (let j = 0; j < ratios.length - 1; j++) {
52
+ const r0 = ratios[j];
53
+ const r1 = ratios[j + 1];
54
+ if (t >= r0 && t <= r1) {
55
+ const blend = r1 > r0 ? (t - r0) / (r1 - r0) : 0;
56
+ const c0 = colors[j];
57
+ const c1 = colors[j + 1];
58
+ r = Math.round(((c0 >> 16) & 0xff) * (1 - blend) + ((c1 >> 16) & 0xff) * blend);
59
+ g = Math.round(((c0 >> 8) & 0xff) * (1 - blend) + ((c1 >> 8) & 0xff) * blend);
60
+ b = Math.round((c0 & 0xff) * (1 - blend) + (c1 & 0xff) * blend);
61
+ a = Math.round(alphas[j] * 255 * (1 - blend) + alphas[j + 1] * 255 * blend);
62
+ break;
63
+ }
64
+ }
65
+ }
66
+ out[i * 4] = r;
67
+ out[i * 4 + 1] = g;
68
+ out[i * 4 + 2] = b;
69
+ out[i * 4 + 3] = a;
70
+ }
71
+ return out;
72
+ }
73
+ // Builds a 256-entry RGBA gradient ramp texture on the GPU. The returned texture is cached and owned by
74
+ // the render state (see getWgpuEffectGradientRampTexture), so it is never destroyed mid-encoder.
75
+ function createWgpuEffectGradientRampTexture(state, colors, alphas, ratios) {
76
+ const data = buildRampData(colors, alphas, ratios);
77
+ const { device } = state;
78
+ const texture = device.createTexture({
79
+ size: [256, 1, 1],
80
+ format: 'rgba8unorm',
81
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST,
82
+ });
83
+ device.queue.writeTexture({ texture, origin: [0, 0, 0] }, data.buffer, { offset: 0, bytesPerRow: 256 * 4 }, [256, 1, 1]);
84
+ return texture;
85
+ }
86
+ // Per-render-state cache of ramp textures keyed by their stops. Textures live for the render state's
87
+ // lifetime; they are tiny (256×1) and the distinct-gradient set is bounded in practice.
88
+ const rampCaches = new WeakMap();
89
+ //# sourceMappingURL=wgpuEffectGradientRamp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wgpuEffectGradientRamp.js","sourceRoot":"","sources":["../src/wgpuEffectGradientRamp.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,gCAAgC,CAC9C,KAAsB,EACtB,MAA6B,EAC7B,MAA6B,EAC7B,MAA6B;IAE7B,IAAI,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;QAClB,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC/B,CAAC;IACD,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IAC1E,IAAI,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,GAAG,mCAAmC,CAAC,KAAK,EAAE,M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OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,EAC9B,IAAI,CAAC,MAAqB,EAC1B,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,EAAE,GAAG,GAAG,CAAC,EAAE,EACnC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CACZ,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,qGAAqG;AACrG,wFAAwF;AACxF,MAAM,UAAU,GAAG,IAAI,OAAO,EAA4C,CAAC"}
@@ -0,0 +1,42 @@
1
+ import type { WgpuRenderState, WgpuRenderTarget } from '@flighthq/types';
2
+ export declare const EFFECT_VERTEX_WGSL = "\nstruct VertexOut {\n @builtin(position) position : vec4f,\n @location(0) uv : vec2f,\n}\n\n@vertex\nfn vs_main(@builtin(vertex_index) vi : u32) -> VertexOut {\n let xi = vi == 1u || vi == 2u || vi == 4u;\n let yi = vi == 2u || vi == 4u || vi == 5u;\n var out : VertexOut;\n out.position = vec4f(select(-1.0, 1.0, xi), select(-1.0, 1.0, yi), 0.0, 1.0);\n out.uv = vec2f(select(0.0, 1.0, xi), select(1.0, 0.0, yi));\n return out;\n}\n";
3
+ export type WgpuEffectBlendMode = 'premul' | 'replace' | 'erase';
4
+ export type WgpuEffectPipeline = {
5
+ pipeline: GPURenderPipeline;
6
+ blendMode: WgpuEffectBlendMode;
7
+ compileForFormat?: (format: GPUTextureFormat) => GPURenderPipeline;
8
+ variants?: Map<GPUTextureFormat, GPURenderPipeline>;
9
+ };
10
+ export type WgpuDualSourceEffectPipeline = WgpuEffectPipeline;
11
+ /** Clears a render target to fully transparent. Ends any active render pass. */
12
+ export declare function clearWgpuEffectTarget(state: WgpuRenderState, target: WgpuRenderTarget): void;
13
+ /** Compiles a dual-source WGSL effect pipeline (source0 = group 1, source1 = group 2). */
14
+ export declare function createWgpuDualSourceEffectPipeline(state: WgpuRenderState, fragmentWGSL: string, blend?: WgpuEffectBlendMode): WgpuDualSourceEffectPipeline;
15
+ /** Compiles a WGSL effect pipeline, creating the combined vertex+fragment shader module. */
16
+ export declare function createWgpuEffectPipeline(state: WgpuRenderState, fragmentWGSL: string, blend?: WgpuEffectBlendMode): WgpuEffectPipeline;
17
+ /**
18
+ * Draws a full-screen pass reading from two source textures.
19
+ * source0 binds to group 1, source1 to group 2.
20
+ */
21
+ export declare function drawWgpuDualSourceEffectPass(state: WgpuRenderState, source0: WgpuRenderTarget, source1: WgpuRenderTarget, dest: WgpuRenderTarget | null, pipeline: WgpuDualSourceEffectPipeline, setUniforms: (f32: Float32Array, i32: Int32Array) => void): void;
22
+ /**
23
+ * Draws a full-screen effect pass: reads from source (group 1), writes to dest.
24
+ * `setUniforms` is called with Float32Array and Int32Array views into the current
25
+ * ring-buffer slot for per-pass uniform uploads. Blend is premultiplied-alpha compositing.
26
+ * Ends any active render pass; does not restore it.
27
+ */
28
+ export declare function drawWgpuEffectPass(state: WgpuRenderState, source: WgpuRenderTarget, dest: WgpuRenderTarget | null, pipeline: WgpuEffectPipeline, setUniforms: (f32: Float32Array, i32: Int32Array) => void): void;
29
+ /**
30
+ * Returns the effect-pass state for the given render state, for use in shaders
31
+ * that need to bind a custom texture (e.g., a gradient ramp) as group 2 or 3.
32
+ */
33
+ export declare function getWgpuEffectPassState(state: WgpuRenderState): {
34
+ uniformBG: GPUBindGroup;
35
+ textureBGLayout: GPUBindGroupLayout;
36
+ uniformBGLayout: GPUBindGroupLayout;
37
+ sampler: GPUSampler;
38
+ acquireSlot: () => number;
39
+ writeSlot: (offset: number, fn: (f32: Float32Array, i32: Int32Array) => void) => void;
40
+ beginPass: (dest: WgpuRenderTarget | null, loadOp: GPULoadOp) => GPURenderPassEncoder;
41
+ };
42
+ //# sourceMappingURL=wgpuEffectPass.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wgpuEffectPass.d.ts","sourceRoot":"","sources":["../src/wgpuEffectPass.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,E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