Unity3d correctly renders the RT to the UI

Source: Internet
Author: User

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











Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.