@remotion/effects 4.0.538 → 4.0.540

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 (209) hide show
  1. package/THIRD_PARTY_LICENSES.md +19 -0
  2. package/dist/barrel-distortion/webgpu-shader.d.ts +1 -0
  3. package/dist/bevel-alpha/webgpu-shaders.d.ts +2 -0
  4. package/dist/burlap-webgpu-shader.d.ts +1 -0
  5. package/dist/checkerboard-webgpu-shader.d.ts +1 -0
  6. package/dist/chromatic-aberration/webgpu-shader.d.ts +1 -0
  7. package/dist/color-correction-webgpu-shader-utils.d.ts +4 -0
  8. package/dist/color-key-webgpu-shader.d.ts +1 -0
  9. package/dist/color-matrix-runtime.d.ts +4 -0
  10. package/dist/contour-lines-webgpu-shader.d.ts +1 -0
  11. package/dist/corner-pin/webgpu-shader.d.ts +1 -0
  12. package/dist/curves.d.ts +65 -0
  13. package/dist/cylinder/webgl-shader.d.ts +1 -0
  14. package/dist/dot-grid-webgpu-shader.d.ts +1 -0
  15. package/dist/drop-shadow/webgpu-shaders.d.ts +2 -0
  16. package/dist/emboss-webgpu-shader.d.ts +1 -0
  17. package/dist/esm/barrel-distortion.mjs +67 -118
  18. package/dist/esm/bevel-alpha.mjs +247 -196
  19. package/dist/esm/blur.mjs +101 -115
  20. package/dist/esm/brightness.mjs +65 -132
  21. package/dist/esm/burlap.mjs +178 -151
  22. package/dist/esm/checkerboard.mjs +6 -514
  23. package/dist/esm/chromatic-aberration.mjs +72 -119
  24. package/dist/esm/color-correction.mjs +186 -224
  25. package/dist/esm/color-key.mjs +149 -136
  26. package/dist/esm/contour-lines.mjs +201 -160
  27. package/dist/esm/contrast.mjs +65 -132
  28. package/dist/esm/corner-pin.mjs +4 -390
  29. package/dist/esm/curves.mjs +357 -0
  30. package/dist/esm/cylinder.mjs +108 -225
  31. package/dist/esm/dot-grid.mjs +184 -213
  32. package/dist/esm/drop-shadow.mjs +162 -180
  33. package/dist/esm/duotone.mjs +110 -143
  34. package/dist/esm/emboss.mjs +153 -151
  35. package/dist/esm/evolve.mjs +228 -154
  36. package/dist/esm/exposure.mjs +93 -201
  37. package/dist/esm/film-burn.mjs +298 -0
  38. package/dist/esm/fisheye.mjs +97 -126
  39. package/dist/esm/flannel.mjs +158 -156
  40. package/dist/esm/fractal-noise.mjs +186 -232
  41. package/dist/esm/glow.mjs +164 -179
  42. package/dist/esm/grayscale.mjs +56 -122
  43. package/dist/esm/gridlines.mjs +6 -575
  44. package/dist/esm/halftone-linear-gradient.mjs +246 -245
  45. package/dist/esm/halftone.mjs +267 -243
  46. package/dist/esm/hue.mjs +55 -122
  47. package/dist/esm/index-00v3hr66.mjs +299 -0
  48. package/dist/esm/index-0w4eqht8.mjs +351 -0
  49. package/dist/esm/index-18y0zcy2.mjs +440 -0
  50. package/dist/esm/index-1m1b1ad7.mjs +520 -0
  51. package/dist/esm/index-34fxm3ax.mjs +518 -0
  52. package/dist/esm/index-4fvp93ps.mjs +32 -0
  53. package/dist/esm/index-4scpn12x.mjs +224 -0
  54. package/dist/esm/index-4z6pt3ka.mjs +104 -0
  55. package/dist/esm/index-618ky75w.mjs +51 -0
  56. package/dist/esm/index-6agxdrvr.mjs +411 -0
  57. package/dist/esm/index-6jkps947.mjs +120 -0
  58. package/dist/esm/index-8agtsbw4.mjs +617 -0
  59. package/dist/esm/index-8jx11jyn.mjs +29 -0
  60. package/dist/esm/index-8p04sssx.mjs +123 -0
  61. package/dist/esm/index-afdtmrh2.mjs +596 -0
  62. package/dist/esm/index-b86qstcs.mjs +18 -0
  63. package/dist/esm/index-cb77qg3g.mjs +587 -0
  64. package/dist/esm/index-cdp7tr8x.mjs +122 -0
  65. package/dist/esm/index-evy8hyah.mjs +55 -0
  66. package/dist/esm/index-gnsce796.mjs +6 -0
  67. package/dist/esm/index-kkvzt8b7.mjs +199 -0
  68. package/dist/esm/index-r0v18b2n.mjs +425 -0
  69. package/dist/esm/index-rswpzmm5.mjs +926 -0
  70. package/dist/esm/index-s9mrx750.mjs +97 -0
  71. package/dist/esm/index-tvfexb7s.mjs +164 -0
  72. package/dist/esm/index-vp56k1gj.mjs +215 -0
  73. package/dist/esm/index-wxhvgv2s.mjs +79 -0
  74. package/dist/esm/index-wy95a41r.mjs +407 -0
  75. package/dist/esm/index-ysnwfc4t.mjs +306 -0
  76. package/dist/esm/index.mjs +49 -4053
  77. package/dist/esm/invert.mjs +54 -122
  78. package/dist/esm/iris-wipe.mjs +315 -0
  79. package/dist/esm/lens-blur.mjs +169 -156
  80. package/dist/esm/levels.mjs +204 -151
  81. package/dist/esm/light-leak.mjs +6 -416
  82. package/dist/esm/light-trail.mjs +124 -128
  83. package/dist/esm/linear-gradient-tint.mjs +4 -424
  84. package/dist/esm/linear-gradient.mjs +4 -370
  85. package/dist/esm/linear-progressive-blur.mjs +92 -118
  86. package/dist/esm/linear-progressive-pixelate.mjs +83 -378
  87. package/dist/esm/lines.mjs +167 -162
  88. package/dist/esm/liquid-contours.mjs +192 -153
  89. package/dist/esm/long-shadows.mjs +278 -251
  90. package/dist/esm/lut.mjs +123 -23
  91. package/dist/esm/mirror.mjs +78 -120
  92. package/dist/esm/noise-displacement.mjs +156 -151
  93. package/dist/esm/noise.mjs +107 -143
  94. package/dist/esm/outline.mjs +192 -170
  95. package/dist/esm/page-turn.mjs +141 -244
  96. package/dist/esm/paper.mjs +522 -194
  97. package/dist/esm/pattern.mjs +4 -568
  98. package/dist/esm/pixel-dissolve.mjs +158 -186
  99. package/dist/esm/pixelate.mjs +92 -149
  100. package/dist/esm/radial-progressive-blur.mjs +96 -118
  101. package/dist/esm/radial-progressive-pixelate.mjs +91 -384
  102. package/dist/esm/radial-wipe.mjs +224 -0
  103. package/dist/esm/rain-fall.mjs +114 -0
  104. package/dist/esm/region-blur.mjs +138 -192
  105. package/dist/esm/rings.mjs +6 -512
  106. package/dist/esm/roughen-edges.mjs +180 -156
  107. package/dist/esm/saturation.mjs +56 -122
  108. package/dist/esm/scale.mjs +50 -60
  109. package/dist/esm/scanlines.mjs +115 -149
  110. package/dist/esm/shadows-highlights.mjs +103 -205
  111. package/dist/esm/shatter.mjs +868 -0
  112. package/dist/esm/shine.mjs +192 -227
  113. package/dist/esm/shrinkwrap.mjs +388 -225
  114. package/dist/esm/skew.mjs +100 -145
  115. package/dist/esm/snow-fall.mjs +170 -0
  116. package/dist/esm/speckle.mjs +192 -210
  117. package/dist/esm/sphere.mjs +101 -225
  118. package/dist/esm/starburst.mjs +6 -345
  119. package/dist/esm/tear.mjs +138 -155
  120. package/dist/esm/thermal-vision.mjs +135 -152
  121. package/dist/esm/tile.mjs +5 -184
  122. package/dist/esm/tint.mjs +80 -132
  123. package/dist/esm/translate.mjs +55 -137
  124. package/dist/esm/turbulent-displace.mjs +182 -221
  125. package/dist/esm/tv-signal-off.mjs +140 -149
  126. package/dist/esm/venetian-blinds.mjs +91 -140
  127. package/dist/esm/vibrance.mjs +95 -204
  128. package/dist/esm/vignette.mjs +136 -155
  129. package/dist/esm/wave.mjs +88 -47
  130. package/dist/esm/waves.mjs +181 -169
  131. package/dist/esm/white-balance.mjs +100 -204
  132. package/dist/esm/white-noise.mjs +98 -146
  133. package/dist/esm/zigzag.mjs +6 -575
  134. package/dist/esm/zoom-blur.mjs +90 -121
  135. package/dist/evolve.d.ts +46 -10
  136. package/dist/film-burn-webgpu-shader.d.ts +1 -0
  137. package/dist/film-burn.d.ts +40 -0
  138. package/dist/fisheye/webgpu-shader.d.ts +1 -0
  139. package/dist/flannel-webgpu-shader.d.ts +1 -0
  140. package/dist/fractal-noise/shader.d.ts +1 -1
  141. package/dist/fractal-noise/webgpu-shader.d.ts +1 -0
  142. package/dist/gaussian-blur-webgpu-shader.d.ts +1 -0
  143. package/dist/glow/webgpu-shaders.d.ts +2 -0
  144. package/dist/gridlines-webgpu-shader.d.ts +1 -0
  145. package/dist/halftone-linear-gradient-webgpu-shader.d.ts +1 -0
  146. package/dist/halftone-webgpu-shader.d.ts +1 -0
  147. package/dist/iris-wipe.d.ts +78 -0
  148. package/dist/lens-blur/webgpu-shader.d.ts +1 -0
  149. package/dist/levels.d.ts +69 -2
  150. package/dist/light-leak-webgpu-shader.d.ts +1 -0
  151. package/dist/light-trail/webgpu-shader.d.ts +1 -0
  152. package/dist/linear-gradient-tint-webgpu-shader.d.ts +1 -0
  153. package/dist/linear-gradient-webgpu-shader.d.ts +1 -0
  154. package/dist/lines-webgpu-shader.d.ts +1 -0
  155. package/dist/liquid-contours-webgpu-shader.d.ts +1 -0
  156. package/dist/long-shadows-webgpu-shaders.d.ts +2 -0
  157. package/dist/lut/webgpu-shader.d.ts +1 -0
  158. package/dist/mirror/webgpu-shader.d.ts +1 -0
  159. package/dist/noise-displacement-webgpu-shader.d.ts +1 -0
  160. package/dist/noise-webgpu-shader.d.ts +1 -0
  161. package/dist/outline/webgpu-shader.d.ts +1 -0
  162. package/dist/page-turn/webgl-shader.d.ts +1 -0
  163. package/dist/paper-webgpu-shader.d.ts +2 -0
  164. package/dist/pattern-webgpu-shader.d.ts +1 -0
  165. package/dist/pixel-dissolve-webgpu-shader.d.ts +1 -0
  166. package/dist/progressive-pixelate-runtime.d.ts +1 -0
  167. package/dist/radial-wipe.d.ts +19 -0
  168. package/dist/rain-fall.d.ts +143 -0
  169. package/dist/rect-transform-runtime.d.ts +11 -0
  170. package/dist/region-blur/webgpu-shader.d.ts +1 -0
  171. package/dist/rings-webgpu-shader.d.ts +1 -0
  172. package/dist/roughen-edges-webgpu-shader.d.ts +1 -0
  173. package/dist/shatter/geometry.d.ts +19 -0
  174. package/dist/shatter/index.d.ts +39 -0
  175. package/dist/shatter/runtime.d.ts +19 -0
  176. package/dist/shatter/webgpu-shader.d.ts +1 -0
  177. package/dist/shatter.d.ts +1 -0
  178. package/dist/shine-webgpu-shader.d.ts +1 -0
  179. package/dist/shrinkwrap-webgpu-shader.d.ts +1 -0
  180. package/dist/single-pass-runtime.d.ts +18 -0
  181. package/dist/skew-webgpu-shader.d.ts +1 -0
  182. package/dist/snow-fall.d.ts +208 -0
  183. package/dist/speckle-webgpu-shader.d.ts +1 -0
  184. package/dist/sphere/webgl-shader.d.ts +1 -0
  185. package/dist/starburst-webgpu-shader.d.ts +1 -0
  186. package/dist/tear-webgpu-shader.d.ts +1 -0
  187. package/dist/thermal-vision-webgpu-shader.d.ts +1 -0
  188. package/dist/tile-gpu-runtime.d.ts +24 -0
  189. package/dist/turbulent-displace/webgpu-shader.d.ts +1 -0
  190. package/dist/value-noise-webgpu-shader.d.ts +1 -0
  191. package/dist/vignette-webgpu-shader.d.ts +1 -0
  192. package/dist/wave/wave-runtime.d.ts +2 -1
  193. package/dist/wave/webgpu-shader.d.ts +1 -0
  194. package/dist/waves-webgpu-shader.d.ts +1 -0
  195. package/dist/weather/params.d.ts +149 -0
  196. package/dist/weather/runtime.d.ts +52 -0
  197. package/dist/weather/shaders.d.ts +4 -0
  198. package/dist/weather/webgpu-runtime.d.ts +36 -0
  199. package/dist/weather/webgpu-shader.d.ts +1 -0
  200. package/dist/webgl-projection-runtime.d.ts +18 -0
  201. package/dist/webgpu-color-state.d.ts +10 -0
  202. package/dist/webgpu-mesh-runtime.d.ts +46 -0
  203. package/dist/webgpu-multipass-runtime.d.ts +50 -0
  204. package/dist/webgpu-projection-runtime.d.ts +9 -5
  205. package/dist/webgpu-single-pass-runtime.d.ts +47 -0
  206. package/dist/white-noise-webgpu-shader.d.ts +1 -0
  207. package/dist/zigzag-webgpu-shader.d.ts +1 -0
  208. package/dist/zoom-blur/webgpu-shader.d.ts +1 -0
  209. package/package.json +59 -3
