@remotion/effects 4.0.525 → 4.0.527

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.
@@ -0,0 +1,501 @@
1
+ // src/lut/index.ts
2
+ import { Internals as Internals2 } from "remotion";
3
+
4
+ // src/lut/lut-runtime.ts
5
+ import { Internals } from "remotion";
6
+
7
+ // src/lut/lut-shaders.ts
8
+ var LUT_VERTEX_SHADER = `#version 300 es
9
+ layout(location = 0) in vec2 aPos;
10
+ layout(location = 1) in vec2 aUv;
11
+ out vec2 vUv;
12
+
13
+ void main() {
14
+ vUv = aUv;
15
+ gl_Position = vec4(aPos, 0.0, 1.0);
16
+ }
17
+ `;
18
+ var LUT_FRAGMENT_SHADER = `#version 300 es
19
+ precision highp float;
20
+ precision highp sampler3D;
21
+
22
+ in vec2 vUv;
23
+ out vec4 fragColor;
24
+
25
+ uniform sampler2D uSource;
26
+ uniform sampler3D uLut;
27
+ uniform int uLutSize;
28
+ uniform vec3 uDomainMin;
29
+ uniform vec3 uDomainMax;
30
+
31
+ vec3 sampleLut(vec3 color) {
32
+ vec3 normalizedColor = clamp(
33
+ (color - uDomainMin) / (uDomainMax - uDomainMin),
34
+ vec3(0.0),
35
+ vec3(1.0)
36
+ );
37
+ vec3 position = normalizedColor * float(uLutSize - 1);
38
+ ivec3 lower = ivec3(floor(position));
39
+ ivec3 upper = min(lower + ivec3(1), ivec3(uLutSize - 1));
40
+ vec3 fraction = fract(position);
41
+
42
+ vec3 c000 = texelFetch(uLut, ivec3(lower.x, lower.y, lower.z), 0).rgb;
43
+ vec3 c100 = texelFetch(uLut, ivec3(upper.x, lower.y, lower.z), 0).rgb;
44
+ vec3 c010 = texelFetch(uLut, ivec3(lower.x, upper.y, lower.z), 0).rgb;
45
+ vec3 c110 = texelFetch(uLut, ivec3(upper.x, upper.y, lower.z), 0).rgb;
46
+ vec3 c001 = texelFetch(uLut, ivec3(lower.x, lower.y, upper.z), 0).rgb;
47
+ vec3 c101 = texelFetch(uLut, ivec3(upper.x, lower.y, upper.z), 0).rgb;
48
+ vec3 c011 = texelFetch(uLut, ivec3(lower.x, upper.y, upper.z), 0).rgb;
49
+ vec3 c111 = texelFetch(uLut, ivec3(upper.x, upper.y, upper.z), 0).rgb;
50
+
51
+ vec3 c00 = mix(c000, c100, fraction.x);
52
+ vec3 c10 = mix(c010, c110, fraction.x);
53
+ vec3 c01 = mix(c001, c101, fraction.x);
54
+ vec3 c11 = mix(c011, c111, fraction.x);
55
+ vec3 c0 = mix(c00, c10, fraction.y);
56
+ vec3 c1 = mix(c01, c11, fraction.y);
57
+ return mix(c0, c1, fraction.z);
58
+ }
59
+
60
+ void main() {
61
+ vec4 sourceColor = texture(uSource, vUv);
62
+ float alpha = sourceColor.a;
63
+
64
+ if (alpha <= 0.0) {
65
+ fragColor = vec4(0.0);
66
+ return;
67
+ }
68
+
69
+ vec3 straightColor = sourceColor.rgb / alpha;
70
+ vec3 transformedColor = sampleLut(straightColor);
71
+ fragColor = vec4(transformedColor * alpha, alpha);
72
+ }
73
+ `;
74
+
75
+ // src/lut/lut-runtime.ts
76
+ var { createWebGL2ContextError } = Internals;
77
+ var compileShader = (gl, type, source) => {
78
+ const shader = gl.createShader(type);
79
+ if (!shader) {
80
+ throw new Error("Failed to create LUT shader");
81
+ }
82
+ gl.shaderSource(shader, source);
83
+ gl.compileShader(shader);
84
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
85
+ const log = gl.getShaderInfoLog(shader);
86
+ gl.deleteShader(shader);
87
+ throw new Error(`LUT shader compile failed: ${log ?? "(no log)"}`);
88
+ }
89
+ return shader;
90
+ };
91
+ var createProgram = (gl) => {
92
+ const vertexShader = compileShader(gl, gl.VERTEX_SHADER, LUT_VERTEX_SHADER);
93
+ const fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, LUT_FRAGMENT_SHADER);
94
+ const program = gl.createProgram();
95
+ if (!program) {
96
+ throw new Error("Failed to create LUT shader program");
97
+ }
98
+ gl.attachShader(program, vertexShader);
99
+ gl.attachShader(program, fragmentShader);
100
+ gl.linkProgram(program);
101
+ gl.deleteShader(vertexShader);
102
+ gl.deleteShader(fragmentShader);
103
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
104
+ const log = gl.getProgramInfoLog(program);
105
+ gl.deleteProgram(program);
106
+ throw new Error(`LUT shader link failed: ${log ?? "(no log)"}`);
107
+ }
108
+ return program;
109
+ };
110
+ var createSourceTexture = (gl) => {
111
+ const texture = gl.createTexture();
112
+ if (!texture) {
113
+ throw new Error("Failed to create LUT source texture");
114
+ }
115
+ gl.bindTexture(gl.TEXTURE_2D, texture);
116
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
117
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
118
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
119
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
120
+ gl.bindTexture(gl.TEXTURE_2D, null);
121
+ return texture;
122
+ };
123
+ var createLutTexture = (gl) => {
124
+ const texture = gl.createTexture();
125
+ if (!texture) {
126
+ throw new Error("Failed to create LUT texture");
127
+ }
128
+ gl.bindTexture(gl.TEXTURE_3D, texture);
129
+ gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
130
+ gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
131
+ gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
132
+ gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
133
+ gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_WRAP_R, gl.CLAMP_TO_EDGE);
134
+ gl.bindTexture(gl.TEXTURE_3D, null);
135
+ return texture;
136
+ };
137
+ var setupLut = (target) => {
138
+ const gl = target.getContext("webgl2", {
139
+ premultipliedAlpha: true,
140
+ alpha: true,
141
+ preserveDrawingBuffer: true
142
+ });
143
+ if (!gl) {
144
+ throw createWebGL2ContextError("LUT effect");
145
+ }
146
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
147
+ const program = createProgram(gl);
148
+ const vao = gl.createVertexArray();
149
+ if (!vao) {
150
+ throw new Error("Failed to create LUT vertex array");
151
+ }
152
+ const vbo = gl.createBuffer();
153
+ if (!vbo) {
154
+ throw new Error("Failed to create LUT vertex buffer");
155
+ }
156
+ gl.bindVertexArray(vao);
157
+ gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
158
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 0, 0, 1, -1, 1, 0, -1, 1, 0, 1, 1, 1, 1, 1]), gl.STATIC_DRAW);
159
+ gl.enableVertexAttribArray(0);
160
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 16, 0);
161
+ gl.enableVertexAttribArray(1);
162
+ gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 16, 8);
163
+ gl.bindVertexArray(null);
164
+ return {
165
+ gl,
166
+ program,
167
+ vao,
168
+ vbo,
169
+ sourceTexture: createSourceTexture(gl),
170
+ lutTexture: createLutTexture(gl),
171
+ uniforms: {
172
+ uSource: gl.getUniformLocation(program, "uSource"),
173
+ uLut: gl.getUniformLocation(program, "uLut"),
174
+ uLutSize: gl.getUniformLocation(program, "uLutSize"),
175
+ uDomainMin: gl.getUniformLocation(program, "uDomainMin"),
176
+ uDomainMax: gl.getUniformLocation(program, "uDomainMax")
177
+ },
178
+ cachedContent: null
179
+ };
180
+ };
181
+ var applyLut = ({
182
+ state,
183
+ source,
184
+ width,
185
+ height,
186
+ content,
187
+ parsed,
188
+ flipSourceY
189
+ }) => {
190
+ const { gl, program, sourceTexture, lutTexture, uniforms, vao } = state;
191
+ if (state.cachedContent !== content) {
192
+ const maxSize = gl.getParameter(gl.MAX_3D_TEXTURE_SIZE);
193
+ if (parsed.size > maxSize) {
194
+ throw new Error(`LUT_3D_SIZE ${parsed.size} exceeds this browser's maximum 3D texture size of ${maxSize}`);
195
+ }
196
+ gl.activeTexture(gl.TEXTURE1);
197
+ gl.bindTexture(gl.TEXTURE_3D, lutTexture);
198
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
199
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
200
+ gl.texImage3D(gl.TEXTURE_3D, 0, gl.RGBA16F, parsed.size, parsed.size, parsed.size, 0, gl.RGBA, gl.FLOAT, parsed.data);
201
+ const uploadError = gl.getError();
202
+ if (uploadError !== gl.NO_ERROR) {
203
+ throw new Error(`Failed to upload the 3D LUT texture (WebGL error ${uploadError})`);
204
+ }
205
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
206
+ state.cachedContent = content;
207
+ }
208
+ gl.viewport(0, 0, width, height);
209
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
210
+ gl.clearColor(0, 0, 0, 0);
211
+ gl.clear(gl.COLOR_BUFFER_BIT);
212
+ gl.activeTexture(gl.TEXTURE0);
213
+ gl.bindTexture(gl.TEXTURE_2D, sourceTexture);
214
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
215
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
216
+ gl.activeTexture(gl.TEXTURE1);
217
+ gl.bindTexture(gl.TEXTURE_3D, lutTexture);
218
+ gl.useProgram(program);
219
+ if (uniforms.uSource)
220
+ gl.uniform1i(uniforms.uSource, 0);
221
+ if (uniforms.uLut)
222
+ gl.uniform1i(uniforms.uLut, 1);
223
+ if (uniforms.uLutSize)
224
+ gl.uniform1i(uniforms.uLutSize, parsed.size);
225
+ if (uniforms.uDomainMin) {
226
+ gl.uniform3f(uniforms.uDomainMin, ...parsed.domainMin);
227
+ }
228
+ if (uniforms.uDomainMax) {
229
+ gl.uniform3f(uniforms.uDomainMax, ...parsed.domainMax);
230
+ }
231
+ gl.bindVertexArray(vao);
232
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
233
+ gl.bindVertexArray(null);
234
+ gl.bindTexture(gl.TEXTURE_3D, null);
235
+ gl.activeTexture(gl.TEXTURE0);
236
+ gl.bindTexture(gl.TEXTURE_2D, null);
237
+ gl.useProgram(null);
238
+ };
239
+ var cleanupLut = ({
240
+ gl,
241
+ program,
242
+ vao,
243
+ vbo,
244
+ sourceTexture,
245
+ lutTexture
246
+ }) => {
247
+ gl.deleteTexture(sourceTexture);
248
+ gl.deleteTexture(lutTexture);
249
+ gl.deleteBuffer(vbo);
250
+ gl.deleteProgram(program);
251
+ gl.deleteVertexArray(vao);
252
+ };
253
+
254
+ // src/lut/parse-cube-lut.ts
255
+ var stripComment = (line) => {
256
+ let insideQuotes = false;
257
+ for (let i = 0;i < line.length; i++) {
258
+ const character = line[i];
259
+ if (character === '"') {
260
+ insideQuotes = !insideQuotes;
261
+ } else if (character === "#" && !insideQuotes) {
262
+ return line.slice(0, i);
263
+ }
264
+ }
265
+ return line;
266
+ };
267
+ var parseTriplet = ({
268
+ values,
269
+ lineNumber,
270
+ label
271
+ }) => {
272
+ if (values.length !== 3) {
273
+ throw new TypeError(`Invalid LUT content on line ${lineNumber}: ${label} must contain exactly 3 numbers`);
274
+ }
275
+ const parsed = values.map((value) => Number(value));
276
+ if (parsed.some((value) => !Number.isFinite(value))) {
277
+ throw new TypeError(`Invalid LUT content on line ${lineNumber}: ${label} must contain only finite numbers`);
278
+ }
279
+ return [parsed[0], parsed[1], parsed[2]];
280
+ };
281
+ var HEADER_DIRECTIVES = new Set([
282
+ "TITLE",
283
+ "LUT_3D_SIZE",
284
+ "DOMAIN_MIN",
285
+ "DOMAIN_MAX"
286
+ ]);
287
+ var parseCubeLut = (content) => {
288
+ const lines = content.replace(/^\uFEFF/, "").split(/\r?\n/);
289
+ let size = null;
290
+ let domainMin = [0, 0, 0];
291
+ let domainMax = [1, 1, 1];
292
+ let hasDomainMin = false;
293
+ let hasDomainMax = false;
294
+ let hasTitle = false;
295
+ let dataRows = 0;
296
+ let dataStarted = false;
297
+ for (let index = 0;index < lines.length; index++) {
298
+ const lineNumber = index + 1;
299
+ const line = stripComment(lines[index]).trim();
300
+ if (line.length === 0) {
301
+ continue;
302
+ }
303
+ const [keyword, ...values] = line.split(/\s+/);
304
+ if (keyword === "LUT_1D_SIZE") {
305
+ throw new TypeError(`Invalid LUT content on line ${lineNumber}: 1D LUTs are not supported`);
306
+ }
307
+ if (HEADER_DIRECTIVES.has(keyword)) {
308
+ if (dataStarted) {
309
+ throw new TypeError(`Invalid LUT content on line ${lineNumber}: ${keyword} must appear before the color data`);
310
+ }
311
+ if (keyword === "TITLE") {
312
+ if (hasTitle) {
313
+ throw new TypeError(`Invalid LUT content on line ${lineNumber}: TITLE may only be declared once`);
314
+ }
315
+ hasTitle = true;
316
+ continue;
317
+ }
318
+ if (keyword === "LUT_3D_SIZE") {
319
+ if (size !== null) {
320
+ throw new TypeError(`Invalid LUT content on line ${lineNumber}: LUT_3D_SIZE may only be declared once`);
321
+ }
322
+ if (values.length !== 1) {
323
+ throw new TypeError(`Invalid LUT content on line ${lineNumber}: LUT_3D_SIZE must contain exactly one integer`);
324
+ }
325
+ const parsedSize = Number(values[0]);
326
+ if (!Number.isInteger(parsedSize) || parsedSize < 2 || parsedSize > 256) {
327
+ throw new TypeError(`Invalid LUT content on line ${lineNumber}: LUT_3D_SIZE must be an integer from 2 to 256`);
328
+ }
329
+ size = parsedSize;
330
+ continue;
331
+ }
332
+ if (keyword === "DOMAIN_MIN") {
333
+ if (hasDomainMin) {
334
+ throw new TypeError(`Invalid LUT content on line ${lineNumber}: DOMAIN_MIN may only be declared once`);
335
+ }
336
+ domainMin = parseTriplet({
337
+ values,
338
+ lineNumber,
339
+ label: "DOMAIN_MIN"
340
+ });
341
+ hasDomainMin = true;
342
+ continue;
343
+ }
344
+ if (hasDomainMax) {
345
+ throw new TypeError(`Invalid LUT content on line ${lineNumber}: DOMAIN_MAX may only be declared once`);
346
+ }
347
+ domainMax = parseTriplet({
348
+ values,
349
+ lineNumber,
350
+ label: "DOMAIN_MAX"
351
+ });
352
+ hasDomainMax = true;
353
+ continue;
354
+ }
355
+ if (/^[A-Z_]/i.test(keyword)) {
356
+ throw new TypeError(`Invalid LUT content on line ${lineNumber}: unsupported directive "${keyword}"`);
357
+ }
358
+ if (size === null) {
359
+ throw new TypeError(`Invalid LUT content on line ${lineNumber}: LUT_3D_SIZE must be declared before the color data`);
360
+ }
361
+ parseTriplet({
362
+ values: [keyword, ...values],
363
+ lineNumber,
364
+ label: "color row"
365
+ });
366
+ dataStarted = true;
367
+ dataRows++;
368
+ const maxDataRows = size ** 3;
369
+ if (dataRows > maxDataRows) {
370
+ throw new TypeError(`Invalid LUT content: expected ${maxDataRows} color rows for LUT_3D_SIZE ${size}, but got more`);
371
+ }
372
+ }
373
+ if (size === null) {
374
+ throw new TypeError("Invalid LUT content: LUT_3D_SIZE is missing");
375
+ }
376
+ for (let channel = 0;channel < 3; channel++) {
377
+ if (domainMin[channel] >= domainMax[channel]) {
378
+ throw new TypeError(`Invalid LUT content: DOMAIN_MIN must be smaller than DOMAIN_MAX for every channel`);
379
+ }
380
+ }
381
+ const expectedRows = size ** 3;
382
+ if (dataRows !== expectedRows) {
383
+ throw new TypeError(`Invalid LUT content: expected ${expectedRows} color rows for LUT_3D_SIZE ${size}, but got ${dataRows}`);
384
+ }
385
+ const data = new Float32Array(expectedRows * 4);
386
+ let dataIndex = 0;
387
+ for (let index = 0;index < lines.length; index++) {
388
+ const line = stripComment(lines[index]).trim();
389
+ if (line.length === 0) {
390
+ continue;
391
+ }
392
+ const [keyword, ...values] = line.split(/\s+/);
393
+ if (HEADER_DIRECTIVES.has(keyword)) {
394
+ continue;
395
+ }
396
+ const [red, green, blue] = parseTriplet({
397
+ values: [keyword, ...values],
398
+ lineNumber: index + 1,
399
+ label: "color row"
400
+ });
401
+ const offset = dataIndex * 4;
402
+ data[offset] = red;
403
+ data[offset + 1] = green;
404
+ data[offset + 2] = blue;
405
+ data[offset + 3] = 1;
406
+ dataIndex++;
407
+ }
408
+ return {
409
+ size,
410
+ domainMin,
411
+ domainMax,
412
+ data
413
+ };
414
+ };
415
+
416
+ // src/lut/index.ts
417
+ var { createEffect } = Internals2;
418
+ var DEFAULT_LUT_CONTENT = `TITLE "Identity"
419
+ LUT_3D_SIZE 2
420
+
421
+ 0 0 0
422
+ 1 0 0
423
+ 0 1 0
424
+ 1 1 0
425
+ 0 0 1
426
+ 1 0 1
427
+ 0 1 1
428
+ 1 1 1`;
429
+ var lutSchema = {
430
+ content: {
431
+ type: "text-content",
432
+ default: DEFAULT_LUT_CONTENT,
433
+ description: "Cube LUT content",
434
+ keyframable: false
435
+ }
436
+ };
437
+ var MAX_CACHED_LUTS = 4;
438
+ var parsedLuts = new Map;
439
+ var getCachedLut = (content) => {
440
+ const cached = parsedLuts.get(content);
441
+ if (cached) {
442
+ parsedLuts.delete(content);
443
+ parsedLuts.set(content, cached);
444
+ return cached;
445
+ }
446
+ let firstHash = 2166136261;
447
+ let secondHash = 5381;
448
+ for (let i = 0;i < content.length; i++) {
449
+ const character = content.charCodeAt(i);
450
+ firstHash ^= character;
451
+ firstHash = Math.imul(firstHash, 16777619);
452
+ secondHash = Math.imul(secondHash, 33) ^ character;
453
+ }
454
+ const created = {
455
+ parsed: parseCubeLut(content),
456
+ effectKey: `lut-${content.length}-${firstHash >>> 0}-${secondHash >>> 0}`
457
+ };
458
+ parsedLuts.set(content, created);
459
+ if (parsedLuts.size > MAX_CACHED_LUTS) {
460
+ const oldestContent = parsedLuts.keys().next().value;
461
+ if (oldestContent !== undefined) {
462
+ parsedLuts.delete(oldestContent);
463
+ }
464
+ }
465
+ return created;
466
+ };
467
+ var validateLutParams = (params) => {
468
+ if (params === null || typeof params !== "object") {
469
+ throw new TypeError(`LUT effect requires a parameters object, but got ${JSON.stringify(params)}`);
470
+ }
471
+ if (typeof params.content !== "string" || params.content.trim().length === 0) {
472
+ throw new TypeError(`"content" must be a non-empty string, but got ${JSON.stringify(params.content)}`);
473
+ }
474
+ getCachedLut(params.content);
475
+ };
476
+ var lut = createEffect({
477
+ type: "remotion/lut",
478
+ label: "lut()",
479
+ documentationLink: "https://www.remotion.dev/docs/effects/lut",
480
+ backend: "webgl2",
481
+ calculateKey: (params) => getCachedLut(params.content).effectKey,
482
+ setup: setupLut,
483
+ apply: ({ source, width, height, params, state, flipSourceY }) => {
484
+ applyLut({
485
+ state,
486
+ source,
487
+ width,
488
+ height,
489
+ content: params.content,
490
+ parsed: getCachedLut(params.content).parsed,
491
+ flipSourceY
492
+ });
493
+ },
494
+ cleanup: cleanupLut,
495
+ schema: lutSchema,
496
+ validateParams: validateLutParams
497
+ });
498
+ export {
499
+ lutSchema,
500
+ lut
501
+ };
@@ -0,0 +1,15 @@
1
+ export declare const lutSchema: {
2
+ readonly content: {
3
+ readonly type: "text-content";
4
+ readonly default: "TITLE \"Identity\"\nLUT_3D_SIZE 2\n\n0 0 0\n1 0 0\n0 1 0\n1 1 0\n0 0 1\n1 0 1\n0 1 1\n1 1 1";
5
+ readonly description: "Cube LUT content";
6
+ readonly keyframable: false;
7
+ };
8
+ };
9
+ export type LutParams = {
10
+ /** The inline contents of a 3D `.cube` LUT file. */
11
+ readonly content: string;
12
+ };
13
+ export declare const lut: (params: LutParams & {
14
+ readonly disabled?: boolean | undefined;
15
+ }) => import("remotion").EffectDescriptor<unknown>;
@@ -0,0 +1,28 @@
1
+ import type { ParsedCubeLut } from './parse-cube-lut.js';
2
+ export type LutState = {
3
+ readonly gl: WebGL2RenderingContext;
4
+ readonly program: WebGLProgram;
5
+ readonly vao: WebGLVertexArrayObject;
6
+ readonly vbo: WebGLBuffer;
7
+ readonly sourceTexture: WebGLTexture;
8
+ readonly lutTexture: WebGLTexture;
9
+ readonly uniforms: {
10
+ readonly uSource: WebGLUniformLocation | null;
11
+ readonly uLut: WebGLUniformLocation | null;
12
+ readonly uLutSize: WebGLUniformLocation | null;
13
+ readonly uDomainMin: WebGLUniformLocation | null;
14
+ readonly uDomainMax: WebGLUniformLocation | null;
15
+ };
16
+ cachedContent: string | null;
17
+ };
18
+ export declare const setupLut: (target: HTMLCanvasElement) => LutState;
19
+ export declare const applyLut: ({ state, source, width, height, content, parsed, flipSourceY, }: {
20
+ readonly state: LutState;
21
+ readonly source: CanvasImageSource;
22
+ readonly width: number;
23
+ readonly height: number;
24
+ readonly content: string;
25
+ readonly parsed: ParsedCubeLut;
26
+ readonly flipSourceY: boolean;
27
+ }) => void;
28
+ export declare const cleanupLut: ({ gl, program, vao, vbo, sourceTexture, lutTexture, }: LutState) => void;
@@ -0,0 +1,2 @@
1
+ export declare const LUT_VERTEX_SHADER = "#version 300 es\nlayout(location = 0) in vec2 aPos;\nlayout(location = 1) in vec2 aUv;\nout vec2 vUv;\n\nvoid main() {\n\tvUv = aUv;\n\tgl_Position = vec4(aPos, 0.0, 1.0);\n}\n";
2
+ export declare const LUT_FRAGMENT_SHADER = "#version 300 es\nprecision highp float;\nprecision highp sampler3D;\n\nin vec2 vUv;\nout vec4 fragColor;\n\nuniform sampler2D uSource;\nuniform sampler3D uLut;\nuniform int uLutSize;\nuniform vec3 uDomainMin;\nuniform vec3 uDomainMax;\n\nvec3 sampleLut(vec3 color) {\n\tvec3 normalizedColor = clamp(\n\t\t(color - uDomainMin) / (uDomainMax - uDomainMin),\n\t\tvec3(0.0),\n\t\tvec3(1.0)\n\t);\n\tvec3 position = normalizedColor * float(uLutSize - 1);\n\tivec3 lower = ivec3(floor(position));\n\tivec3 upper = min(lower + ivec3(1), ivec3(uLutSize - 1));\n\tvec3 fraction = fract(position);\n\n\tvec3 c000 = texelFetch(uLut, ivec3(lower.x, lower.y, lower.z), 0).rgb;\n\tvec3 c100 = texelFetch(uLut, ivec3(upper.x, lower.y, lower.z), 0).rgb;\n\tvec3 c010 = texelFetch(uLut, ivec3(lower.x, upper.y, lower.z), 0).rgb;\n\tvec3 c110 = texelFetch(uLut, ivec3(upper.x, upper.y, lower.z), 0).rgb;\n\tvec3 c001 = texelFetch(uLut, ivec3(lower.x, lower.y, upper.z), 0).rgb;\n\tvec3 c101 = texelFetch(uLut, ivec3(upper.x, lower.y, upper.z), 0).rgb;\n\tvec3 c011 = texelFetch(uLut, ivec3(lower.x, upper.y, upper.z), 0).rgb;\n\tvec3 c111 = texelFetch(uLut, ivec3(upper.x, upper.y, upper.z), 0).rgb;\n\n\tvec3 c00 = mix(c000, c100, fraction.x);\n\tvec3 c10 = mix(c010, c110, fraction.x);\n\tvec3 c01 = mix(c001, c101, fraction.x);\n\tvec3 c11 = mix(c011, c111, fraction.x);\n\tvec3 c0 = mix(c00, c10, fraction.y);\n\tvec3 c1 = mix(c01, c11, fraction.y);\n\treturn mix(c0, c1, fraction.z);\n}\n\nvoid main() {\n\tvec4 sourceColor = texture(uSource, vUv);\n\tfloat alpha = sourceColor.a;\n\n\tif (alpha <= 0.0) {\n\t\tfragColor = vec4(0.0);\n\t\treturn;\n\t}\n\n\tvec3 straightColor = sourceColor.rgb / alpha;\n\tvec3 transformedColor = sampleLut(straightColor);\n\tfragColor = vec4(transformedColor * alpha, alpha);\n}\n";
@@ -0,0 +1,7 @@
1
+ export type ParsedCubeLut = {
2
+ readonly size: number;
3
+ readonly domainMin: readonly [number, number, number];
4
+ readonly domainMax: readonly [number, number, number];
5
+ readonly data: Float32Array;
6
+ };
7
+ export declare const parseCubeLut: (content: string) => ParsedCubeLut;
package/dist/lut.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { lut, lutSchema, type LutParams } from './lut/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/effects",
3
- "version": "4.0.525",
3
+ "version": "4.0.527",
4
4
  "description": "Effects that can be applied to Remotion-based canvas components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "url": "https://github.com/remotion-dev/remotion/issues"
