Search Unity

Resolved Replace Color Node - Docs

Discussion in 'Shader Graph' started by Jesus, Dec 8, 2020.

  1. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    504
    Hi

    Looking through the Replace Color Node on the wiki for it, to try and make my own improved version.
    https://docs.unity3d.com/Packages/com.unity.shadergraph@10.2/manual/Replace-Color-Node.html

    Can someone please explain where 'e' and 'f' are coming from?

    Code (CSharp):
    1. void Unity_ReplaceColor_float(float3 In, float3 From, float3 To, float Range, float Fuzziness, out float3 Out)
    2. {
    3.     float Distance = distance(From, In);
    4.     Out = lerp(To, In, saturate((Distance - Range) / max(Fuzziness, e-f)));
    5. }
    Am I just going mad? I can't open the compiled shaders (or can I? how) to look through them to see if they're set automagically for each shader all the time like some sort of constant.
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi,
    Hmm I'm not sure which Shader Graph version you are using, but the source code shows in the Shader Graph for me something like this (not identical to the documentation):

    Code (HLSL):
    1. Out = lerp(To, In, saturate((Distance - Range) / max(Fuzziness, 1e-5f)));
    Which does in this form look like E notation, 1 to the power of -5 (i.e. 0.00001)

    For code, did you try right click over a node, then "Show Generated Code"?
     
    Last edited: Dec 10, 2020
    Jesus likes this.
  3. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    504
    Cheers Olmi, that did the trick. I'd completely forgotten about the Show Generated Code option...

    Interesting that the docs don't have the numbers? e-f isn't exactly readable, and doesn't even give the exponent. 1e-5f is better, though why not just put 0.00001 in the first place I wonder?
     
  4. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Just a guess but maybe it's some automatically generated or a just badly copied code snippet. I don't know tbh.
     
    Last edited: Dec 11, 2020