Search Unity

Feedback Custom Function Nodes require workaround to output Gradients.

Discussion in 'Shader Graph' started by pixelante, Aug 29, 2019.

  1. pixelante

    pixelante

    Joined:
    Aug 22, 2013
    Posts:
    4
    [EDIT: Changed the workaround's return value to a more sensible default.]

    Custom Function Nodes do not support Gradient types as an out parameter (in both LWRP and URP).

    They will not compile due to a missing overload of the isfinite() method.

    Error log:
    Shader error in '[...]': 'isfinite': no matching 1 parameter intrinsic function; Possible intrinsic functions are: isfinite(float|half) at line 98 (on d3d11)

    Providing your own isfinite(Gradient) in the same script will make it work.

    I don't understand the implications of returning true or false, or how to write it to select between them. Either option works for me right now so I'm moving on.

    Here's an example HLSL script that will allow you to make a gradient node that takes two Colors as inputs, so you can use Material parameters to control them.

    Code (CSharp):
    1. void URP_GradientInputNode_float (float4 BeginColor, float4 EndColor, out Gradient Out)
    2. {
    3.     Out.type = 1;
    4.  
    5.     Out.colorsLength = 2;
    6.     Out.alphasLength = 2;
    7.  
    8.     Out.colors[0] = float4(BeginColor.r, BeginColor.g, BeginColor.b, 0.0f);
    9.     Out.colors[1] = float4(EndColor.r, EndColor.g, EndColor.b, 1.0f);
    10.  
    11.     Out.alphas[0] = float2(BeginColor.a, 0.0);
    12.     Out.alphas[1] = float2(EndColor.a, 1.0);
    13.  
    14.     Out.colors[2] = 0;
    15.     Out.colors[3] = 0;
    16.     Out.colors[4] = 0;
    17.     Out.colors[5] = 0;
    18.     Out.colors[6] = 0;
    19.     Out.colors[7] = 0;
    20.     Out.alphas[2] = 0;
    21.     Out.alphas[3] = 0;
    22.     Out.alphas[4] = 0;
    23.     Out.alphas[5] = 0;
    24.     Out.alphas[6] = 0;
    25.     Out.alphas[7] = 0;
    26. }
    27.  
    28. bool isfinite(Gradient g)
    29. {
    30.    return true;
    31. }
    (refer to https://docs.unity3d.com/Packages/com.unity.shadergraph@6.9/manual/Custom-Function-Node.html to understand how to set up this node in the graph view)
     
    Last edited: Aug 30, 2019
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    isfinite should probably return if the value is a finite number or not.
    This does not make much sense for a gradient but returning true Is probabel the " more" sensible return value.
    Its probably used internally to not use / special handel a value that is infinite.
     
    pixelante likes this.