@remotion/effects 4.0.539 → 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.
- package/THIRD_PARTY_LICENSES.md +15 -0
- package/dist/barrel-distortion/webgpu-shader.d.ts +1 -0
- package/dist/bevel-alpha/webgpu-shaders.d.ts +2 -0
- package/dist/burlap-webgpu-shader.d.ts +1 -0
- package/dist/checkerboard-webgpu-shader.d.ts +1 -0
- package/dist/chromatic-aberration/webgpu-shader.d.ts +1 -0
- package/dist/color-correction-webgpu-shader-utils.d.ts +4 -0
- package/dist/color-key-webgpu-shader.d.ts +1 -0
- package/dist/color-matrix-runtime.d.ts +4 -0
- package/dist/contour-lines-webgpu-shader.d.ts +1 -0
- package/dist/corner-pin/webgpu-shader.d.ts +1 -0
- package/dist/cylinder/webgl-shader.d.ts +1 -0
- package/dist/dot-grid-webgpu-shader.d.ts +1 -0
- package/dist/drop-shadow/webgpu-shaders.d.ts +2 -0
- package/dist/emboss-webgpu-shader.d.ts +1 -0
- package/dist/esm/barrel-distortion.mjs +67 -118
- package/dist/esm/bevel-alpha.mjs +247 -196
- package/dist/esm/blur.mjs +101 -115
- package/dist/esm/brightness.mjs +65 -132
- package/dist/esm/burlap.mjs +178 -151
- package/dist/esm/checkerboard.mjs +6 -514
- package/dist/esm/chromatic-aberration.mjs +72 -119
- package/dist/esm/color-correction.mjs +186 -224
- package/dist/esm/color-key.mjs +149 -136
- package/dist/esm/contour-lines.mjs +201 -160
- package/dist/esm/contrast.mjs +65 -132
- package/dist/esm/corner-pin.mjs +4 -390
- package/dist/esm/curves.mjs +195 -211
- package/dist/esm/cylinder.mjs +108 -225
- package/dist/esm/dot-grid.mjs +184 -213
- package/dist/esm/drop-shadow.mjs +162 -180
- package/dist/esm/duotone.mjs +110 -143
- package/dist/esm/emboss.mjs +153 -151
- package/dist/esm/evolve.mjs +228 -154
- package/dist/esm/exposure.mjs +93 -201
- package/dist/esm/film-burn.mjs +298 -0
- package/dist/esm/fisheye.mjs +97 -126
- package/dist/esm/flannel.mjs +158 -156
- package/dist/esm/fractal-noise.mjs +186 -232
- package/dist/esm/glow.mjs +164 -179
- package/dist/esm/grayscale.mjs +56 -122
- package/dist/esm/gridlines.mjs +6 -575
- package/dist/esm/halftone-linear-gradient.mjs +246 -245
- package/dist/esm/halftone.mjs +267 -243
- package/dist/esm/hue.mjs +55 -122
- package/dist/esm/index-00v3hr66.mjs +299 -0
- package/dist/esm/index-0w4eqht8.mjs +351 -0
- package/dist/esm/index-18y0zcy2.mjs +440 -0
- package/dist/esm/index-1m1b1ad7.mjs +520 -0
- package/dist/esm/index-34fxm3ax.mjs +518 -0
- package/dist/esm/index-4fvp93ps.mjs +32 -0
- package/dist/esm/index-4scpn12x.mjs +224 -0
- package/dist/esm/index-4z6pt3ka.mjs +104 -0
- package/dist/esm/index-618ky75w.mjs +51 -0
- package/dist/esm/index-6agxdrvr.mjs +411 -0
- package/dist/esm/index-6jkps947.mjs +120 -0
- package/dist/esm/index-8agtsbw4.mjs +617 -0
- package/dist/esm/index-8jx11jyn.mjs +29 -0
- package/dist/esm/index-8p04sssx.mjs +123 -0
- package/dist/esm/index-afdtmrh2.mjs +596 -0
- package/dist/esm/index-b86qstcs.mjs +18 -0
- package/dist/esm/index-cb77qg3g.mjs +587 -0
- package/dist/esm/index-cdp7tr8x.mjs +122 -0
- package/dist/esm/index-evy8hyah.mjs +55 -0
- package/dist/esm/index-gnsce796.mjs +6 -0
- package/dist/esm/index-kkvzt8b7.mjs +199 -0
- package/dist/esm/index-r0v18b2n.mjs +425 -0
- package/dist/esm/index-rswpzmm5.mjs +926 -0
- package/dist/esm/index-s9mrx750.mjs +97 -0
- package/dist/esm/index-tvfexb7s.mjs +164 -0
- package/dist/esm/index-vp56k1gj.mjs +215 -0
- package/dist/esm/index-wxhvgv2s.mjs +79 -0
- package/dist/esm/index-wy95a41r.mjs +407 -0
- package/dist/esm/index-ysnwfc4t.mjs +306 -0
- package/dist/esm/index.mjs +49 -4053
- package/dist/esm/invert.mjs +54 -122
- package/dist/esm/iris-wipe.mjs +315 -0
- package/dist/esm/lens-blur.mjs +169 -156
- package/dist/esm/levels.mjs +134 -151
- package/dist/esm/light-leak.mjs +6 -416
- package/dist/esm/light-trail.mjs +124 -128
- package/dist/esm/linear-gradient-tint.mjs +4 -424
- package/dist/esm/linear-gradient.mjs +4 -370
- package/dist/esm/linear-progressive-blur.mjs +92 -118
- package/dist/esm/linear-progressive-pixelate.mjs +83 -378
- package/dist/esm/lines.mjs +167 -162
- package/dist/esm/liquid-contours.mjs +192 -153
- package/dist/esm/long-shadows.mjs +278 -251
- package/dist/esm/lut.mjs +123 -23
- package/dist/esm/mirror.mjs +78 -120
- package/dist/esm/noise-displacement.mjs +156 -151
- package/dist/esm/noise.mjs +107 -143
- package/dist/esm/outline.mjs +192 -170
- package/dist/esm/page-turn.mjs +141 -244
- package/dist/esm/paper.mjs +522 -194
- package/dist/esm/pattern.mjs +4 -568
- package/dist/esm/pixel-dissolve.mjs +158 -186
- package/dist/esm/pixelate.mjs +92 -149
- package/dist/esm/radial-progressive-blur.mjs +96 -118
- package/dist/esm/radial-progressive-pixelate.mjs +91 -384
- package/dist/esm/radial-wipe.mjs +224 -0
- package/dist/esm/rain-fall.mjs +114 -0
- package/dist/esm/region-blur.mjs +138 -192
- package/dist/esm/rings.mjs +6 -512
- package/dist/esm/roughen-edges.mjs +180 -156
- package/dist/esm/saturation.mjs +56 -122
- package/dist/esm/scale.mjs +50 -60
- package/dist/esm/scanlines.mjs +115 -149
- package/dist/esm/shadows-highlights.mjs +103 -205
- package/dist/esm/shatter.mjs +133 -153
- package/dist/esm/shine.mjs +192 -227
- package/dist/esm/shrinkwrap.mjs +388 -225
- package/dist/esm/skew.mjs +100 -145
- package/dist/esm/snow-fall.mjs +170 -0
- package/dist/esm/speckle.mjs +192 -210
- package/dist/esm/sphere.mjs +101 -225
- package/dist/esm/starburst.mjs +6 -345
- package/dist/esm/tear.mjs +138 -155
- package/dist/esm/thermal-vision.mjs +135 -152
- package/dist/esm/tile.mjs +5 -184
- package/dist/esm/tint.mjs +80 -132
- package/dist/esm/translate.mjs +55 -137
- package/dist/esm/turbulent-displace.mjs +182 -221
- package/dist/esm/tv-signal-off.mjs +140 -149
- package/dist/esm/venetian-blinds.mjs +91 -140
- package/dist/esm/vibrance.mjs +95 -204
- package/dist/esm/vignette.mjs +136 -155
- package/dist/esm/wave.mjs +88 -47
- package/dist/esm/waves.mjs +181 -169
- package/dist/esm/white-balance.mjs +100 -204
- package/dist/esm/white-noise.mjs +98 -146
- package/dist/esm/zigzag.mjs +6 -575
- package/dist/esm/zoom-blur.mjs +90 -121
- package/dist/evolve.d.ts +46 -10
- package/dist/film-burn-webgpu-shader.d.ts +1 -0
- package/dist/film-burn.d.ts +40 -0
- package/dist/fisheye/webgpu-shader.d.ts +1 -0
- package/dist/flannel-webgpu-shader.d.ts +1 -0
- package/dist/fractal-noise/shader.d.ts +1 -1
- package/dist/fractal-noise/webgpu-shader.d.ts +1 -0
- package/dist/gaussian-blur-webgpu-shader.d.ts +1 -0
- package/dist/glow/webgpu-shaders.d.ts +2 -0
- package/dist/gridlines-webgpu-shader.d.ts +1 -0
- package/dist/halftone-linear-gradient-webgpu-shader.d.ts +1 -0
- package/dist/halftone-webgpu-shader.d.ts +1 -0
- package/dist/iris-wipe.d.ts +78 -0
- package/dist/lens-blur/webgpu-shader.d.ts +1 -0
- package/dist/light-leak-webgpu-shader.d.ts +1 -0
- package/dist/light-trail/webgpu-shader.d.ts +1 -0
- package/dist/linear-gradient-tint-webgpu-shader.d.ts +1 -0
- package/dist/linear-gradient-webgpu-shader.d.ts +1 -0
- package/dist/lines-webgpu-shader.d.ts +1 -0
- package/dist/liquid-contours-webgpu-shader.d.ts +1 -0
- package/dist/long-shadows-webgpu-shaders.d.ts +2 -0
- package/dist/lut/webgpu-shader.d.ts +1 -0
- package/dist/mirror/webgpu-shader.d.ts +1 -0
- package/dist/noise-displacement-webgpu-shader.d.ts +1 -0
- package/dist/noise-webgpu-shader.d.ts +1 -0
- package/dist/outline/webgpu-shader.d.ts +1 -0
- package/dist/page-turn/webgl-shader.d.ts +1 -0
- package/dist/paper-webgpu-shader.d.ts +2 -0
- package/dist/pattern-webgpu-shader.d.ts +1 -0
- package/dist/pixel-dissolve-webgpu-shader.d.ts +1 -0
- package/dist/progressive-pixelate-runtime.d.ts +1 -0
- package/dist/radial-wipe.d.ts +19 -0
- package/dist/rain-fall.d.ts +143 -0
- package/dist/rect-transform-runtime.d.ts +11 -0
- package/dist/region-blur/webgpu-shader.d.ts +1 -0
- package/dist/rings-webgpu-shader.d.ts +1 -0
- package/dist/roughen-edges-webgpu-shader.d.ts +1 -0
- package/dist/shatter/webgpu-shader.d.ts +1 -0
- package/dist/shine-webgpu-shader.d.ts +1 -0
- package/dist/shrinkwrap-webgpu-shader.d.ts +1 -0
- package/dist/single-pass-runtime.d.ts +18 -0
- package/dist/skew-webgpu-shader.d.ts +1 -0
- package/dist/snow-fall.d.ts +208 -0
- package/dist/speckle-webgpu-shader.d.ts +1 -0
- package/dist/sphere/webgl-shader.d.ts +1 -0
- package/dist/starburst-webgpu-shader.d.ts +1 -0
- package/dist/tear-webgpu-shader.d.ts +1 -0
- package/dist/thermal-vision-webgpu-shader.d.ts +1 -0
- package/dist/tile-gpu-runtime.d.ts +24 -0
- package/dist/turbulent-displace/webgpu-shader.d.ts +1 -0
- package/dist/value-noise-webgpu-shader.d.ts +1 -0
- package/dist/vignette-webgpu-shader.d.ts +1 -0
- package/dist/wave/wave-runtime.d.ts +2 -1
- package/dist/wave/webgpu-shader.d.ts +1 -0
- package/dist/waves-webgpu-shader.d.ts +1 -0
- package/dist/weather/params.d.ts +149 -0
- package/dist/weather/runtime.d.ts +52 -0
- package/dist/weather/shaders.d.ts +4 -0
- package/dist/weather/webgpu-runtime.d.ts +36 -0
- package/dist/weather/webgpu-shader.d.ts +1 -0
- package/dist/webgl-projection-runtime.d.ts +18 -0
- package/dist/webgpu-color-state.d.ts +10 -0
- package/dist/webgpu-mesh-runtime.d.ts +46 -0
- package/dist/webgpu-multipass-runtime.d.ts +50 -0
- package/dist/webgpu-projection-runtime.d.ts +9 -5
- package/dist/webgpu-single-pass-runtime.d.ts +47 -0
- package/dist/white-noise-webgpu-shader.d.ts +1 -0
- package/dist/zigzag-webgpu-shader.d.ts +1 -0
- package/dist/zoom-blur/webgpu-shader.d.ts +1 -0
- package/package.json +43 -3
|
@@ -1,110 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WEBGPU_MULTIPASS_BINDINGS,
|
|
3
|
+
setupWebGpuMultipass,
|
|
4
|
+
cleanupWebGpuMultipass,
|
|
5
|
+
applyWebGpuMultipass
|
|
6
|
+
} from "./index-kkvzt8b7.mjs";
|
|
7
|
+
import {
|
|
8
|
+
assertOptionalFiniteNumber,
|
|
9
|
+
validateUnitInterval,
|
|
10
|
+
validateNonNegative,
|
|
11
|
+
parseColorRgba
|
|
12
|
+
} from "./index-wxhvgv2s.mjs";
|
|
13
|
+
import {
|
|
14
|
+
assertEffectParamsObject,
|
|
15
|
+
assertOptionalColor
|
|
16
|
+
} from "./index-4fvp93ps.mjs";
|
|
17
|
+
|
|
1
18
|
// src/long-shadows.ts
|
|
2
19
|
import { Internals } from "remotion";
|
|
3
20
|
|
|
4
|
-
// src/
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (typeof value !== "boolean") {
|
|
31
|
-
throw new TypeError(`"${name}" must be a boolean, but got ${JSON.stringify(value)}`);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
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
|
-
};
|
|
21
|
+
// src/long-shadows-webgpu-shaders.ts
|
|
22
|
+
var LONG_SHADOWS_EXTEND_WEBGPU_SHADER = `
|
|
23
|
+
${WEBGPU_MULTIPASS_BINDINGS}
|
|
24
|
+
struct Params {offset: vec4f,}
|
|
25
|
+
fn alphaAt(pixel: vec2i) -> f32 {
|
|
26
|
+
let size=vec2i(textureDimensions(source));
|
|
27
|
+
if (any(pixel<vec2i(0)) || any(pixel>=size)) {return 0.0;}
|
|
28
|
+
return textureLoad(source,pixel,0).a;
|
|
29
|
+
}
|
|
30
|
+
@fragment fn fragment(input: VertexOutput) -> @location(0) vec4f {
|
|
31
|
+
let pixel=(input.uv-params.offset.xy)*vec2f(textureDimensions(source))-0.5;
|
|
32
|
+
let base=vec2i(floor(pixel));let fraction=fract(pixel);
|
|
33
|
+
let shifted=mix(mix(alphaAt(base),alphaAt(base+vec2i(1,0)),fraction.x),mix(alphaAt(base+vec2i(0,1)),alphaAt(base+vec2i(1,1)),fraction.x),fraction.y);
|
|
34
|
+
return vec4f(0,0,0,max(textureSampleLevel(source,sourceSampler,input.uv,0).a,shifted));
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
var LONG_SHADOWS_COMPOSITE_WEBGPU_SHADER = `
|
|
38
|
+
${WEBGPU_MULTIPASS_BINDINGS}
|
|
39
|
+
struct Params {color: vec4f,}
|
|
40
|
+
@fragment fn fragment(input: VertexOutput) -> @location(0) vec4f {
|
|
41
|
+
let color=textureSampleLevel(source,sourceSampler,input.uv,0);
|
|
42
|
+
let alpha=textureSampleLevel(secondary,sourceSampler,input.uv,0).a*params.color.a;
|
|
43
|
+
return color+vec4f(params.color.rgb*alpha,alpha)*(1.0-color.a);
|
|
44
|
+
}`;
|
|
108
45
|
|
|
109
46
|
// src/long-shadows.ts
|
|
110
47
|
var { createEffect, createWebGL2ContextError } = Internals;
|
|
@@ -249,158 +186,248 @@ var longShadows = createEffect({
|
|
|
249
186
|
type: "remotion/long-shadows",
|
|
250
187
|
label: "longShadows()",
|
|
251
188
|
documentationLink: "https://www.remotion.dev/docs/effects/long-shadows",
|
|
252
|
-
backend: "webgl2",
|
|
253
189
|
calculateKey: (params) => {
|
|
254
190
|
const { length, angle, color, opacity } = resolve(params);
|
|
255
191
|
return `long-shadows-${length}-${angle}-${color}-${opacity}`;
|
|
256
192
|
},
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
193
|
+
implementations: {
|
|
194
|
+
webgpu: Internals.createEffectImplementation({
|
|
195
|
+
setup: (target) => {
|
|
196
|
+
const canvas = document.createElement("canvas");
|
|
197
|
+
canvas.width = 1;
|
|
198
|
+
canvas.height = 1;
|
|
199
|
+
const colorCtx = canvas.getContext("2d", { willReadFrequently: true });
|
|
200
|
+
if (!colorCtx)
|
|
201
|
+
throw new Error("Could not create color parser");
|
|
202
|
+
return {
|
|
203
|
+
...setupWebGpuMultipass(target, "long-shadows"),
|
|
204
|
+
colorCtx,
|
|
205
|
+
cachedColor: null,
|
|
206
|
+
cachedRgba: [0, 0, 0, 0]
|
|
207
|
+
};
|
|
208
|
+
},
|
|
209
|
+
apply: ({ source, width, height, params, state, gpuDevice }) => {
|
|
210
|
+
if (!gpuDevice)
|
|
211
|
+
throw new Error("A WebGPU device is required for this effect");
|
|
212
|
+
const r = resolve(params);
|
|
213
|
+
if (state.cachedColor !== r.color) {
|
|
214
|
+
state.cachedColor = r.color;
|
|
215
|
+
state.cachedRgba = parseColorRgba(state.colorCtx, r.color);
|
|
216
|
+
}
|
|
217
|
+
const color = state.cachedRgba.map((channel) => channel / 255);
|
|
218
|
+
const distance = r.opacity === 0 || color[3] === 0 ? 0 : Math.min(r.length, Math.hypot(width, height));
|
|
219
|
+
const steps = Math.ceil(distance);
|
|
220
|
+
const angle = r.angle % 360 * Math.PI / 180;
|
|
221
|
+
const stepLength = steps === 0 ? 0 : distance / steps;
|
|
222
|
+
const passes = [];
|
|
223
|
+
let covered = 0;
|
|
224
|
+
while (covered < steps) {
|
|
225
|
+
const extension = Math.min(covered + 1, steps - covered);
|
|
226
|
+
passes.push({
|
|
227
|
+
shader: LONG_SHADOWS_EXTEND_WEBGPU_SHADER,
|
|
228
|
+
uniforms: new Float32Array([
|
|
229
|
+
Math.cos(angle) * extension * stepLength / width,
|
|
230
|
+
Math.sin(angle) * extension * stepLength / height,
|
|
231
|
+
0,
|
|
232
|
+
0
|
|
233
|
+
]),
|
|
234
|
+
source: passes.length - 1,
|
|
235
|
+
secondary: -1
|
|
236
|
+
});
|
|
237
|
+
covered += extension;
|
|
238
|
+
}
|
|
239
|
+
passes.push({
|
|
240
|
+
shader: LONG_SHADOWS_COMPOSITE_WEBGPU_SHADER,
|
|
241
|
+
uniforms: new Float32Array([
|
|
242
|
+
color[0],
|
|
243
|
+
color[1],
|
|
244
|
+
color[2],
|
|
245
|
+
r.length === 0 ? 0 : color[3] * r.opacity
|
|
246
|
+
]),
|
|
247
|
+
source: -1,
|
|
248
|
+
secondary: passes.length - 1
|
|
249
|
+
});
|
|
250
|
+
applyWebGpuMultipass({
|
|
251
|
+
auxiliarySource: null,
|
|
252
|
+
state,
|
|
253
|
+
source,
|
|
254
|
+
width,
|
|
255
|
+
height,
|
|
256
|
+
device: gpuDevice,
|
|
257
|
+
passes
|
|
258
|
+
});
|
|
259
|
+
},
|
|
260
|
+
cleanup: cleanupWebGpuMultipass
|
|
261
|
+
}),
|
|
262
|
+
webgl2: Internals.createEffectImplementation({
|
|
263
|
+
setup: (target) => {
|
|
264
|
+
const gl = target.getContext("webgl2", {
|
|
265
|
+
premultipliedAlpha: true,
|
|
266
|
+
alpha: true,
|
|
267
|
+
preserveDrawingBuffer: true
|
|
268
|
+
});
|
|
269
|
+
if (!gl) {
|
|
270
|
+
throw createWebGL2ContextError("long shadows effect");
|
|
271
|
+
}
|
|
272
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
273
|
+
const extendProgram = createProgram(gl, EXTEND_SHADER);
|
|
274
|
+
const compositeProgram = createProgram(gl, COMPOSITE_SHADER);
|
|
275
|
+
const vao = gl.createVertexArray();
|
|
276
|
+
const vbo = gl.createBuffer();
|
|
277
|
+
const framebuffer = gl.createFramebuffer();
|
|
278
|
+
if (!vao || !vbo || !framebuffer) {
|
|
279
|
+
throw new Error("Failed to create long shadows buffers");
|
|
280
|
+
}
|
|
281
|
+
gl.bindVertexArray(vao);
|
|
282
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
283
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
|
|
284
|
+
-1,
|
|
285
|
+
-1,
|
|
286
|
+
0,
|
|
287
|
+
0,
|
|
288
|
+
1,
|
|
289
|
+
-1,
|
|
290
|
+
1,
|
|
291
|
+
0,
|
|
292
|
+
-1,
|
|
293
|
+
1,
|
|
294
|
+
0,
|
|
295
|
+
1,
|
|
296
|
+
1,
|
|
297
|
+
1,
|
|
298
|
+
1,
|
|
299
|
+
1
|
|
300
|
+
]), gl.STATIC_DRAW);
|
|
301
|
+
gl.enableVertexAttribArray(0);
|
|
302
|
+
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 16, 0);
|
|
303
|
+
gl.enableVertexAttribArray(1);
|
|
304
|
+
gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 16, 8);
|
|
305
|
+
gl.bindVertexArray(null);
|
|
306
|
+
const textures = [0, 1, 2].map(() => {
|
|
307
|
+
const texture = gl.createTexture();
|
|
308
|
+
if (!texture) {
|
|
309
|
+
throw new Error("Failed to create long shadows texture");
|
|
310
|
+
}
|
|
311
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
312
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
313
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
314
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
315
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
316
|
+
return texture;
|
|
317
|
+
});
|
|
318
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
319
|
+
const colorCanvas = document.createElement("canvas");
|
|
320
|
+
colorCanvas.width = 1;
|
|
321
|
+
colorCanvas.height = 1;
|
|
322
|
+
const colorCtx = colorCanvas.getContext("2d", {
|
|
323
|
+
willReadFrequently: true
|
|
324
|
+
});
|
|
325
|
+
if (!colorCtx) {
|
|
326
|
+
throw new Error("Failed to acquire 2D context for color parsing");
|
|
327
|
+
}
|
|
328
|
+
return {
|
|
329
|
+
gl,
|
|
330
|
+
extendProgram,
|
|
331
|
+
compositeProgram,
|
|
332
|
+
vao,
|
|
333
|
+
vbo,
|
|
334
|
+
framebuffer,
|
|
335
|
+
sourceTexture: textures[0],
|
|
336
|
+
shadowTextures: [textures[1], textures[2]],
|
|
337
|
+
extendSource: gl.getUniformLocation(extendProgram, "uSource"),
|
|
338
|
+
extendOffset: gl.getUniformLocation(extendProgram, "uOffset"),
|
|
339
|
+
compositeSource: gl.getUniformLocation(compositeProgram, "uSource"),
|
|
340
|
+
compositeShadow: gl.getUniformLocation(compositeProgram, "uShadow"),
|
|
341
|
+
compositeColor: gl.getUniformLocation(compositeProgram, "uColor"),
|
|
342
|
+
colorCtx,
|
|
343
|
+
cachedColor: "",
|
|
344
|
+
cachedRgba: [0, 0, 0, 0],
|
|
345
|
+
width: 0,
|
|
346
|
+
height: 0
|
|
347
|
+
};
|
|
348
|
+
},
|
|
349
|
+
apply: ({ source, width, height, params, state, flipSourceY }) => {
|
|
350
|
+
const { length, angle, color, opacity } = resolve(params);
|
|
351
|
+
const { gl, sourceTexture, shadowTextures, framebuffer } = state;
|
|
352
|
+
if (state.cachedColor !== color) {
|
|
353
|
+
state.cachedRgba = parseColorRgba(state.colorCtx, color);
|
|
354
|
+
state.cachedColor = color;
|
|
355
|
+
}
|
|
356
|
+
gl.viewport(0, 0, width, height);
|
|
357
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
358
|
+
gl.bindTexture(gl.TEXTURE_2D, sourceTexture);
|
|
359
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
|
|
360
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
|
|
361
|
+
if (state.width !== width || state.height !== height) {
|
|
362
|
+
for (const texture of shadowTextures) {
|
|
363
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
364
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
365
|
+
}
|
|
366
|
+
state.width = width;
|
|
367
|
+
state.height = height;
|
|
368
|
+
}
|
|
369
|
+
gl.bindVertexArray(state.vao);
|
|
370
|
+
gl.useProgram(state.extendProgram);
|
|
371
|
+
gl.uniform1i(state.extendSource, 0);
|
|
372
|
+
const distance = opacity === 0 || state.cachedRgba[3] === 0 ? 0 : Math.min(length, Math.hypot(width, height));
|
|
373
|
+
const steps = Math.ceil(distance);
|
|
374
|
+
const radians = angle % 360 * Math.PI / 180;
|
|
375
|
+
const stepLength = steps === 0 ? 0 : distance / steps;
|
|
376
|
+
let shadow = sourceTexture;
|
|
377
|
+
let covered = 0;
|
|
378
|
+
let pass = 0;
|
|
379
|
+
while (covered < steps) {
|
|
380
|
+
const extension = Math.min(covered + 1, steps - covered);
|
|
381
|
+
const output = shadowTextures[pass % 2];
|
|
382
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
383
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, output, 0);
|
|
384
|
+
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE) {
|
|
385
|
+
throw new Error("Long shadows framebuffer incomplete");
|
|
386
|
+
}
|
|
387
|
+
gl.bindTexture(gl.TEXTURE_2D, shadow);
|
|
388
|
+
gl.uniform2f(state.extendOffset, Math.cos(radians) * extension * stepLength / width, -Math.sin(radians) * extension * stepLength / height);
|
|
389
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
390
|
+
shadow = output;
|
|
391
|
+
covered += extension;
|
|
392
|
+
pass++;
|
|
393
|
+
}
|
|
394
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
395
|
+
gl.useProgram(state.compositeProgram);
|
|
396
|
+
gl.bindTexture(gl.TEXTURE_2D, sourceTexture);
|
|
397
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
398
|
+
gl.bindTexture(gl.TEXTURE_2D, shadow);
|
|
399
|
+
gl.uniform1i(state.compositeSource, 0);
|
|
400
|
+
gl.uniform1i(state.compositeShadow, 1);
|
|
401
|
+
const [r, g, b, a] = state.cachedRgba;
|
|
402
|
+
gl.uniform4f(state.compositeColor, r / 255, g / 255, b / 255, length === 0 ? 0 : a / 255 * opacity);
|
|
403
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
404
|
+
gl.bindVertexArray(null);
|
|
405
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
406
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
407
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
408
|
+
gl.useProgram(null);
|
|
409
|
+
},
|
|
410
|
+
cleanup: ({
|
|
411
|
+
gl,
|
|
412
|
+
extendProgram,
|
|
413
|
+
compositeProgram,
|
|
414
|
+
vao,
|
|
415
|
+
vbo,
|
|
416
|
+
framebuffer,
|
|
417
|
+
sourceTexture,
|
|
418
|
+
shadowTextures
|
|
419
|
+
}) => {
|
|
420
|
+
gl.deleteProgram(extendProgram);
|
|
421
|
+
gl.deleteProgram(compositeProgram);
|
|
422
|
+
gl.deleteVertexArray(vao);
|
|
423
|
+
gl.deleteBuffer(vbo);
|
|
424
|
+
gl.deleteFramebuffer(framebuffer);
|
|
425
|
+
gl.deleteTexture(sourceTexture);
|
|
426
|
+
for (const texture of shadowTextures) {
|
|
427
|
+
gl.deleteTexture(texture);
|
|
428
|
+
}
|
|
340
429
|
}
|
|
341
|
-
|
|
342
|
-
state.height = height;
|
|
343
|
-
}
|
|
344
|
-
gl.bindVertexArray(state.vao);
|
|
345
|
-
gl.useProgram(state.extendProgram);
|
|
346
|
-
gl.uniform1i(state.extendSource, 0);
|
|
347
|
-
const distance = opacity === 0 || state.cachedRgba[3] === 0 ? 0 : Math.min(length, Math.hypot(width, height));
|
|
348
|
-
const steps = Math.ceil(distance);
|
|
349
|
-
const radians = angle % 360 * Math.PI / 180;
|
|
350
|
-
const stepLength = steps === 0 ? 0 : distance / steps;
|
|
351
|
-
let shadow = sourceTexture;
|
|
352
|
-
let covered = 0;
|
|
353
|
-
let pass = 0;
|
|
354
|
-
while (covered < steps) {
|
|
355
|
-
const extension = Math.min(covered + 1, steps - covered);
|
|
356
|
-
const output = shadowTextures[pass % 2];
|
|
357
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
358
|
-
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, output, 0);
|
|
359
|
-
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE) {
|
|
360
|
-
throw new Error("Long shadows framebuffer incomplete");
|
|
361
|
-
}
|
|
362
|
-
gl.bindTexture(gl.TEXTURE_2D, shadow);
|
|
363
|
-
gl.uniform2f(state.extendOffset, Math.cos(radians) * extension * stepLength / width, -Math.sin(radians) * extension * stepLength / height);
|
|
364
|
-
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
365
|
-
shadow = output;
|
|
366
|
-
covered += extension;
|
|
367
|
-
pass++;
|
|
368
|
-
}
|
|
369
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
370
|
-
gl.useProgram(state.compositeProgram);
|
|
371
|
-
gl.bindTexture(gl.TEXTURE_2D, sourceTexture);
|
|
372
|
-
gl.activeTexture(gl.TEXTURE1);
|
|
373
|
-
gl.bindTexture(gl.TEXTURE_2D, shadow);
|
|
374
|
-
gl.uniform1i(state.compositeSource, 0);
|
|
375
|
-
gl.uniform1i(state.compositeShadow, 1);
|
|
376
|
-
const [r, g, b, a] = state.cachedRgba;
|
|
377
|
-
gl.uniform4f(state.compositeColor, r / 255, g / 255, b / 255, length === 0 ? 0 : a / 255 * opacity);
|
|
378
|
-
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
379
|
-
gl.bindVertexArray(null);
|
|
380
|
-
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
381
|
-
gl.activeTexture(gl.TEXTURE0);
|
|
382
|
-
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
383
|
-
gl.useProgram(null);
|
|
384
|
-
},
|
|
385
|
-
cleanup: ({
|
|
386
|
-
gl,
|
|
387
|
-
extendProgram,
|
|
388
|
-
compositeProgram,
|
|
389
|
-
vao,
|
|
390
|
-
vbo,
|
|
391
|
-
framebuffer,
|
|
392
|
-
sourceTexture,
|
|
393
|
-
shadowTextures
|
|
394
|
-
}) => {
|
|
395
|
-
gl.deleteProgram(extendProgram);
|
|
396
|
-
gl.deleteProgram(compositeProgram);
|
|
397
|
-
gl.deleteVertexArray(vao);
|
|
398
|
-
gl.deleteBuffer(vbo);
|
|
399
|
-
gl.deleteFramebuffer(framebuffer);
|
|
400
|
-
gl.deleteTexture(sourceTexture);
|
|
401
|
-
for (const texture of shadowTextures) {
|
|
402
|
-
gl.deleteTexture(texture);
|
|
403
|
-
}
|
|
430
|
+
})
|
|
404
431
|
},
|
|
405
432
|
schema: longShadowsSchema,
|
|
406
433
|
validateParams: validateLongShadowsParams
|