Assume that the RT to render a pixel,rt background color is B, in order to write the color, first write A1, then write A2, then the final color
Art = (A1 blend (A2 blend B))
Expand
A2 Blend B = A2 * F2 + b * f2 '
A1 Blend (A2 blend B) = A1 * F1 + (A2 * F2 + b * f2 ') * F1 '
Get:
ART = A1 * f1 + (A2 * F2 + b * f2 ') * f1 ' = A1 * f1 + A2 * F2 * f1 ' + b * f2 ' * f1 '
Make
C = A1 * f1 + A2 * F2 * f1 '
T = F2 ' * f1 '
Get art= C + T * B
The question comes, if you take an RT rendering to Rawimage, deduce it according to the formula above, and get:
Bi = background color of UI
A = Art Blend Bt = art * frt + bt * frt ' = (C + T * B) * frt + BT * frt '
But in fact, what we really need is to replace the black background on the RT with the background of the UI, and then the UI, which is
A = C + T * Bi
So we're going to implement a = C + T * Bi, what to do.
The practice here is that C, T are stored on the RT, when RT gives image, and then retrieve c,t from RT, you can successfully calculate A = C + T * Bi.
So how can we store C and T?
For the storage of C, see above, render the scene to RT on the case:
C = A1 * f1 + A2 * F2 * f1 ' = A1 blend (A2 * F2) = A1 blend (A2 * F2 + b * f2 ') (When B = zero is set) =
A1 Blend (A2 blend b) (when B = Zero is established)
So, in fact, the normal rendering of the scene of things to RT, RT background Color RGB is black, RT of the RGB storage is C.
For the storage of T,
T = F2 ' * f1 '
Can be stored using RT's alpha, the Blend Op has no multiplication, so you can use Scralpha * Zero + dstalpha * dstblendfactor
And the alpha of the background color on the RT is 1.
Finally, the implementation is given:
Assuming that a particle system is to be rendered to the RT, the shader used by the particle system should:
Blendop Add, add
Blend Srcalpha Oneminussrcalpha, Zero Oneminussrcalpha
Colormask RGBA
Then RT to a rawimage, rawimage material with the shader should be like this:
Blend One Srcalpha