Search Unity

Help Wanted Flickering fade shader

Discussion in 'Shader Graph' started by Crouching-Tuna, Aug 12, 2019.

  1. Crouching-Tuna


    Apr 4, 2014
    Hi all. This should be a general shader question but i'm using ShaderGraph in case it's related

    Basically i'm trying to recreate this:

    So i'll have particles spread, with infinite lifetime, as the "path". Not rendered.
    The trails that follows will use this shader. Using alpha clip to determine the final "length" of the trail from the base, with a 0-1 alpha "Color over Trail", so that all each particle needs to do is change its Start Color's alpha.

    trail flicker settings.png

    So far so good.

    But this is happening. Here the particle (and the following trail) is going upwards slowly and start color is full, not changing

    Reducing the StartColor alpha will shorten the trail, as expected, and the flickering is only "less intense".
    Notice also the flickering gets more intense the longer the trail is stretched
    flicker shader.png

    Here there's a lot of "Clamps", "Maximum" i added because i thought it's a division by zero issue. But it doesn't help

    In pseudocode it's something like this:
    Code (CSharp):
    1. float vertAlpha;
    2. float uv;
    4. float fadeValue = vertAlpha / uv.x;
    5. float fadeFlip = 1-fadeValue;
    6. float valueAtUv = uv.x - fadeFlip;
    7. float fraction = valueAtUv / fadeValue;
    8. float fadeOverTrailAfterClip = Lerp(0, 1, fraction);
    And the flickering happens around when UV.x is 0, vertAlpha is 0; So, around 0/0 in line 4

    Any help is appreciated,