How can I get WebGl to apply several programs successively, like
- draw something
- convert it to black and white
In this example, it's easy to put all that in a single shader, but I'd like to be able to keep things separated for reusability of larger shaders.
So far to do one pass I've something like
gl = canvas.getContext("webgl");
gl.viewport(0, 0, canvas.width, canvas.height);
fragmentShader = attachShader(fragmentShaderCode, gl, gl.FRAGMENT_SHADER);
vertexShader = attachShader(vertexShaderCode, gl, gl.VERTEX_SHADER);
program = gl.createProgram();
gl.attachShader(program, vertexShader);
gl.attachShader(program, fragmentShader);
gl.linkProgram(program);
gl.useProgram(program);
// attach textures and variables
gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0);
and I'm not sure how to add a second pass taking input from the first pass efficiently. My best guess atm is to use a second canvas that takes the first one as texture input. But that sounds like rendering twice and that's not awesome.