Capítulo 646 de 988
Build a presentation that runs the entering and exiting scenes through a shader using the HTML-in-canvas APIs.
export type MyShaderProps = {
intensity?: number;
};
const VERTEX_SHADER = `#version 300 es
in vec2 a_pos;
out vec2 v_uv;
void main() {
v_uv = vec2(a_pos.x * 0.5 + 0.5, 0.5 - a_pos.y * 0.5);
gl_Position = vec4(a_pos, 0.0, 1.0);
}`;
const FRAGMENT_SHADER = `#version 300 es
precision highp float;
uniform sampler2D u_prev;
uniform sampler2D u_next;
uniform float u_time;
in vec2 v_uv;
out vec4 outColor;
void main() {
// u_time = 1 → fully prev, u_time = 0 → fully next
outColor = mix(
texture(u_next, v_uv),
texture(u_prev, v_uv),
u_time
);
}`;
export const myShader: HtmlInCanvasShader<MyShaderProps> = (canvas) => {
const gl = canvas.getContext('webgl2', {premultipliedAlpha: true});
if (!gl) {
throw new Error(
'WebGL2 unavailable. See https://remotion.dev/docs/troubleshooting/webgl2-context.',
);
}
// Compile + link program, create textures, bind a fullscreen quad...
// (see "Source references" below for a full implementation)
return {
clear: () => {
gl.clearColor(0, 0, 0, 0);
gl.clear(gl.COLOR_BUFFER_BIT);
},
cleanup: () => {
// Release WebGL resources here
},
draw: ({prevImage, nextImage, width, height, time, passedProps}) => {
// Upload prevImage / nextImage to textures via gl.texImage2D
// Set uniforms, draw the quad
},
};
};
export const myPresentation = makeHtmlInCan
// ...(truncated)