Search Unity

Question Particle shader to blend "paint" on camera with "don't clear" flags

Discussion in 'Shaders' started by Megalon2D, Nov 23, 2020.

  1. Megalon2D

    Megalon2D

    Joined:
    Nov 29, 2015
    Posts:
    8
    Hello,
    I'm trying to create a simple spray-painting system in Unity using the particle system to "paint" particles onto a render texture. The camera's clear flags are set to "don't clear", so it gives the illusion of painting as each particle passes through the camera's clipping plane and is added to the render texture.

    Here is an example:
    upload_2020-11-23_4-47-37.png

    My problem is that the particles don't blend correctly.
    I am using the default particle texture, and I need to be able to tint it to any color, and every color needs to "paint" on top of any previous color.

    The closest I've gotten (as seen in the screenshot above) is by using the "Standard Unlit" particle shader, with the blending options set to:
    Rendering Mode: "Transparent"
    Color Mode: "Multiply"


    However, this doesn't render all colors correctly.
    #4600FF should be mostly blue, but it renders the center magenta, and the outer ring more blue.
    upload_2020-11-23_4-31-26.png

    These settings also seem to nullify the "Color of Lifetime" alpha settings, as they never appear to get any more transparent over time.

    The next best option I've found is
    Rendering Mode: "Fade"
    Color Mode: "Multiply"


    But this leaves a dark band around the sprayed spot when the particles.
    White ends up like this
    upload_2020-11-23_4-37-41.png

    I think I need to use a custom shader, but I'm not sure how to approach it!
    I have a little bit of shader writing experience, but I am no expert.

    I am forced to use Unity version 2018.4.20f1 (for the game VR Chat), which does not have ShaderGraph. (It is available as a "preview" package, but was buggy in my experience).
     

    Attached Files:

  2. Megalon2D

    Megalon2D

    Joined:
    Nov 29, 2015
    Posts:
    8
    I've come to realize that the default unity particle is not actually transparent, but white on a black background.
    Using an actual transparent texture, along with "Fade" and "Multiply" fixed most of my issues.
    I'm still seeing "banding" when a lot of low transparency sprites stack on top of each other, but it's good enough for now.