There are various possible ways to do this, depending on how the RGBA values really represent the properties of the materials.
Here is a possible algorithm. Start with the final pixel colors lightr=lightg=lightb=0 , lightleft=1 ;
For each r, g, b, the occurring pixel estimates:
lightr += lightleft*r*(1-a) lightg += lightleft*g*(1-a) lightb += lightleft*b*(1-a) lightleft *= 1-a;
(RGBA values are normalized between 0 and 1, and I assume that a = 1 means opacity, a = 0 means completely transparent)
If the first pixel encountered is blue with an opacity of 50%, then 50% of the available color will be blue, and the rest is unknown. If a red pixel with an opacity of 50% is next, then 25% of the remaining light will be red, so the pixel will be 50% blue, 25% red. If a green pixel with an opacity of 60% is next, then the pixel will be 50% blue, 25% red, 15% green, with 10% of the remaining light.
Physical materials corresponding to this function are light-emitting, but partially opaque materials: thus, a pixel in the middle of the stack can never darken the final color: it can only prevent the light behind it, increasing the final color (being black and completely opaque).
Chris johnson
source share