@remotion/effects 4.0.467 → 4.0.469
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/dist/color-utils.d.ts +2 -0
- package/dist/dot-grid.d.ts +31 -0
- package/dist/drop-shadow/drop-shadow-runtime.d.ts +54 -0
- package/dist/drop-shadow/drop-shadow-shaders.d.ts +5 -0
- package/dist/drop-shadow/index.d.ts +15 -0
- package/dist/drop-shadow.d.ts +1 -0
- package/dist/duotone.d.ts +31 -0
- package/dist/esm/barrel-distortion.mjs +14 -1
- package/dist/esm/blur.mjs +38 -17
- package/dist/esm/brightness.mjs +14 -1
- package/dist/esm/chromatic-aberration.mjs +14 -1
- package/dist/esm/contrast.mjs +14 -1
- package/dist/esm/dot-grid.mjs +349 -0
- package/dist/esm/drop-shadow.mjs +610 -0
- package/dist/esm/duotone.mjs +365 -0
- package/dist/esm/glow.mjs +599 -0
- package/dist/esm/grayscale.mjs +14 -1
- package/dist/esm/halftone-linear-gradient.mjs +480 -0
- package/dist/esm/halftone.mjs +17 -18
- package/dist/esm/hue.mjs +14 -1
- package/dist/esm/invert.mjs +14 -1
- package/dist/esm/mirror.mjs +14 -1
- package/dist/esm/noise.mjs +341 -0
- package/dist/esm/saturation.mjs +14 -1
- package/dist/esm/scale.mjs +7 -1
- package/dist/esm/shine.mjs +389 -0
- package/dist/esm/speckle.mjs +360 -0
- package/dist/esm/tint.mjs +14 -1
- package/dist/esm/translate.mjs +15 -2
- package/dist/esm/vignette.mjs +439 -0
- package/dist/esm/wave.mjs +7 -1
- package/dist/gaussian-blur-shader.d.ts +1 -0
- package/dist/glow/glow-runtime.d.ts +52 -0
- package/dist/glow/glow-shaders.d.ts +5 -0
- package/dist/glow/index.d.ts +13 -0
- package/dist/glow.d.ts +1 -0
- package/dist/halftone-linear-gradient.d.ts +93 -0
- package/dist/noise.d.ts +11 -0
- package/dist/shine.d.ts +17 -0
- package/dist/speckle.d.ts +11 -0
- package/dist/validate-effect-param.d.ts +1 -0
- package/dist/vignette.d.ts +68 -0
- package/package.json +75 -3
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
// src/drop-shadow/index.ts
|
|
2
|
+
import { Internals as Internals2 } from "remotion";
|
|
3
|
+
|
|
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
|
+
|
|
27
|
+
// src/color-utils.ts
|
|
28
|
+
var DEFAULT_AMOUNT = 1;
|
|
29
|
+
var DEFAULT_BRIGHTNESS_AMOUNT = 0;
|
|
30
|
+
var DEFAULT_HUE_DEGREES = 0;
|
|
31
|
+
var colorAmountSchema = {
|
|
32
|
+
type: "number",
|
|
33
|
+
min: 0,
|
|
34
|
+
max: 1,
|
|
35
|
+
step: 0.01,
|
|
36
|
+
default: DEFAULT_AMOUNT,
|
|
37
|
+
description: "Amount"
|
|
38
|
+
};
|
|
39
|
+
var colorMultiplierSchema = {
|
|
40
|
+
type: "number",
|
|
41
|
+
min: 0,
|
|
42
|
+
step: 0.01,
|
|
43
|
+
default: DEFAULT_AMOUNT,
|
|
44
|
+
description: "Amount"
|
|
45
|
+
};
|
|
46
|
+
var brightnessAmountSchema = {
|
|
47
|
+
type: "number",
|
|
48
|
+
min: -1,
|
|
49
|
+
max: 1,
|
|
50
|
+
step: 0.01,
|
|
51
|
+
default: DEFAULT_BRIGHTNESS_AMOUNT,
|
|
52
|
+
description: "Amount"
|
|
53
|
+
};
|
|
54
|
+
var hueDegreesSchema = {
|
|
55
|
+
type: "number",
|
|
56
|
+
step: 1,
|
|
57
|
+
default: DEFAULT_HUE_DEGREES,
|
|
58
|
+
description: "Degrees"
|
|
59
|
+
};
|
|
60
|
+
var assertOptionalFiniteNumber = (value, name) => {
|
|
61
|
+
if (value === undefined) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
assertRequiredFiniteNumber(value, name);
|
|
65
|
+
};
|
|
66
|
+
var validateUnitInterval = (value, name) => {
|
|
67
|
+
if (value < 0) {
|
|
68
|
+
throw new TypeError(`"${name}" must be >= 0, but got ${JSON.stringify(value)}`);
|
|
69
|
+
}
|
|
70
|
+
if (value > 1) {
|
|
71
|
+
throw new TypeError(`"${name}" must be <= 1, but got ${JSON.stringify(value)}`);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var validateNonNegative = (value, name) => {
|
|
75
|
+
if (value < 0) {
|
|
76
|
+
throw new TypeError(`"${name}" must be >= 0, but got ${JSON.stringify(value)}`);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var validateSignedUnitInterval = (value, name) => {
|
|
80
|
+
if (value < -1) {
|
|
81
|
+
throw new TypeError(`"${name}" must be >= -1, but got ${JSON.stringify(value)}`);
|
|
82
|
+
}
|
|
83
|
+
if (value > 1) {
|
|
84
|
+
throw new TypeError(`"${name}" must be <= 1, but got ${JSON.stringify(value)}`);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var clampColorChannel = (value) => {
|
|
88
|
+
return Math.max(0, Math.min(255, value));
|
|
89
|
+
};
|
|
90
|
+
var parseColorRgba = (ctx, color) => {
|
|
91
|
+
ctx.clearRect(0, 0, 1, 1);
|
|
92
|
+
ctx.fillStyle = color;
|
|
93
|
+
ctx.fillRect(0, 0, 1, 1);
|
|
94
|
+
const { data } = ctx.getImageData(0, 0, 1, 1);
|
|
95
|
+
return [data[0], data[1], data[2], data[3]];
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/drop-shadow/drop-shadow-runtime.ts
|
|
99
|
+
import { Internals } from "remotion";
|
|
100
|
+
|
|
101
|
+
// src/gaussian-blur-shader.ts
|
|
102
|
+
var buildGaussianBlurFs = (direction) => {
|
|
103
|
+
const dirVec = direction === "horizontal" ? "vec2(1.0, 0.0)" : "vec2(0.0, 1.0)";
|
|
104
|
+
return `#version 300 es
|
|
105
|
+
precision highp float;
|
|
106
|
+
|
|
107
|
+
in vec2 vUv;
|
|
108
|
+
out vec4 fragColor;
|
|
109
|
+
|
|
110
|
+
uniform sampler2D uSource;
|
|
111
|
+
uniform float uRadius;
|
|
112
|
+
uniform vec2 uTexelSize;
|
|
113
|
+
|
|
114
|
+
const int MIN_KERNEL_HALF = 4;
|
|
115
|
+
const int MAX_KERNEL_HALF = 32;
|
|
116
|
+
const float TARGET_SAMPLE_DISTANCE_PX = 2.0;
|
|
117
|
+
const vec2 DIRECTION = ${dirVec};
|
|
118
|
+
|
|
119
|
+
void main() {
|
|
120
|
+
if (uRadius <= 0.0) {
|
|
121
|
+
fragColor = texture(uSource, vUv);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
int kernelHalf = int(
|
|
126
|
+
min(
|
|
127
|
+
float(MAX_KERNEL_HALF),
|
|
128
|
+
max(float(MIN_KERNEL_HALF), ceil(uRadius / TARGET_SAMPLE_DISTANCE_PX))
|
|
129
|
+
)
|
|
130
|
+
);
|
|
131
|
+
float pixelStride = uRadius / float(kernelHalf);
|
|
132
|
+
float sigma = uRadius / 3.0;
|
|
133
|
+
float twoSigmaSq = 2.0 * sigma * sigma;
|
|
134
|
+
|
|
135
|
+
vec4 sum = vec4(0.0);
|
|
136
|
+
float weightSum = 0.0;
|
|
137
|
+
|
|
138
|
+
for (int i = -MAX_KERNEL_HALF; i <= MAX_KERNEL_HALF; ++i) {
|
|
139
|
+
if (abs(i) > kernelHalf) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
float offsetPx = float(i) * pixelStride;
|
|
144
|
+
float w = exp(-(offsetPx * offsetPx) / twoSigmaSq);
|
|
145
|
+
vec2 uv = vUv + DIRECTION * uTexelSize * offsetPx;
|
|
146
|
+
sum += texture(uSource, uv) * w;
|
|
147
|
+
weightSum += w;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
fragColor = sum / weightSum;
|
|
151
|
+
}
|
|
152
|
+
`;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// src/drop-shadow/drop-shadow-shaders.ts
|
|
156
|
+
var DROP_SHADOW_VS = `#version 300 es
|
|
157
|
+
layout(location = 0) in vec2 aPos;
|
|
158
|
+
layout(location = 1) in vec2 aUv;
|
|
159
|
+
out vec2 vUv;
|
|
160
|
+
|
|
161
|
+
void main() {
|
|
162
|
+
vUv = aUv;
|
|
163
|
+
gl_Position = vec4(aPos, 0.0, 1.0);
|
|
164
|
+
}
|
|
165
|
+
`;
|
|
166
|
+
var DROP_SHADOW_EXTRACT_FS = `#version 300 es
|
|
167
|
+
precision highp float;
|
|
168
|
+
|
|
169
|
+
in vec2 vUv;
|
|
170
|
+
out vec4 fragColor;
|
|
171
|
+
|
|
172
|
+
uniform sampler2D uSource;
|
|
173
|
+
uniform vec4 uColor;
|
|
174
|
+
uniform float uOpacity;
|
|
175
|
+
|
|
176
|
+
void main() {
|
|
177
|
+
vec4 source = texture(uSource, vUv);
|
|
178
|
+
float shadowAlpha = source.a * uColor.a * clamp(uOpacity, 0.0, 1.0);
|
|
179
|
+
|
|
180
|
+
fragColor = vec4(uColor.rgb * shadowAlpha, shadowAlpha);
|
|
181
|
+
}
|
|
182
|
+
`;
|
|
183
|
+
var DROP_SHADOW_BLUR_FS_HORIZONTAL = buildGaussianBlurFs("horizontal");
|
|
184
|
+
var DROP_SHADOW_BLUR_FS_VERTICAL = buildGaussianBlurFs("vertical");
|
|
185
|
+
var DROP_SHADOW_COMPOSITE_FS = `#version 300 es
|
|
186
|
+
precision highp float;
|
|
187
|
+
|
|
188
|
+
in vec2 vUv;
|
|
189
|
+
out vec4 fragColor;
|
|
190
|
+
|
|
191
|
+
uniform sampler2D uSource;
|
|
192
|
+
uniform sampler2D uShadow;
|
|
193
|
+
uniform vec2 uOffset;
|
|
194
|
+
uniform vec2 uTexelSize;
|
|
195
|
+
|
|
196
|
+
void main() {
|
|
197
|
+
vec4 source = texture(uSource, vUv);
|
|
198
|
+
vec2 shadowUv = vUv - vec2(uOffset.x, -uOffset.y) * uTexelSize;
|
|
199
|
+
vec4 shadow = vec4(0.0);
|
|
200
|
+
|
|
201
|
+
if (
|
|
202
|
+
shadowUv.x >= 0.0 &&
|
|
203
|
+
shadowUv.x <= 1.0 &&
|
|
204
|
+
shadowUv.y >= 0.0 &&
|
|
205
|
+
shadowUv.y <= 1.0
|
|
206
|
+
) {
|
|
207
|
+
shadow = texture(uShadow, shadowUv);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
fragColor = source + shadow * (1.0 - source.a);
|
|
211
|
+
}
|
|
212
|
+
`;
|
|
213
|
+
|
|
214
|
+
// src/drop-shadow/drop-shadow-runtime.ts
|
|
215
|
+
var { createWebGL2ContextError } = Internals;
|
|
216
|
+
var compileShader = (gl, type, source) => {
|
|
217
|
+
const shader = gl.createShader(type);
|
|
218
|
+
if (!shader) {
|
|
219
|
+
throw new Error("Failed to create WebGL shader");
|
|
220
|
+
}
|
|
221
|
+
gl.shaderSource(shader, source);
|
|
222
|
+
gl.compileShader(shader);
|
|
223
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
224
|
+
const log = gl.getShaderInfoLog(shader);
|
|
225
|
+
gl.deleteShader(shader);
|
|
226
|
+
throw new Error(`Drop shadow shader compile failed: ${log ?? "(no log)"}`);
|
|
227
|
+
}
|
|
228
|
+
return shader;
|
|
229
|
+
};
|
|
230
|
+
var linkProgram = (gl, vs, fs) => {
|
|
231
|
+
const program = gl.createProgram();
|
|
232
|
+
if (!program) {
|
|
233
|
+
throw new Error("Failed to create WebGL program");
|
|
234
|
+
}
|
|
235
|
+
gl.attachShader(program, vs);
|
|
236
|
+
gl.attachShader(program, fs);
|
|
237
|
+
gl.linkProgram(program);
|
|
238
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
239
|
+
const log = gl.getProgramInfoLog(program);
|
|
240
|
+
gl.deleteProgram(program);
|
|
241
|
+
throw new Error(`Drop shadow program link failed: ${log ?? "(no log)"}`);
|
|
242
|
+
}
|
|
243
|
+
return program;
|
|
244
|
+
};
|
|
245
|
+
var createProgram = (gl, vertexSource, fragmentSource) => {
|
|
246
|
+
const vs = compileShader(gl, gl.VERTEX_SHADER, vertexSource);
|
|
247
|
+
const fs = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
|
|
248
|
+
const program = linkProgram(gl, vs, fs);
|
|
249
|
+
gl.deleteShader(vs);
|
|
250
|
+
gl.deleteShader(fs);
|
|
251
|
+
return program;
|
|
252
|
+
};
|
|
253
|
+
var createRgbaTexture = (gl) => {
|
|
254
|
+
const texture = gl.createTexture();
|
|
255
|
+
if (!texture) {
|
|
256
|
+
throw new Error("Failed to create WebGL texture");
|
|
257
|
+
}
|
|
258
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
259
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
260
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
261
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
262
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
263
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
264
|
+
return texture;
|
|
265
|
+
};
|
|
266
|
+
var getBlurUniforms = (gl, program) => ({
|
|
267
|
+
uRadius: gl.getUniformLocation(program, "uRadius"),
|
|
268
|
+
uTexelSize: gl.getUniformLocation(program, "uTexelSize"),
|
|
269
|
+
uSource: gl.getUniformLocation(program, "uSource")
|
|
270
|
+
});
|
|
271
|
+
var setupDropShadow = (target) => {
|
|
272
|
+
const gl = target.getContext("webgl2", {
|
|
273
|
+
premultipliedAlpha: true,
|
|
274
|
+
alpha: true,
|
|
275
|
+
preserveDrawingBuffer: true
|
|
276
|
+
});
|
|
277
|
+
if (!gl) {
|
|
278
|
+
throw createWebGL2ContextError("drop shadow effect");
|
|
279
|
+
}
|
|
280
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
281
|
+
const programExtract = createProgram(gl, DROP_SHADOW_VS, DROP_SHADOW_EXTRACT_FS);
|
|
282
|
+
const programHorizontal = createProgram(gl, DROP_SHADOW_VS, DROP_SHADOW_BLUR_FS_HORIZONTAL);
|
|
283
|
+
const programVertical = createProgram(gl, DROP_SHADOW_VS, DROP_SHADOW_BLUR_FS_VERTICAL);
|
|
284
|
+
const programComposite = createProgram(gl, DROP_SHADOW_VS, DROP_SHADOW_COMPOSITE_FS);
|
|
285
|
+
const vao = gl.createVertexArray();
|
|
286
|
+
if (!vao) {
|
|
287
|
+
throw new Error("Failed to create WebGL vertex array");
|
|
288
|
+
}
|
|
289
|
+
gl.bindVertexArray(vao);
|
|
290
|
+
const data = new Float32Array([
|
|
291
|
+
-1,
|
|
292
|
+
-1,
|
|
293
|
+
0,
|
|
294
|
+
0,
|
|
295
|
+
1,
|
|
296
|
+
-1,
|
|
297
|
+
1,
|
|
298
|
+
0,
|
|
299
|
+
-1,
|
|
300
|
+
1,
|
|
301
|
+
0,
|
|
302
|
+
1,
|
|
303
|
+
1,
|
|
304
|
+
1,
|
|
305
|
+
1,
|
|
306
|
+
1
|
|
307
|
+
]);
|
|
308
|
+
const vbo = gl.createBuffer();
|
|
309
|
+
if (!vbo) {
|
|
310
|
+
throw new Error("Failed to create WebGL buffer");
|
|
311
|
+
}
|
|
312
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
313
|
+
gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
|
|
314
|
+
gl.enableVertexAttribArray(0);
|
|
315
|
+
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 16, 0);
|
|
316
|
+
gl.enableVertexAttribArray(1);
|
|
317
|
+
gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 16, 8);
|
|
318
|
+
gl.bindVertexArray(null);
|
|
319
|
+
const textureSource = createRgbaTexture(gl);
|
|
320
|
+
const textureShadowA = createRgbaTexture(gl);
|
|
321
|
+
const textureShadowB = createRgbaTexture(gl);
|
|
322
|
+
const framebuffer = gl.createFramebuffer();
|
|
323
|
+
if (!framebuffer) {
|
|
324
|
+
throw new Error("Failed to create WebGL framebuffer");
|
|
325
|
+
}
|
|
326
|
+
const colorCanvas = document.createElement("canvas");
|
|
327
|
+
colorCanvas.width = 1;
|
|
328
|
+
colorCanvas.height = 1;
|
|
329
|
+
const colorCtx = colorCanvas.getContext("2d", { willReadFrequently: true });
|
|
330
|
+
if (!colorCtx) {
|
|
331
|
+
throw new Error("Failed to acquire 2D context for color parsing");
|
|
332
|
+
}
|
|
333
|
+
return {
|
|
334
|
+
gl,
|
|
335
|
+
programExtract,
|
|
336
|
+
programHorizontal,
|
|
337
|
+
programVertical,
|
|
338
|
+
programComposite,
|
|
339
|
+
vao,
|
|
340
|
+
vbo,
|
|
341
|
+
textureSource,
|
|
342
|
+
textureShadowA,
|
|
343
|
+
textureShadowB,
|
|
344
|
+
framebuffer,
|
|
345
|
+
extract: {
|
|
346
|
+
uSource: gl.getUniformLocation(programExtract, "uSource"),
|
|
347
|
+
uColor: gl.getUniformLocation(programExtract, "uColor"),
|
|
348
|
+
uOpacity: gl.getUniformLocation(programExtract, "uOpacity")
|
|
349
|
+
},
|
|
350
|
+
horizontal: getBlurUniforms(gl, programHorizontal),
|
|
351
|
+
vertical: getBlurUniforms(gl, programVertical),
|
|
352
|
+
composite: {
|
|
353
|
+
uSource: gl.getUniformLocation(programComposite, "uSource"),
|
|
354
|
+
uShadow: gl.getUniformLocation(programComposite, "uShadow"),
|
|
355
|
+
uOffset: gl.getUniformLocation(programComposite, "uOffset"),
|
|
356
|
+
uTexelSize: gl.getUniformLocation(programComposite, "uTexelSize")
|
|
357
|
+
},
|
|
358
|
+
colorCtx,
|
|
359
|
+
cachedColorStr: "",
|
|
360
|
+
cachedColorRgba: [0, 0, 0, 255]
|
|
361
|
+
};
|
|
362
|
+
};
|
|
363
|
+
var cleanupDropShadow = ({
|
|
364
|
+
gl,
|
|
365
|
+
programExtract,
|
|
366
|
+
programHorizontal,
|
|
367
|
+
programVertical,
|
|
368
|
+
programComposite,
|
|
369
|
+
vao,
|
|
370
|
+
vbo,
|
|
371
|
+
textureSource,
|
|
372
|
+
textureShadowA,
|
|
373
|
+
textureShadowB,
|
|
374
|
+
framebuffer
|
|
375
|
+
}) => {
|
|
376
|
+
gl.deleteFramebuffer(framebuffer);
|
|
377
|
+
gl.deleteTexture(textureSource);
|
|
378
|
+
gl.deleteTexture(textureShadowA);
|
|
379
|
+
gl.deleteTexture(textureShadowB);
|
|
380
|
+
gl.deleteBuffer(vbo);
|
|
381
|
+
gl.deleteProgram(programExtract);
|
|
382
|
+
gl.deleteProgram(programHorizontal);
|
|
383
|
+
gl.deleteProgram(programVertical);
|
|
384
|
+
gl.deleteProgram(programComposite);
|
|
385
|
+
gl.deleteVertexArray(vao);
|
|
386
|
+
};
|
|
387
|
+
var drawFullscreenQuad = (state) => {
|
|
388
|
+
const { gl, vao } = state;
|
|
389
|
+
gl.bindVertexArray(vao);
|
|
390
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
391
|
+
gl.bindVertexArray(null);
|
|
392
|
+
};
|
|
393
|
+
var setTextureSize = (gl, texture, width, height) => {
|
|
394
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
395
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
396
|
+
};
|
|
397
|
+
var setFramebufferTexture = (gl, framebuffer, texture) => {
|
|
398
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
399
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
400
|
+
const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
|
|
401
|
+
if (status !== gl.FRAMEBUFFER_COMPLETE) {
|
|
402
|
+
throw new Error(`Drop shadow framebuffer incomplete: 0x${status.toString(16)}`);
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
var setBlurUniforms = ({
|
|
406
|
+
gl,
|
|
407
|
+
uniforms,
|
|
408
|
+
radius,
|
|
409
|
+
width,
|
|
410
|
+
height
|
|
411
|
+
}) => {
|
|
412
|
+
if (uniforms.uSource)
|
|
413
|
+
gl.uniform1i(uniforms.uSource, 0);
|
|
414
|
+
if (uniforms.uRadius)
|
|
415
|
+
gl.uniform1f(uniforms.uRadius, radius);
|
|
416
|
+
if (uniforms.uTexelSize) {
|
|
417
|
+
gl.uniform2f(uniforms.uTexelSize, 1 / width, 1 / height);
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
var normalizedColor = (color) => {
|
|
421
|
+
return [color[0] / 255, color[1] / 255, color[2] / 255, color[3] / 255];
|
|
422
|
+
};
|
|
423
|
+
var applyDropShadow = ({
|
|
424
|
+
state,
|
|
425
|
+
source,
|
|
426
|
+
width,
|
|
427
|
+
height,
|
|
428
|
+
radius,
|
|
429
|
+
offsetX,
|
|
430
|
+
offsetY,
|
|
431
|
+
opacity,
|
|
432
|
+
color,
|
|
433
|
+
flipSourceY
|
|
434
|
+
}) => {
|
|
435
|
+
const {
|
|
436
|
+
gl,
|
|
437
|
+
textureSource,
|
|
438
|
+
textureShadowA,
|
|
439
|
+
textureShadowB,
|
|
440
|
+
framebuffer,
|
|
441
|
+
programExtract,
|
|
442
|
+
programHorizontal,
|
|
443
|
+
programVertical,
|
|
444
|
+
programComposite
|
|
445
|
+
} = state;
|
|
446
|
+
gl.viewport(0, 0, width, height);
|
|
447
|
+
gl.clearColor(0, 0, 0, 0);
|
|
448
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
449
|
+
gl.bindTexture(gl.TEXTURE_2D, textureSource);
|
|
450
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
|
|
451
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
|
|
452
|
+
setTextureSize(gl, textureShadowA, width, height);
|
|
453
|
+
setTextureSize(gl, textureShadowB, width, height);
|
|
454
|
+
const [r, g, b, a] = normalizedColor(color);
|
|
455
|
+
setFramebufferTexture(gl, framebuffer, textureShadowA);
|
|
456
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
457
|
+
gl.useProgram(programExtract);
|
|
458
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
459
|
+
gl.bindTexture(gl.TEXTURE_2D, textureSource);
|
|
460
|
+
if (state.extract.uSource)
|
|
461
|
+
gl.uniform1i(state.extract.uSource, 0);
|
|
462
|
+
if (state.extract.uColor)
|
|
463
|
+
gl.uniform4f(state.extract.uColor, r, g, b, a);
|
|
464
|
+
if (state.extract.uOpacity)
|
|
465
|
+
gl.uniform1f(state.extract.uOpacity, opacity);
|
|
466
|
+
drawFullscreenQuad(state);
|
|
467
|
+
setFramebufferTexture(gl, framebuffer, textureShadowB);
|
|
468
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
469
|
+
gl.useProgram(programHorizontal);
|
|
470
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
471
|
+
gl.bindTexture(gl.TEXTURE_2D, textureShadowA);
|
|
472
|
+
setBlurUniforms({
|
|
473
|
+
gl,
|
|
474
|
+
uniforms: state.horizontal,
|
|
475
|
+
radius,
|
|
476
|
+
width,
|
|
477
|
+
height
|
|
478
|
+
});
|
|
479
|
+
drawFullscreenQuad(state);
|
|
480
|
+
setFramebufferTexture(gl, framebuffer, textureShadowA);
|
|
481
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
482
|
+
gl.useProgram(programVertical);
|
|
483
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
484
|
+
gl.bindTexture(gl.TEXTURE_2D, textureShadowB);
|
|
485
|
+
setBlurUniforms({
|
|
486
|
+
gl,
|
|
487
|
+
uniforms: state.vertical,
|
|
488
|
+
radius,
|
|
489
|
+
width,
|
|
490
|
+
height
|
|
491
|
+
});
|
|
492
|
+
drawFullscreenQuad(state);
|
|
493
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
494
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
495
|
+
gl.useProgram(programComposite);
|
|
496
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
497
|
+
gl.bindTexture(gl.TEXTURE_2D, textureSource);
|
|
498
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
499
|
+
gl.bindTexture(gl.TEXTURE_2D, textureShadowA);
|
|
500
|
+
if (state.composite.uSource)
|
|
501
|
+
gl.uniform1i(state.composite.uSource, 0);
|
|
502
|
+
if (state.composite.uShadow)
|
|
503
|
+
gl.uniform1i(state.composite.uShadow, 1);
|
|
504
|
+
if (state.composite.uOffset) {
|
|
505
|
+
gl.uniform2f(state.composite.uOffset, offsetX, offsetY);
|
|
506
|
+
}
|
|
507
|
+
if (state.composite.uTexelSize) {
|
|
508
|
+
gl.uniform2f(state.composite.uTexelSize, 1 / width, 1 / height);
|
|
509
|
+
}
|
|
510
|
+
drawFullscreenQuad(state);
|
|
511
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
512
|
+
gl.useProgram(null);
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
// src/drop-shadow/index.ts
|
|
516
|
+
var { createEffect } = Internals2;
|
|
517
|
+
var DEFAULT_RADIUS = 12;
|
|
518
|
+
var DEFAULT_OFFSET_X = 8;
|
|
519
|
+
var DEFAULT_OFFSET_Y = 8;
|
|
520
|
+
var DEFAULT_OPACITY = 0.5;
|
|
521
|
+
var DEFAULT_COLOR = "#000000";
|
|
522
|
+
var dropShadowSchema = {
|
|
523
|
+
radius: {
|
|
524
|
+
type: "number",
|
|
525
|
+
min: 0,
|
|
526
|
+
max: 100,
|
|
527
|
+
step: 1,
|
|
528
|
+
default: DEFAULT_RADIUS,
|
|
529
|
+
description: "Radius"
|
|
530
|
+
},
|
|
531
|
+
offsetX: {
|
|
532
|
+
type: "number",
|
|
533
|
+
step: 1,
|
|
534
|
+
default: DEFAULT_OFFSET_X,
|
|
535
|
+
description: "Offset X"
|
|
536
|
+
},
|
|
537
|
+
offsetY: {
|
|
538
|
+
type: "number",
|
|
539
|
+
step: 1,
|
|
540
|
+
default: DEFAULT_OFFSET_Y,
|
|
541
|
+
description: "Offset Y"
|
|
542
|
+
},
|
|
543
|
+
opacity: {
|
|
544
|
+
type: "number",
|
|
545
|
+
min: 0,
|
|
546
|
+
max: 1,
|
|
547
|
+
step: 0.01,
|
|
548
|
+
default: DEFAULT_OPACITY,
|
|
549
|
+
description: "Opacity"
|
|
550
|
+
},
|
|
551
|
+
color: {
|
|
552
|
+
type: "color",
|
|
553
|
+
default: DEFAULT_COLOR,
|
|
554
|
+
description: "Color"
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
var resolve = (p) => ({
|
|
558
|
+
radius: p.radius ?? DEFAULT_RADIUS,
|
|
559
|
+
offsetX: p.offsetX ?? DEFAULT_OFFSET_X,
|
|
560
|
+
offsetY: p.offsetY ?? DEFAULT_OFFSET_Y,
|
|
561
|
+
opacity: p.opacity ?? DEFAULT_OPACITY,
|
|
562
|
+
color: p.color ?? DEFAULT_COLOR
|
|
563
|
+
});
|
|
564
|
+
var validateDropShadowParams = (params) => {
|
|
565
|
+
assertEffectParamsObject(params, "Drop shadow");
|
|
566
|
+
assertOptionalFiniteNumber(params.radius, "radius");
|
|
567
|
+
assertOptionalFiniteNumber(params.offsetX, "offsetX");
|
|
568
|
+
assertOptionalFiniteNumber(params.offsetY, "offsetY");
|
|
569
|
+
assertOptionalFiniteNumber(params.opacity, "opacity");
|
|
570
|
+
assertOptionalColor(params.color, "color");
|
|
571
|
+
const r = resolve(params);
|
|
572
|
+
validateNonNegative(r.radius, "radius");
|
|
573
|
+
validateUnitInterval(r.opacity, "opacity");
|
|
574
|
+
};
|
|
575
|
+
var dropShadow = createEffect({
|
|
576
|
+
type: "remotion/drop-shadow",
|
|
577
|
+
label: "dropShadow()",
|
|
578
|
+
documentationLink: "https://www.remotion.dev/docs/effects/drop-shadow",
|
|
579
|
+
backend: "webgl2",
|
|
580
|
+
calculateKey: (params) => {
|
|
581
|
+
const r = resolve(params);
|
|
582
|
+
return `drop-shadow-${r.radius}-${r.offsetX}-${r.offsetY}-${r.opacity}-${r.color}`;
|
|
583
|
+
},
|
|
584
|
+
setup: (target) => setupDropShadow(target),
|
|
585
|
+
apply: ({ source, width, height, params, state, flipSourceY }) => {
|
|
586
|
+
const r = resolve(params);
|
|
587
|
+
if (state.cachedColorStr !== r.color) {
|
|
588
|
+
state.cachedColorStr = r.color;
|
|
589
|
+
state.cachedColorRgba = parseColorRgba(state.colorCtx, r.color);
|
|
590
|
+
}
|
|
591
|
+
applyDropShadow({
|
|
592
|
+
state,
|
|
593
|
+
source,
|
|
594
|
+
width,
|
|
595
|
+
height,
|
|
596
|
+
radius: r.radius,
|
|
597
|
+
offsetX: r.offsetX,
|
|
598
|
+
offsetY: r.offsetY,
|
|
599
|
+
opacity: r.opacity,
|
|
600
|
+
color: state.cachedColorRgba,
|
|
601
|
+
flipSourceY
|
|
602
|
+
});
|
|
603
|
+
},
|
|
604
|
+
cleanup: (state) => cleanupDropShadow(state),
|
|
605
|
+
schema: dropShadowSchema,
|
|
606
|
+
validateParams: validateDropShadowParams
|
|
607
|
+
});
|
|
608
|
+
export {
|
|
609
|
+
dropShadow
|
|
610
|
+
};
|