I want to:
<canvas>
tag.<canvas>
contents (case i render output) as a texture in the next render pass.I'm trying to make a compute shader and need to carry a value per pixel (fragment) on each render pass. A simple example would be incrementing the blue value of a pixel on each render call.
I.e.
pass 1: b=1
pass 2: b=2
pass 2: b=3
etc.
Is this kind of a shader loop even possible?
Is there a better way to keep a'carry' texture in video memory for multipass processing (where uniform values must change between passes, unlike standard in-shader multipass processing)?
WebGL enables web content to use an API based on OpenGL ES 2.0 to perform 2D and 3D rendering in an HTML canvas in browsers that support it without the use of plug-ins.
To create a WebGL rendering context on the canvas element, you should pass the string experimental-webgl, instead of 2d to the canvas. getContext() method. Some browsers support only 'webgl'.
WebGL is the version of OpenGL, which is a 3D engine. It helps its user to perform 3D manipulation in web browsers. Canvas is a part of HTML5, allows its users with dynamic, script rendered 2D shapes. It can be considered a low level that has the ability to update bitmap images and does not have a built-in scene graph.
We tell WebGL we want to affect unit 0. We then call bindTexture() which binds the texture to the TEXTURE_2D bind point of texture unit 0. We then tell the shader that for the uSampler use texture unit 0. Lastly, add texture as a parameter to the drawScene() function, both where it is defined and where it is called.
The short answer is you can't
You can't currently access the canvas as a texture. Some other solutions
Copy the canvas to a texture
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, gl.canvas);
Will copy the current contents of the canvas into a texture.
Render to your own texture by attaching it to a framebuffer.
In this case you'd render to a texture that is set as an attachment to a framebuffer and then render that texture to the canvas (assuming you want to see the result and not just do math). There's an example here and here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With