Splat map gradient effect

Hey there,

I’m coming in relatively new to shaders have managed to piece together a simple triplaner shader from some examples, but need some assistance/advice on how to create a gradient effect from multiple different textures.

I have has some success when an image draws over another, but I’m a bit lost on how i would make this work in a gradient sense.

Here is how it works currently…

Heres the current code:

Shader "Custom/Terrain" {
    Properties {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Terrain Texture Array", 2DArray) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200
       
        CGPROGRAM
        #pragma surface surf Standard fullforwardshadows vertex:vert
        #pragma target 3.5
        #include "UnityCG.cginc"
        UNITY_DECLARE_TEX2DARRAY(_MainTex);

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;
        uniform sampler2D _Control;
        struct Input {
            float4 color : COLOR;
            float3 worldPos;
            float3 terrain;
            float3 worldNormal;
        };

        void vert (inout appdata_full v, out Input data) {
            UNITY_INITIALIZE_OUTPUT(Input, data);
            data.terrain = v.texcoord2.xyz;
        }

        float4 GetTerrainColor (Input IN, int index) {
            float mult = 1;
            float3 blend = abs(IN.worldNormal);
            blend /= dot(blend, 1.0);
            float3 ux = float3(IN.worldPos.zy * mult, IN.terrain[index]);
            float3 uy = float3(IN.worldPos.xz * mult, IN.terrain[index]);
            float3 uz = float3(IN.worldPos.xy * mult, IN.terrain[index]);
           
            fixed4 cx = UNITY_SAMPLE_TEX2DARRAY(_MainTex, ux);
            fixed4 cy = UNITY_SAMPLE_TEX2DARRAY(_MainTex, uy);
            fixed4 cz = UNITY_SAMPLE_TEX2DARRAY(_MainTex, uz);

            fixed4 blended = cx * blend.x + cy * blend.y + cz * blend.z;
            fixed3 c = IN.color[index] * blend;

            return blended * IN.color[index];
        }

        void surf (Input IN, inout SurfaceOutputStandard o) {
            fixed4 splat_control = tex2D(_Control, IN.worldPos);
             
            fixed4 c = splat_control * GetTerrainColor(IN, 0);
            c += splat_control * GetTerrainColor(IN, 1);
            c += splat_control.a * GetTerrainColor(IN, 2);

            o.Albedo = c.rgb * _Color;
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

The furthest i hope to extend this is to also include normal maps and specular maps for some context on where i am going on this, so if you see any red flags for this, an early warning would also be greatly appreciated.

But ultimately, for this question in particular. Does anyone have a suggestion on how i can get a more gradient effect between the textures?

Did you check out the Unity’s built in terrain shader source? It shows exactly how it does its blending.