@remotion/effects 4.0.460 → 4.0.462

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.
@@ -1,5 +1,4 @@
1
- import type { EffectDescriptor } from 'remotion';
2
1
  export type BlurHorizontalParams = {
3
2
  readonly radius: number;
4
3
  };
5
- export declare const blurHorizontal: (params: BlurHorizontalParams) => EffectDescriptor<unknown>;
4
+ export declare const blurHorizontal: (params: BlurHorizontalParams) => import("remotion").EffectDescriptor<unknown>;
@@ -1,13 +1,31 @@
1
1
  export type BlurState = {
2
2
  gl: WebGL2RenderingContext;
3
- program: WebGLProgram;
3
+ programHorizontal: WebGLProgram;
4
+ programVertical: WebGLProgram;
4
5
  vao: WebGLVertexArrayObject;
5
6
  vbo: WebGLBuffer;
6
- texture: WebGLTexture;
7
- uRadius: WebGLUniformLocation | null;
8
- uTexelSize: WebGLUniformLocation | null;
9
- uSource: WebGLUniformLocation | null;
7
+ textureSource: WebGLTexture;
8
+ textureIntermediate: WebGLTexture;
9
+ framebuffer: WebGLFramebuffer;
10
+ horizontal: {
11
+ uRadius: WebGLUniformLocation | null;
12
+ uTexelSize: WebGLUniformLocation | null;
13
+ uSource: WebGLUniformLocation | null;
14
+ };
15
+ vertical: {
16
+ uRadius: WebGLUniformLocation | null;
17
+ uTexelSize: WebGLUniformLocation | null;
18
+ uSource: WebGLUniformLocation | null;
19
+ };
10
20
  };
11
- export declare const setupBlur: (target: HTMLCanvasElement, fragmentSource: string) => BlurState;
21
+ export declare const setupBlur: (target: HTMLCanvasElement) => BlurState;
12
22
  export declare const cleanupBlur: (state: BlurState) => void;
13
- export declare const applyBlur: (state: BlurState, source: CanvasImageSource, width: number, height: number, radius: number) => void;
23
+ type ApplyBlurParams = {
24
+ readonly state: BlurState;
25
+ readonly source: CanvasImageSource;
26
+ readonly width: number;
27
+ readonly height: number;
28
+ readonly radius: number;
29
+ };
30
+ export declare const applyBlur: ({ state, source, width, height, radius, }: ApplyBlurParams) => void;
31
+ export {};
@@ -1,3 +1,3 @@
1
- export declare const BLUR_VS = "#version 300 es\nin vec2 aPos;\nin vec2 aUv;\nout vec2 vUv;\nvoid main() {\n\tvUv = aUv;\n\tgl_Position = vec4(aPos, 0.0, 1.0);\n}\n";
1
+ export declare const BLUR_VS = "#version 300 es\nlayout(location = 0) in vec2 aPos;\nlayout(location = 1) in vec2 aUv;\nout vec2 vUv;\nvoid main() {\n\tvUv = aUv;\n\tgl_Position = vec4(aPos, 0.0, 1.0);\n}\n";
2
2
  export declare const BLUR_FS_HORIZONTAL: string;
3
3
  export declare const BLUR_FS_VERTICAL: string;
@@ -1,5 +1,4 @@
1
- import type { EffectDescriptor } from 'remotion';
2
1
  export type BlurVerticalParams = {
3
2
  readonly radius: number;
4
3
  };
5
- export declare const blurVertical: (params: BlurVerticalParams) => EffectDescriptor<unknown>;
4
+ export declare const blurVertical: (params: BlurVerticalParams) => import("remotion").EffectDescriptor<unknown>;
@@ -1,9 +1,4 @@
1
- import type { EffectDescriptor } from 'remotion';
2
1
  export type BlurParams = {
3
2
  readonly radius: number;
4
3
  };
