Quiero manipular el lienzo con un sombreador, pero no sé cómo pasar el lienzo actual al sombreador. Supongo que uso sampler2D. ¿Por qué este código no invierte el lienzo? En cambio, es solo una pantalla blanca en blanco.
image(cnvs) funciona perfectamente bien.
guión.js
let cnvs; let shdr; function preload() { shdr = loadShader("shaders/shader.vert", "shaders/shader.frag"); } function setup() { cnvs = createCanvas(500, 500, WEBGL); } function draw() { fill(255, 0, 0); square(0, 0, width / 2); shdr.setUniform("u_resolution", [width, height]); shdr.setUniform("u_texture", cnvs); shader(shdr); fill(0); rect(0, 0, width, height); resetShader(); noLoop(); }shader.frag
#ifdef GL_ES precision mediump float; #endif uniform vec2 u_resolution; uniform sampler2D u_texture; void main() { vec2 st = gl_FragCoord.xy / u_resolution.xy; st.y = 1.0 - st.y; vec4 tex = texture2D(u_texture, st); gl_FragColor = tex; }shader.vert
#ifdef GL_ES precision mediump float; #endif attribute vec3 aPosition; void main() { vec4 positionVec4 = vec4(aPosition, 1.0); // Copy the position data into a vec4, adding 1.0 as the w parameter positionVec4.xy = positionVec4.xy * 2.0 - 1.0; // Scale to make the output fit the canvas. gl_Position = positionVec4; }