Original Post
I have been striving to understand recently the way blending works, and tried to create a "good" system to use blending to create any effect imaginable easily.
My current system is made up of blending stages that work in the following way:
- Get alpha and color from one or two sources
- Set blending operations
- Render the result color and alpha to the destination pixel
Since the color is written to the destination pixel, the only thing I can do is create a (theoretically infinite) chain with the stages, each stage using the output of the previous stage as input, like this:
Chain
However, this is still limited, because I may need to do computations that cannot be solved as a chain of stages, for instance :
( Texture 1 + Texture 2 ) * ( Light 1 + Light 2 )
This all boils down to being able to set up a "tree" of stages, like this:
Tree
A few solutions come to my mind, but I don''t know how I could implement them.
1°/ Replace the tree computation by an equivalent chain computation, using inverse stages.
for instance, a * b + c * d = a * ( b + c * d / a )
The problem with this is actually determinating the inverse stage, for instance the "divide", inverse modulate, stage?
2°/ Rendering each stage in the tree to a texture instead of the screen, virtually turning each stage into a source.
The problem is I don''t know how to go about matching correctly the pixels during write and read.
Thank you for your help!
ToohrVyk