Shader Story

August 1, 2025 · View on GitHub

Common HLSL Functions: Lerp

lerp(a, b, t) returns the linear interpolation between values a and b, using t (0–1) as the blend factor. It's foundational in shaders for blending, animation, transitions, gradients, and cross-fading effects.

float3 result = lerp(colorA, colorB, blendFactor); // Linear interpolation


Visual demo

This shader demonstrates a color blend using lerp() across the horizontal UV (x) axis.

Shader Story: Function - Lerp


URP Shader Code

Shader "DecompiledArt/CommonFunctions/Lerp/Lerp"
{
    Properties
    {
        _Tint_01("Tint_01", Color) = (1.0, 0.0, 0.0, 1.0)
        _Tint_02("Tint_02", Color) = (0.0, 0.0, 1.0, 1.0)
    }

    SubShader
    {
        Tags { "RenderType"="Opaque" "RenderPipeline" = "UniversalPipeline" }

        Pass
        {
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

            struct Attributes
            {
                float4 positionOS : POSITION;
                half2 uvs: TEXCOORD0;
            };

            struct Varyings
            {
                float4 positionHCS : SV_POSITION;
                half2 uvs: TEXCOORD0;
            };

            CBUFFER_START(UnityPerMaterial)
            half4 _Tint_01;
            half4 _Tint_02;
            CBUFFER_END

            Varyings vert (Attributes IN)
            {
                Varyings OUT;

                OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
                OUT.uvs = IN.uvs;
                return OUT;
            }

            half4 frag(Varyings IN) : SV_Target
            {
                return half4(lerp(_Tint_01.xyz, _Tint_02.xyz, IN.uvs.x), 1.0);
            }

            ENDHLSL
        }
    }
}


URP Shader graph

Shader Story: Function - Lerp


StepRemapSmoothstepExpAbs


❤️ Support Shader Story

If this article helped you, consider supporting the project on Patreon - you'll get access to the related source files, reference cheat-sheets, and other exclusive resources:

DecompiledArt on Patreon

Your support helps keep this library open, growing, and free for everyone.