27
27
  },
28
28
  "dependencies": {
29
- "remotion": "4.0.525"
29
+ "remotion": "4.0.527"
30
30
  },
31
31
  "exports": {
32
32
  ".": {
@@ -204,6 +204,11 @@
204
204
  "module": "./dist/esm/levels.mjs",
205
205
  "import": "./dist/esm/levels.mjs"
206
206
  },
207
+ "./lut": {
208
+ "types": "./dist/lut.d.ts",
209
+ "module": "./dist/esm/lut.mjs",
210
+ "import": "./dist/esm/lut.mjs"
211
+ },
207
212
  "./light-leak": {
208
213
  "types": "./dist/light-leak.d.ts",
209
214
  "module": "./dist/esm/light-leak.mjs",
@@ -500,6 +505,9 @@
500
505
  "levels": [
501
506
  "dist/levels.d.ts"
502
507
  ],
508
+ "lut": [
509
+ "dist/lut.d.ts"
510
+ ],
503
511
  "light-leak": [
504
512
  "dist/light-leak.d.ts"
505
513
  ],
@@ -618,7 +626,7 @@
618
626
  },
619
627
  "homepage": "https://www.remotion.dev/docs/effects/api",
620
628
  "devDependencies": {
621
- "@remotion/eslint-config-internal": "4.0.525",
629
+ "@remotion/eslint-config-internal": "4.0.527",
622
630
  "@vitest/browser-playwright": "4.0.9",
623
631
  "eslint": "9.19.0",
624
632
  "vitest": "4.0.9",