I'm using the fragment shader to render to a texture. I would like the rendering of the previous iteration of the shader to be used by the next one. How is that possible?
To re-use the texture in the fragment shader:
either
null framebuffer object or bind another framebuffer object) to which the texture is attached,or
null, attach another texture with framebufferTexture2D or attach a renderbuffer instead).and then bind the texture as a normal texture to be used in the fragment shader (via sampler2D and texture2D in the shader code).
To re-use the texture in the vertex shader, it is roughly the same, except that this feature (vertex textures) is non-standard (and has some limitations). Check MAX_VERTEX_TEXTURE_IMAGE_UNITS for support.
If you have an iterative algorithm that requires multiple rendering passes, one typical approach is to switch between two textures 1 and 2: during odd rendering passes, 1 is attached to the current framebuffer object and 2 is bound as a normal texture and during even rendering passes, it's the opposite. See also this answer on whether texture attachments should be changed in a single framebuffer object or whole framebuffer objects should instead be swapped.
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