PDA

View Full Version : Can shader read from target framebuffer?



kitfox
04-07-2012, 10:17 AM
I'm trying to use OpenGL and framebuffer/texturebuffer objects to composite some 2D mask images.

At the moment, I'm creating a new destination texture and binding it to a framebuffer so it will accumulate the final mask. Then I iterate through all my source textures and draw them one at a time on top of my destination texture. (I'm doing this by drawing a singe quad with a simple shader that just samples the source texture).

While this works well for simple alpha blending, I would like to be able to create more complex operations that use the current color of the destination pixel to calculate the color of the current fragment. For example, I would like to do something like:



vec4 src = texture2D(u_mySrcTex, v_samplingCoord);
vec4 dst = getCurrentColorAtOutputFragmentPosition();
vec4 finalColor = vec4(dst.rgb, max(src.a, dst.a));


I'd also like to be able to implement Porter-Duff compositing and things like that.

BionicBytes
04-07-2012, 12:35 PM
You could always just copy or blit the current framebuffer to another texture and use that copy as one of the source textures.

V-man
04-08-2012, 09:36 AM
http://www.opengl.org/wiki/Framebuffer_Objects#Feedback_Loops

kRogue
04-11-2012, 12:28 PM
There is GL_NV_texture_barrier (http://www.opengl.org/registry/specs/NV/texture_barrier.txt) which allows to a very limited extent to use a texture even if it is the texture to which one is rendering.