Sample Gradient Node | Shader Graph | 6.9.2
docs.unity3d.com
    Show / Hide Table of Contents

    Sample Gradient Node

    Description

    Samples a Gradient given the input of Time. Returns a Vector 4 color value for use in the shader.

    Ports

    Name Direction Type Binding Description
    Gradient Input Gradient None Gradient to sample
    Time Input Vector 1 None Point at which to sample gradient
    Out Output Vector 4 None Output value as Vector4

    Generated Code Example

    The following example code represents one possible outcome of this node.

    void Unity_SampleGradient_float(float4 Gradient, float Time, out float4 Out)
    {
        float3 color = Gradient.colors[0].rgb;
        [unroll]
        for (int c = 1; c < 8; c++)
        {
            float colorPos = saturate((Time - Gradient.colors[c-1].w) / (Gradient.colors[c].w - Gradient.colors[c-1].w)) * step(c, Gradient.colorsLength-1);
            color = lerp(color, Gradient.colors[c].rgb, lerp(colorPos, step(0.01, colorPos), Gradient.type));
        }
    #ifndef UNITY_COLORSPACE_GAMMA
        color = SRGBToLinear(color);
    #endif
        float alpha = Gradient.alphas[0].x;
        [unroll]
        for (int a = 1; a < 8; a++)
        {
            float alphaPos = saturate((Time - Gradient.alphas[a-1].y) / (Gradient.alphas[a].y - Gradient.alphas[a-1].y)) * step(a, Gradient.alphasLength-1);
            alpha = lerp(alpha, Gradient.alphas[a].x, lerp(alphaPos, step(0.01, alphaPos), Gradient.type));
        }
        Out = float4(color, alpha);
    }
    
    In This Article
    • Description
    • Ports
    • Generated Code Example
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023