A new way of color blending

I was looking through the Fragment Program specs and began wondering. Is there a way to determine the color of a destination point? When using color blending, there is a source and destination, the source being the incoming color/fragment. I want to know if a fragment program can use that color, along with its alpha value and depth in calculations. The first and probably obvious reason for this is to make my own color blending routines.

Next, I have some ideas on transparency and refraction code I would like to try out, but I need to be able to know what the color “behind” an incoming fragment is. Any thoughts or suggestions? Thanks.

Do ping-pong rendering to two offscreen textures.

  1. When rendering to the 1st texture, bind the 2nd texture to read RGBA values at the current window position (WPOS) and combine them with your incoming fragment RGBA values.
  2. Then render to the 2nd texture and bind the first texture to read the accumulated RGBA values at the current WPOS.
  3. repeat

Ping-pong blending is required because you cannot read and write to a texture at the same time.

Hope that helps,

Using GL2 fragment programs, you can read the colour/depth/stencil values from the existing fragment in the framebuffer.