Home>

Details about what I want to ask here
I'm trying to project an effect (Particle System) shot with a camera using RenderTexture onto a RawImage under the Canvas, but the camera background (for example, black is specified in Solid Color in the camera settings) In this case, the effect will be reflected in the black background. If i set alpha to 0 here, nothing will be displayed this time, so I am in trouble.

* Apparently, Canvas is required to play Particle System.
If i try to force it with RenderTexture, it will not appear unless MeshRenderer is behind.
In conclusion, it was impossible.

If i am still able to do that, I would appreciate it.

■ Unity version
5.5.2 p1

Try it information:(language/FW/tool version etc.)
  • Answer # 1

    I tested with version 5.6.1f1, but I think there is a big difference in the questioner's version.

    Place the main camera, particle camera, particle system, two models in the background and the ground plane in the scene

    The camera for particles sets the clear flag to SolidColor, the background color to ARGB all 0, and the target texture to RenderTexture (named Particle Texture)

    Particle Texture color format is the default ARGB32, and the size is 256.

    Place RawImage in the center of the screen, refer to Particle Texture, and set the size to 512 pixels square

    Arrangement

    When you move it, as the questioner said, particles were drawn only on the opaque part of the texture.

    Failure drawing

    It seems that the default shader behavior of the particle system seems to be the cause, and since the alpha component is not rewritten at the time of particle drawing, the transparent part seems to be transparent as it is.

    Create a new shader, download the built-in shader in the download archive, replace the entire contents of the new shader with the contents of Particle Premultiply Blend.shader in DefaultResourcesExtra, change the shader name appropriately, ColorMask Change to RGBA and write to alpha channel.

    Shader "Particles/Alpha Blended Premultiply (RGBA)" {// Renamed to distinguish from built-in shaders
        Properties {
            _MainTex ("Particle Texture", 2D) = "white" {}
            _InvFade ("Soft Particles Factor", Range (0.01,3.0)) = 1.0
        }
        Category {
            Tags {"Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane"}
            Blend One OneMinusSrcAlpha
            ColorMask RGBA // This is changed from "RGB" to "RGBA"
            Cull Off Lighting Off ZWrite Off
            / * Omitted * /
        }
    }

    Create a new material, change the Shader to the previously created Particles/Alpha Blended Premultiply (RGBA), set the Particle Texture to the same Default-Particle as the default, and set this material to the Particle System Renderer Material .
    Now, when you enter play mode, it will be drawn in the transparent area, but black fringes will appear in the particles drawn in the transparent area.

    Failure drawing part 2

    This is a typical symptom that appears when an alpha-multiplied image is composited as if it were a straight alpha image (Is this site helpful?) This time, the material of RawImage is modified. is needed.

    In the same way, copy UI-Default.shader in DefaultResourcesExtra/UI to create a shader, and change Blend to prevent alpha channel multiplication.

    Shader "UI/Straight Alpha" // Again renamed
    {
        Properties
        {
            [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
            _Color ("Tint", Color) = (1,1,1,1)
            _StencilComp ("Stencil Comparison", Float) = 8
            _Stencil ("Stencil ID", Float) = 0
            _StencilOp ("Stencil Operation", Float) = 0_StencilWriteMask ("Stencil Write Mask", Float) = 255
            _StencilReadMask ("Stencil Read Mask", Float) = 255
            _ColorMask ("Color Mask", Float) = 15
            [Toggle (UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
        }
        SubShader
        {
            Tags
            {
                "Queue" = "Transparent"
                "IgnoreProjector" = "True"
                "RenderType" = "Transparent"
                "PreviewType" = "Plane"
                "CanUseSpriteAtlas" = "True"
            }
            Stencil
            {
                Ref [_Stencil]
                Comp [_StencilComp]
                Pass [_StencilOp]
                ReadMask [_StencilReadMask]
                WriteMask [_StencilWriteMask]
            }
            Cull Off
            Lighting Off
            ZWrite Off
            ZTest [unity_GUIZTestMode]
            Blend One OneMinusSrcAlpha // Change this from "Blend SrcAlpha OneMinusSrcAlpha" to "Blend One OneMinusSrcAlpha"
            ColorMask [_ColorMask]
            / * Omitted * /
        }
    }


    Set this shader on a new material, and set that material on the Raw Image (Script) Material of RawImage.
    The fringe disappeared when drawing with this.

    Decent drawing

    By placing the particle system on a single layer and rendering the camera to capture only that layer, only the particles could be rendered into the texture.

    Rendering only particles

    I wondered if it would work out if I changed the settings a little.
    To be honest, the questioner's solution seems simpler and better than this ...