@@ -1,110 +1,68 @@
1
+ import {
2
+ setupWebGpuColors,
3
+ getWebGpuColors
4
+ } from "./index-8jx11jyn.mjs";
5
+ import {
6
+ assertOptionalFiniteNumber,
7
+ parseColorRgba
8
+ } from "./index-wxhvgv2s.mjs";
9
+ import {
10
+ WEBGPU_SINGLE_PASS_VERTEX,
11
+ cleanupWebGpuSinglePass,
12
+ applyWebGpuSinglePass
13
+ } from "./index-tvfexb7s.mjs";
14
+ import {
15
+ assertEffectParamsObject,
16
+ assertOptionalColor,
17
+ assertOptionalBoolean
18
+ } from "./index-4fvp93ps.mjs";
19
+
1
20
  // src/halftone-linear-gradient.ts
2
21
  import { Internals } from "remotion";
3
22
 
4
- // src/validate-effect-param.ts
5
- var assertEffectParamsObject = (params, effectLabel) => {
6
- if (params === null || typeof params !== "object") {
7
- throw new TypeError(`${effectLabel} effect requires a parameters object, but got ${JSON.stringify(params)}`);
8
- }
9
- };
10
- var assertRequiredFiniteNumber = (value, name) => {
11
- if (typeof value !== "number" || !Number.isFinite(value)) {
12
- throw new TypeError(`"${name}" must be a finite number, but got ${JSON.stringify(value)}`);
13
- }
14
- };
15
- var assertRequiredColor = (value, name) => {
16
- if (typeof value !== "string" || value.length === 0) {
17
- throw new TypeError(`"${name}" must be a non-empty string, but got ${JSON.stringify(value)}`);
18
- }
19
- };
20
- var assertOptionalColor = (value, name) => {
21
- if (value === undefined) {
22
- return;
23
- }
24
- assertRequiredColor(value, name);
25
- };
26
- var assertOptionalBoolean = (value, name) => {
27
- if (value === undefined) {
28
- return;
29
- }
30
- if (typeof value !== "boolean") {
31
- throw new TypeError(`"${name}" must be a boolean, but got ${JSON.stringify(value)}`);
32
- }
33
- };
23
+ // src/halftone-linear-gradient-webgpu-shader.ts
24
+ var HALFTONE_LINEAR_GRADIENT_WEBGPU_SHADER = `
25
+ ${WEBGPU_SINGLE_PASS_VERTEX}
26
+ @group(0) @binding(0) var sourceTexture: texture_2d<f32>;
27
+ @group(0) @binding(1) var sourceSampler: sampler;
28
+ @group(0) @binding(2) var<uniform> params: Params;
29
+ struct Params {
30
+ geometry: vec4f,
31
+ stops: vec4f,
32
+ flags: vec4f,
33
+ color: vec4f,
34
+ }
35
+ fn sampleSource(uv: vec2f) -> vec4f {
36
+ return textureSampleLevel(sourceTexture, sourceSampler, vec2f(uv.x, 1.0 - uv.y), 0);
37
+ }
34
38
 
35
- // src/color-utils.ts
36
- var DEFAULT_AMOUNT = 1;
37
- var DEFAULT_BRIGHTNESS_AMOUNT = 0;
38
- var DEFAULT_HUE_DEGREES = 0;
39
- var colorAmountSchema = {
40
- type: "number",
41
- min: 0,
42
- max: 1,
43
- step: 0.01,
44
- default: DEFAULT_AMOUNT,
45
- description: "Amount",
46
- hiddenFromList: false
47
- };
48
- var colorMultiplierSchema = {
49
- type: "number",
50
- min: 0,
51
- step: 0.01,
52
- default: DEFAULT_AMOUNT,
53
- description: "Amount",
54
- hiddenFromList: false
55
- };
56
- var brightnessAmountSchema = {
57
- type: "number",
58
- min: -1,
59
- max: 1,
60
- step: 0.01,
61
- default: DEFAULT_BRIGHTNESS_AMOUNT,
62
- description: "Amount",
63
- hiddenFromList: false
64
- };
65
- var hueDegreesSchema = {
66
- type: "rotation-degrees",
67
- step: 1,
68
- default: DEFAULT_HUE_DEGREES,
69
- description: "Degrees"
70
- };
71
- var assertOptionalFiniteNumber = (value, name) => {
72
- if (value === undefined) {
73
- return;
74
- }
75
- assertRequiredFiniteNumber(value, name);
76
- };
77
- var validateUnitInterval = (value, name) => {
78
- if (value < 0) {
79
- throw new TypeError(`"${name}" must be >= 0, but got ${JSON.stringify(value)}`);
80
- }
81
- if (value > 1) {
82
- throw new TypeError(`"${name}" must be <= 1, but got ${JSON.stringify(value)}`);
83
- }
84
- };
85
- var validateNonNegative = (value, name) => {
86
- if (value < 0) {
87
- throw new TypeError(`"${name}" must be >= 0, but got ${JSON.stringify(value)}`);
88
- }
89
- };
90
- var validateSignedUnitInterval = (value, name) => {
91
- if (value < -1) {
92
- throw new TypeError(`"${name}" must be >= -1, but got ${JSON.stringify(value)}`);
93
- }
94
- if (value > 1) {
95
- throw new TypeError(`"${name}" must be <= 1, but got ${JSON.stringify(value)}`);
96
- }
97
- };
98
- var clampColorChannel = (value) => {
99
- return Math.max(0, Math.min(255, value));
100
- };
101
- var parseColorRgba = (ctx, color) => {
102
- ctx.clearRect(0, 0, 1, 1);
103
- ctx.fillStyle = color;
104
- ctx.fillRect(0, 0, 1, 1);
105
- const { data } = ctx.getImageData(0, 0, 1, 1);
106
- return [data[0], data[1], data[2], data[3]];
107
- };
39
+ @fragment fn fragment(input: VertexOutput) -> @location(0) vec4f {
40
+ let vUv = vec2f(input.uv.x, 1.0 - input.uv.y);
41
+
42
+ let center = params.geometry.xy * 0.5;
43
+ let gridPos = vec2f(input.position.x, params.geometry.y - input.position.y) - center;
44
+ let gridSize = max(params.flags.x, 0.001);
45
+ let cellIndex = floor(gridPos / gridSize + vec2f(0.5));
46
+ let gridCenter = cellIndex * gridSize;
47
+ let canvasCenter = center + gridCenter;
48
+ let centerUv = canvasCenter / params.geometry.xy;
49
+ let gradientUv = vec2f(centerUv.x, 1.0 - centerUv.y);
50
+ let stopVector = params.stops.zw - params.stops.xy;
51
+ let stopDistance = dot(stopVector, stopVector);
52
+ var progress = 0.0;
53
+ if (stopDistance > 0.0) { progress = clamp(dot(gradientUv - params.stops.xy, stopVector) / stopDistance, 0.0, 1.0); }
54
+ let dotSize = mix(params.geometry.z, params.geometry.w, progress);
55
+ if (dotSize <= 0.01) { return vec4f(0); }
56
+ let radius = dotSize * 0.5;
57
+ let coverage = 1.0 - smoothstep(radius - 0.75, radius + 0.75, length(gridPos - gridCenter));
58
+ let texColor = sampleSource(clamp(centerUv, vec2f(0), vec2f(1)));
59
+ let dotColor = select(params.color, texColor, params.flags.y != 0.0) * coverage;
60
+ if (params.flags.y != 0.0) { return dotColor; }
61
+ if (params.flags.z != 0.0) { return vec4f(dotColor.rgb * texColor.a + texColor.rgb * (1.0 - dotColor.a), texColor.a); }
62
+ return dotColor + texColor * (1.0 - dotColor.a);
63
+
64
+ }
65
+ `;
108
66
 