5
- export declare const blur: (params: BlurParams) => readonly [EffectDescriptor<unknown>, EffectDescriptor<unknown>];
6
- export { blurHorizontal } from './blur-horizontal.js';
7
- export type { BlurHorizontalParams } from './blur-horizontal.js';
8
- export { blurVertical } from './blur-vertical.js';
9
- export type { BlurVerticalParams } from './blur-vertical.js';
4
+ export declare const blur: (params: BlurParams) => import("remotion").EffectDescriptor<unknown>;
@@ -0,0 +1,4 @@
1
+ import * as blurExports from '../blur/index.js';
2
+ export type { BlurParams } from '../blur/index.js';
3
+ declare const blur: (params: blurExports.BlurParams) => import("remotion").EffectDescriptor<unknown>;
4
+ export { blur };
@@ -0,0 +1,330 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, {
5
+ get: all[name],
6
+ enumerable: true,
7
+ configurable: true,
8
+ set: (newValue) => all[name] = () => newValue
9
+ });
10
+ };
11
+
12
+ // src/blur/index.ts
13
+ var exports_blur = {};
14
+ __export(exports_blur, {
15
+ blur: () => blur
16
+ });
17
+ import { Internals } from "remotion";
18
+
19
+ // src/blur/blur-shaders.ts
20
+ var BLUR_VS = `#version 300 es
21
+ layout(location = 0) in vec2 aPos;
22
+ layout(location = 1) in vec2 aUv;
23
+ out vec2 vUv;
24
+ void main() {
25
+ vUv = aUv;
26
+ gl_Position = vec4(aPos, 0.0, 1.0);
27
+ }
28
+ `;
29
+ var buildFs = (direction) => {
30
+ const dirVec = direction === "horizontal" ? "vec2(1.0, 0.0)" : "vec2(0.0, 1.0)";
31
+ return `#version 300 es
32
+ precision highp float;
33
+ in vec2 vUv;
34
+ out vec4 fragColor;
35
+
36
+ uniform sampler2D uSource;
37
+ uniform float uRadius;
38
+ uniform vec2 uTexelSize;
39
+
40
+ const int KERNEL_HALF = 4;
41
+ const vec2 DIRECTION = ${dirVec};
42
+
43
+ void main() {
44
+ if (uRadius <= 0.0) {
45
+ fragColor = texture(uSource, vUv);
46
+ return;
47
+ }
48
+
49
+ float pixelStride = uRadius / float(KERNEL_HALF);
50
+ float sigma = uRadius / 3.0;
51
+ float twoSigmaSq = 2.0 * sigma * sigma;
52
+
53
+ vec4 sum = vec4(0.0);
54
+ float weightSum = 0.0;
55
+
56
+ for (int i = -KERNEL_HALF; i <= KERNEL_HALF; ++i) {
57
+ float offsetPx = float(i) * pixelStride;
58
+ float w = exp(-(offsetPx * offsetPx) / twoSigmaSq);
59
+ vec2 uv = vUv + DIRECTION * uTexelSize * offsetPx;
60
+ sum += texture(uSource, uv) * w;
61
+ weightSum += w;
62
+ }
63
+
64
+ fragColor = sum / weightSum;
65
+ }
66
+ `;
67
+ };
68
+ var BLUR_FS_HORIZONTAL = buildFs("horizontal");
69
+ var BLUR_FS_VERTICAL = buildFs("vertical");
70
+
71
+ // src/blur/blur-runtime.ts
72
+ var compileShader = (gl, type, source) => {
73
+ const shader = gl.createShader(type);
74
+ if (!shader) {
75
+ throw new Error("Failed to create WebGL shader");
76
+ }
77
+ gl.shaderSource(shader, source);
78
+ gl.compileShader(shader);
79
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
80
+ const log = gl.getShaderInfoLog(shader);
81
+ gl.deleteShader(shader);
82
+ throw new Error(`Shader compile failed: ${log ?? "(no log)"}`);
83
+ }
84
+ return shader;
85
+ };
86
+ var linkProgram = (gl, vs, fs) => {
87
+ const program = gl.createProgram();
88
+ if (!program) {
89
+ throw new Error("Failed to create WebGL program");
90
+ }
91
+ gl.attachShader(program, vs);
92
+ gl.attachShader(program, fs);
93
+ gl.linkProgram(program);
94
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
95
+ const log = gl.getProgramInfoLog(program);
96
+ gl.deleteProgram(program);
97
+ throw new Error(`Program link failed: ${log ?? "(no log)"}`);
98
+ }
99
+ return program;
100
+ };
101
+ var createProgram = (gl, vertexSource, fragmentSource) => {
102
+ const vs = compileShader(gl, gl.VERTEX_SHADER, vertexSource);
103
+ const fs = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
104
+ const program = linkProgram(gl, vs, fs);
105
+ gl.deleteShader(vs);
106
+ gl.deleteShader(fs);
107
+ return program;
108
+ };
109
+ var getBlurUniforms = (gl, program) => ({
110
+ uRadius: gl.getUniformLocation(program, "uRadius"),
111
+ uTexelSize: gl.getUniformLocation(program, "uTexelSize"),
112
+ uSource: gl.getUniformLocation(program, "uSource")
113
+ });
114
+ var createRgbaTexture = (gl) => {
115
+ const texture = gl.createTexture();
116
+ if (!texture) {
117
+ throw new Error("Failed to create WebGL texture");
118
+ }
119
+ gl.bindTexture(gl.TEXTURE_2D, texture);
120
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
121
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
122
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
123
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
124
+ gl.bindTexture(gl.TEXTURE_2D, null);
125
+ return texture;
126
+ };
127
+ var setupBlur = (target) => {
128
+ const gl = target.getContext("webgl2", {
129
+ premultipliedAlpha: true,
130
+ alpha: true,
131
+ preserveDrawingBuffer: true
132
+ });
133
+ if (!gl) {
134
+ throw new Error("Failed to acquire WebGL2 context for blur effect");
135
+ }
136
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
137
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
138
+ const programHorizontal = createProgram(gl, BLUR_VS, BLUR_FS_HORIZONTAL);
139
+ const programVertical = createProgram(gl, BLUR_VS, BLUR_FS_VERTICAL);
140
+ const vao = gl.createVertexArray();
141
+ if (!vao) {
142
+ throw new Error("Failed to create WebGL vertex array");
143
+ }
144
+ gl.bindVertexArray(vao);
145
+ const data = new Float32Array([
146
+ -1,
147
+ -1,
148
+ 0,
149
+ 0,
150
+ 1,
151
+ -1,
152
+ 1,
153
+ 0,
154
+ -1,
155
+ 1,
156
+ 0,
157
+ 1,
158
+ 1,
159
+ 1,
160
+ 1,
161
+ 1
162
+ ]);
163
+ const vbo = gl.createBuffer();
164
+ if (!vbo) {
165
+ throw new Error("Failed to create WebGL buffer");
166
+ }
167
+ gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
168
+ gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
169
+ gl.enableVertexAttribArray(0);
170
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 16, 0);
171
+ gl.enableVertexAttribArray(1);
172
+ gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 16, 8);
173
+ gl.bindVertexArray(null);
174
+ const textureSource = createRgbaTexture(gl);
175
+ const textureIntermediate = createRgbaTexture(gl);
176
+ const framebuffer = gl.createFramebuffer();
177
+ if (!framebuffer) {
178
+ throw new Error("Failed to create WebGL framebuffer");
179
+ }
180
+ const w = Math.max(1, target.width);
181
+ const h = Math.max(1, target.height);
182
+ gl.bindTexture(gl.TEXTURE_2D, textureIntermediate);
183
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, w, h, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
184
+ gl.bindTexture(gl.TEXTURE_2D, null);
185
+ gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
186
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, textureIntermediate, 0);
187
+ const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
188
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
189
+ if (status !== gl.FRAMEBUFFER_COMPLETE) {
190
+ throw new Error(`Blur framebuffer incomplete: 0x${status.toString(16)}`);
191
+ }
192
+ return {
193
+ gl,
194
+ programHorizontal,
195
+ programVertical,
196
+ vao,
197
+ vbo,
198
+ textureSource,
199
+ textureIntermediate,
200
+ framebuffer,
201
+ horizontal: getBlurUniforms(gl, programHorizontal),
202
+ vertical: getBlurUniforms(gl, programVertical)
203
+ };
204
+ };
205
+ var cleanupBlur = (state) => {
206
+ const {
207
+ gl,
208
+ programHorizontal,
209
+ programVertical,
210
+ vao,
211
+ vbo,
212
+ textureSource,
213
+ textureIntermediate,
214
+ framebuffer
215
+ } = state;
216
+ gl.deleteFramebuffer(framebuffer);
217
+ gl.deleteTexture(textureSource);
218
+ gl.deleteTexture(textureIntermediate);
219
+ gl.deleteBuffer(vbo);
220
+ gl.deleteProgram(programHorizontal);
221
+ gl.deleteProgram(programVertical);
222
+ gl.deleteVertexArray(vao);
223
+ };
224
+ var setBlurUniforms = ({
225
+ gl,
226
+ uniforms,
227
+ radius,
228
+ width,
229
+ height
230
+ }) => {
231
+ if (uniforms.uSource)
232
+ gl.uniform1i(uniforms.uSource, 0);
233
+ if (uniforms.uRadius)
234
+ gl.uniform1f(uniforms.uRadius, radius);
235
+ if (uniforms.uTexelSize)
236
+ gl.uniform2f(uniforms.uTexelSize, 1 / width, 1 / height);
237
+ };
238
+ var drawFullscreenQuad = (state) => {
239
+ const { gl, vao } = state;
240
+ gl.bindVertexArray(vao);
241
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
242
+ gl.bindVertexArray(null);
243
+ };
244
+ var applyBlur = ({
245
+ state,
246
+ source,
247
+ width,
248
+ height,
249
+ radius
250
+ }) => {
251
+ const {
252
+ gl,
253
+ programHorizontal,
254
+ programVertical,
255
+ textureSource,
256
+ textureIntermediate,
257
+ framebuffer
258
+ } = state;
259
+ gl.viewport(0, 0, width, height);
260
+ gl.bindTexture(gl.TEXTURE_2D, textureSource);
261
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
262
+ gl.bindTexture(gl.TEXTURE_2D, textureIntermediate);
263
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
264
+ gl.bindTexture(gl.TEXTURE_2D, null);
265
+ gl.clearColor(0, 0, 0, 0);
266
+ gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
267
+ gl.clear(gl.COLOR_BUFFER_BIT);
268
+ gl.activeTexture(gl.TEXTURE0);
269
+ gl.bindTexture(gl.TEXTURE_2D, textureSource);
270
+ gl.useProgram(programHorizontal);
271
+ setBlurUniforms({
272
+ gl,
273
+ uniforms: state.horizontal,
274
+ radius,
275
+ width,
276
+ height
277
+ });
278
+ drawFullscreenQuad(state);
279
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
280
+ gl.clear(gl.COLOR_BUFFER_BIT);
281
+ gl.bindTexture(gl.TEXTURE_2D, textureIntermediate);
282
+ gl.useProgram(programVertical);
283
+ setBlurUniforms({
284
+ gl,
285
+ uniforms: state.vertical,
286
+ radius,
287
+ width,
288
+ height
289
+ });
290
+ drawFullscreenQuad(state);
291
+ gl.bindTexture(gl.TEXTURE_2D, null);
292
+ gl.useProgram(null);
293
+ };
294
+
295
+ // src/blur/index.ts
296
+ var { createEffect } = Internals;
297
+ var blurSchema = {
298
+ radius: {
299
+ type: "number",
300
+ min: 0,
301
+ max: 100,
302
+ step: 1,
303
+ default: 10,
304
+ description: "Blur radius"
305
+ }
306
+ };
307
+ var blur = createEffect({
308
+ type: "remotion/blur",
309
+ label: "Blur",
310
+ backend: "webgl2",
311
+ calculateKey: (params) => String(params.radius),
312
+ setup: (target) => setupBlur(target),
313
+ apply: ({ source, width, height, params, state }) => {
314
+ applyBlur({
315
+ state,
316
+ source,
317
+ width,
318
+ height,
319
+ radius: params.radius
320
+ });
321
+ },
322
+ cleanup: (state) => cleanupBlur(state),
323
+ schema: blurSchema
324
+ });
325
+
326
+ // src/entrypoints/blur.ts
327
+ var { blur: blur2 } = exports_blur;
328
+ export {
329
+ blur2 as blur
330
+ };