109
67
  // src/halftone-linear-gradient.ts
110
68
  var { createEffect, createWebGL2ContextError } = Internals;
@@ -213,7 +171,7 @@ var resolve = (p) => ({
213
171
  dotColor: "dotColor" in p ? p.dotColor ?? DEFAULT_DOT_COLOR : DEFAULT_DOT_COLOR,
214
172
  maskToSourceAlpha: p.maskToSourceAlpha ?? DEFAULT_MASK_TO_SOURCE_ALPHA
215
173
  });
216
- var validateNonNegative2 = (value, name) => {
174
+ var validateNonNegative = (value, name) => {
217
175
  if (value < 0) {
218
176
  throw new TypeError(`"${name}" must be >= 0, but got ${JSON.stringify(value)}`);
219
177
  }
@@ -245,10 +203,10 @@ var validateHalftoneLinearGradientParams = (params) => {
245
203
  }
246
204
  assertOptionalColor("dotColor" in params ? params.dotColor : undefined, "dotColor");
247
205
  if (params.firstStopDotSize !== undefined) {
248
- validateNonNegative2(params.firstStopDotSize, "firstStopDotSize");
206
+ validateNonNegative(params.firstStopDotSize, "firstStopDotSize");
249
207
  }
250
208
  if (params.secondStopDotSize !== undefined) {
251
- validateNonNegative2(params.secondStopDotSize, "secondStopDotSize");
209
+ validateNonNegative(params.secondStopDotSize, "secondStopDotSize");
252
210
  }
253
211
  if (params.gridSize !== undefined) {
254
212
  validatePositive(params.gridSize, "gridSize");
@@ -302,7 +260,7 @@ vec4 sourceAtop(vec4 backdrop, vec4 overlay) {
302
260
  }
303
261
 
304
262
  void main() {
305
- vec2 fragPos = vUv * uResolution;
263
+ vec2 fragPos = gl_FragCoord.xy;
306
264
  vec2 center = uResolution * 0.5;
307
265
  vec2 gridPos = fragPos - center;
308
266
 
@@ -369,149 +327,192 @@ var halftoneLinearGradient = createEffect({
369
327
  type: "dev.remotion.effects.halftoneLinearGradient",
370
328
  label: "halftoneLinearGradient()",
371
329
  documentationLink: "https://www.remotion.dev/docs/effects/halftone-linear-gradient",
372
- backend: "webgl2",
373
330
  calculateKey: (params) => {
374
331
  const r = resolve(params);
375
332
  const maskSuffix = r.maskToSourceAlpha ? "-mask-to-source-alpha" : "";
376
333
  return `halftone-linear-gradient-${r.firstStopDotSize}-${r.secondStopDotSize}-${r.firstStopPosition.join(":")}-${r.secondStopPosition.join(":")}-${r.gridSize}-${r.colorMode}-${r.dotColor}${maskSuffix}`;
377
334
  },
378
- setup: (target) => {
379
- const gl = target.getContext("webgl2", {
380
- premultipliedAlpha: true,
381
- alpha: true,
382
- preserveDrawingBuffer: true
383
- });
384
- if (!gl) {
385
- throw createWebGL2ContextError("halftone linear gradient effect");
386
- }
387
- gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
388
- const vs = compileShader(gl, gl.VERTEX_SHADER, HALFTONE_LINEAR_GRADIENT_VS);
389
- const fs = compileShader(gl, gl.FRAGMENT_SHADER, HALFTONE_LINEAR_GRADIENT_FS);
390
- const program = linkProgram(gl, vs, fs);
391
- gl.deleteShader(vs);
392
- gl.deleteShader(fs);
393
- const vao = gl.createVertexArray();
394
- if (!vao) {
395
- throw new Error("Failed to create WebGL vertex array");
396
- }
397
- gl.bindVertexArray(vao);
398
- const data = new Float32Array([
399
- -1,
400
- -1,
401
- 0,
402
- 0,
403
- 1,
404
- -1,
405
- 1,
406
- 0,
407
- -1,
408
- 1,
409
- 0,
410
- 1,
411
- 1,
412
- 1,
413
- 1,
414
- 1
415
- ]);
416
- const vbo = gl.createBuffer();
417
- if (!vbo) {
418
- throw new Error("Failed to create WebGL buffer");
419
- }
420
- gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
421
- gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
422
- const aPos = gl.getAttribLocation(program, "aPos");
423
- const aUv = gl.getAttribLocation(program, "aUv");
424
- gl.enableVertexAttribArray(aPos);
425
- gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 16, 0);
426
- gl.enableVertexAttribArray(aUv);
427
- gl.vertexAttribPointer(aUv, 2, gl.FLOAT, false, 16, 8);
428
- gl.bindVertexArray(null);
429
- const texture = gl.createTexture();
430
- if (!texture) {
431
- throw new Error("Failed to create WebGL texture");
432
- }
433
- gl.bindTexture(gl.TEXTURE_2D, texture);
434
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
435
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
436
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
437
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
438
- gl.bindTexture(gl.TEXTURE_2D, null);
439
- const colorCanvas = document.createElement("canvas");
440
- colorCanvas.width = 1;
441
- colorCanvas.height = 1;
442
- const colorCtx = colorCanvas.getContext("2d", { willReadFrequently: true });
443
- if (!colorCtx) {
444
- throw new Error("Failed to acquire 2D context for color parsing");
445
- }
446
- return {
447
- gl,
448
- program,
449
- vao,
450
- vbo,
451
- texture,
452
- uSource: gl.getUniformLocation(program, "uSource"),
453
- uResolution: gl.getUniformLocation(program, "uResolution"),
454
- uFirstStopDotSize: gl.getUniformLocation(program, "uFirstStopDotSize"),
455
- uSecondStopDotSize: gl.getUniformLocation(program, "uSecondStopDotSize"),
456
- uFirstStopPosition: gl.getUniformLocation(program, "uFirstStopPosition"),
457
- uSecondStopPosition: gl.getUniformLocation(program, "uSecondStopPosition"),
458
- uGridSize: gl.getUniformLocation(program, "uGridSize"),
459
- uColor: gl.getUniformLocation(program, "uColor"),
460
- uUseSourceColor: gl.getUniformLocation(program, "uUseSourceColor"),
461
- uMaskToSourceAlpha: gl.getUniformLocation(program, "uMaskToSourceAlpha"),
462
- colorCtx,
463
- cachedColorStr: "",
464
- cachedColorRgba: [0, 0, 0, 255]
465
- };
466
- },
467
- apply: ({ source, width, height, params, state, flipSourceY }) => {
468
- const r = resolve(params);
469
- const { gl, program, vao, texture } = state;
470
- if (state.cachedColorStr !== r.dotColor) {
471
- state.cachedColorStr = r.dotColor;
472
- state.cachedColorRgba = parseColorRgba(state.colorCtx, r.dotColor);
473
- }
474
- const [cr, cg, cb, ca] = state.cachedColorRgba;
475
- const caNormalized = ca / 255;
476
- gl.viewport(0, 0, width, height);
477
- gl.clearColor(0, 0, 0, 0);
478
- gl.clear(gl.COLOR_BUFFER_BIT);
479
- gl.useProgram(program);
480
- gl.bindVertexArray(vao);
481
- gl.activeTexture(gl.TEXTURE0);
482
- gl.bindTexture(gl.TEXTURE_2D, texture);
483
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
484
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
485
- if (state.uSource)
486
- gl.uniform1i(state.uSource, 0);
487
- if (state.uResolution)
488
- gl.uniform2f(state.uResolution, width, height);
489
- if (state.uFirstStopDotSize)
490
- gl.uniform1f(state.uFirstStopDotSize, r.firstStopDotSize);
491
- if (state.uSecondStopDotSize)
492
- gl.uniform1f(state.uSecondStopDotSize, r.secondStopDotSize);
493
- if (state.uFirstStopPosition)
494
- gl.uniform2f(state.uFirstStopPosition, r.firstStopPosition[0], r.firstStopPosition[1]);
495
- if (state.uSecondStopPosition)
496
- gl.uniform2f(state.uSecondStopPosition, r.secondStopPosition[0], r.secondStopPosition[1]);
497
- if (state.uGridSize)
498
- gl.uniform1f(state.uGridSize, r.gridSize);
499
- if (state.uColor)
500
- gl.uniform4f(state.uColor, cr / 255 * caNormalized, cg / 255 * caNormalized, cb / 255 * caNormalized, caNormalized);
501
- if (state.uUseSourceColor)
502
- gl.uniform1i(state.uUseSourceColor, r.colorMode === "source" ? 1 : 0);
503
- if (state.uMaskToSourceAlpha)
504
- gl.uniform1i(state.uMaskToSourceAlpha, r.maskToSourceAlpha ? 1 : 0);
505
- gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
506
- gl.bindVertexArray(null);
507
- gl.bindTexture(gl.TEXTURE_2D, null);
508
- gl.useProgram(null);
509
- },
510
- cleanup: ({ gl, program, vao, vbo, texture }) => {
511
- gl.deleteBuffer(vbo);
512
- gl.deleteProgram(program);
513
- gl.deleteVertexArray(vao);
514
- gl.deleteTexture(texture);
335
+ implementations: {
336
+ webgpu: Internals.createEffectImplementation({
337
+ setup: (target) => setupWebGpuColors(target, "halftone-linear-gradient"),
338
+ apply: ({ source, width, height, params, state, gpuDevice }) => {
339
+ if (!gpuDevice)
340
+ throw new Error("A WebGPU device is required for the halftone-linear-gradient effect");
341
+ const r = resolve(params);
342
+ const colors = getWebGpuColors(state, [r.dotColor]);
343
+ const uniformData = new Float32Array([
344
+ width,
345
+ height,
346
+ r.firstStopDotSize,
347
+ r.secondStopDotSize,
348
+ r.firstStopPosition[0],
349
+ r.firstStopPosition[1],
350
+ r.secondStopPosition[0],
351
+ r.secondStopPosition[1],
352
+ r.gridSize,
353
+ r.colorMode === "source" ? 1 : 0,
354
+ r.maskToSourceAlpha ? 1 : 0,
355
+ 0,
356
+ colors[0] / 255 * (colors[3] / 255),
357
+ colors[1] / 255 * (colors[3] / 255),
358
+ colors[2] / 255 * (colors[3] / 255),
359
+ colors[3] / 255
360
+ ]);
361
+ applyWebGpuSinglePass({
362
+ state,
363
+ source,
364
+ width,
365
+ height,
366
+ device: gpuDevice,
367
+ shader: HALFTONE_LINEAR_GRADIENT_WEBGPU_SHADER,
368
+ uniformData
369
+ });
370
+ },
371
+ cleanup: cleanupWebGpuSinglePass
372
+ }),
373
+ webgl2: Internals.createEffectImplementation({
374
+ setup: (target) => {
375
+ const gl = target.getContext("webgl2", {
376
+ premultipliedAlpha: true,
377
+ alpha: true,
378
+ preserveDrawingBuffer: true
379
+ });
380
+ if (!gl) {
381
+ throw createWebGL2ContextError("halftone linear gradient effect");
382
+ }
383
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
384
+ const vs = compileShader(gl, gl.VERTEX_SHADER, HALFTONE_LINEAR_GRADIENT_VS);
385
+ const fs = compileShader(gl, gl.FRAGMENT_SHADER, HALFTONE_LINEAR_GRADIENT_FS);
386
+ const program = linkProgram(gl, vs, fs);
387
+ gl.deleteShader(vs);
388
+ gl.deleteShader(fs);
389
+ const vao = gl.createVertexArray();
390
+ if (!vao) {
391
+ throw new Error("Failed to create WebGL vertex array");
392
+ }
393
+ gl.bindVertexArray(vao);
394
+ const data = new Float32Array([
395
+ -1,
396
+ -1,
397
+ 0,
398
+ 0,
399
+ 1,
400
+ -1,
401
+ 1,
402
+ 0,
403
+ -1,
404
+ 1,
405
+ 0,
406
+ 1,
407
+ 1,
408
+ 1,
409
+ 1,
410
+ 1
411
+ ]);
412
+ const vbo = gl.createBuffer();
413
+ if (!vbo) {
414
+ throw new Error("Failed to create WebGL buffer");
415
+ }
416
+ gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
417
+ gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
418
+ const aPos = gl.getAttribLocation(program, "aPos");
419
+ const aUv = gl.getAttribLocation(program, "aUv");
420
+ gl.enableVertexAttribArray(aPos);
421
+ gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 16, 0);
422
+ gl.enableVertexAttribArray(aUv);
423
+ gl.vertexAttribPointer(aUv, 2, gl.FLOAT, false, 16, 8);
424
+ gl.bindVertexArray(null);
425
+ const texture = gl.createTexture();
426
+ if (!texture) {
427
+ throw new Error("Failed to create WebGL texture");
428
+ }
429
+ gl.bindTexture(gl.TEXTURE_2D, texture);
430
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
431
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
432
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
433
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
434
+ gl.bindTexture(gl.TEXTURE_2D, null);
435
+ const colorCanvas = document.createElement("canvas");
436
+ colorCanvas.width = 1;
437
+ colorCanvas.height = 1;
438
+ const colorCtx = colorCanvas.getContext("2d", {
439
+ willReadFrequently: true
440
+ });
441
+ if (!colorCtx) {
442
+ throw new Error("Failed to acquire 2D context for color parsing");
443
+ }
444
+ return {
445
+ gl,
446
+ program,
447
+ vao,
448
+ vbo,
449
+ texture,
450
+ uSource: gl.getUniformLocation(program, "uSource"),
451
+ uResolution: gl.getUniformLocation(program, "uResolution"),
452
+ uFirstStopDotSize: gl.getUniformLocation(program, "uFirstStopDotSize"),
453
+ uSecondStopDotSize: gl.getUniformLocation(program, "uSecondStopDotSize"),
454
+ uFirstStopPosition: gl.getUniformLocation(program, "uFirstStopPosition"),
455
+ uSecondStopPosition: gl.getUniformLocation(program, "uSecondStopPosition"),
456
+ uGridSize: gl.getUniformLocation(program, "uGridSize"),
457
+ uColor: gl.getUniformLocation(program, "uColor"),
458
+ uUseSourceColor: gl.getUniformLocation(program, "uUseSourceColor"),
459
+ uMaskToSourceAlpha: gl.getUniformLocation(program, "uMaskToSourceAlpha"),
460
+ colorCtx,
461
+ cachedColorStr: "",
462
+ cachedColorRgba: [0, 0, 0, 255]
463
+ };
464
+ },
465
+ apply: ({ source, width, height, params, state, flipSourceY }) => {
466
+ const r = resolve(params);
467
+ const { gl, program, vao, texture } = state;
468
+ if (state.cachedColorStr !== r.dotColor) {
469
+ state.cachedColorStr = r.dotColor;
470
+ state.cachedColorRgba = parseColorRgba(state.colorCtx, r.dotColor);
471
+ }
472
+ const [cr, cg, cb, ca] = state.cachedColorRgba;
473
+ const caNormalized = ca / 255;
474
+ gl.viewport(0, 0, width, height);
475
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
476
+ gl.clearColor(0, 0, 0, 0);
477
+ gl.clear(gl.COLOR_BUFFER_BIT);
478
+ gl.useProgram(program);
479
+ gl.bindVertexArray(vao);
480
+ gl.activeTexture(gl.TEXTURE0);
481
+ gl.bindTexture(gl.TEXTURE_2D, texture);
482
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
483
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
484
+ if (state.uSource)
485
+ gl.uniform1i(state.uSource, 0);
486
+ if (state.uResolution)
487
+ gl.uniform2f(state.uResolution, width, height);
488
+ if (state.uFirstStopDotSize)
489
+ gl.uniform1f(state.uFirstStopDotSize, r.firstStopDotSize);
490
+ if (state.uSecondStopDotSize)
491
+ gl.uniform1f(state.uSecondStopDotSize, r.secondStopDotSize);
492
+ if (state.uFirstStopPosition)
493
+ gl.uniform2f(state.uFirstStopPosition, r.firstStopPosition[0], r.firstStopPosition[1]);
494
+ if (state.uSecondStopPosition)
495
+ gl.uniform2f(state.uSecondStopPosition, r.secondStopPosition[0], r.secondStopPosition[1]);
496
+ if (state.uGridSize)
497
+ gl.uniform1f(state.uGridSize, r.gridSize);
498
+ if (state.uColor)
499
+ gl.uniform4f(state.uColor, cr / 255 * caNormalized, cg / 255 * caNormalized, cb / 255 * caNormalized, caNormalized);
500
+ if (state.uUseSourceColor)
501
+ gl.uniform1i(state.uUseSourceColor, r.colorMode === "source" ? 1 : 0);
502
+ if (state.uMaskToSourceAlpha)
503
+ gl.uniform1i(state.uMaskToSourceAlpha, r.maskToSourceAlpha ? 1 : 0);
504
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
505
+ gl.bindVertexArray(null);
506
+ gl.bindTexture(gl.TEXTURE_2D, null);
507
+ gl.useProgram(null);
508
+ },
509
+ cleanup: ({ gl, program, vao, vbo, texture }) => {
510
+ gl.deleteBuffer(vbo);
511
+ gl.deleteProgram(program);
512
+ gl.deleteVertexArray(vao);
513
+ gl.deleteTexture(texture);
514
+ }
515
+ })
515
516
  },
516
517
  schema: halftoneLinearGradientSchema,
517
518
  validateParams: validateHalftoneLinearGradientParams