Splat map shader with more then 4 textues

I’m working on a procedural universe and it’s coming of pretty nice so far, here are some first planet tests:


But currently I’m hold back because I can’t get more then 4 textures on my planet.
Currently I use the Unity terrain FirstPass shader:

Shader "Custom/Splatmap/Lightmap-FirstPass" {
Properties {
    _Control ("Control (RGBA)", 2D) = "red" {}
    _Splat3 ("Layer 3 (A)", 2D) = "white" {}
    _Splat2 ("Layer 2 (B)", 2D) = "white" {}
    _Splat1 ("Layer 1 (G)", 2D) = "white" {}
    _Splat0 ("Layer 0 (R)", 2D) = "white" {}
    // used in fallback on old cards
    _MainTex ("BaseMap (RGB)", 2D) = "white" {}
    _Color ("Main Color", Color) = (1,1,1,1)
}
   
SubShader {
    Tags {
        "SplatCount" = "4"
        "Queue" = "Geometry-100"
        "RenderType" = "Opaque"
    }

CGPROGRAM
#pragma surface surf Lambert
struct Input {
    float2 uv_Control : TEXCOORD0;
    float2 uv_Splat0 : TEXCOORD1;
    float2 uv_Splat1 : TEXCOORD2;
    float2 uv_Splat2 : TEXCOORD3;
    float2 uv_Splat3 : TEXCOORD4;
};

sampler2D _Control;
sampler2D _Splat0,_Splat1,_Splat2,_Splat3;

void surf (Input IN, inout SurfaceOutput o) {
    fixed4 splat_control = tex2D (_Control, IN.uv_Control);
    fixed3 col;
    col  = splat_control.r * tex2D (_Splat0, IN.uv_Splat0).rgb;
    col += splat_control.g * tex2D (_Splat1, IN.uv_Splat1).rgb;
    col += splat_control.b * tex2D (_Splat2, IN.uv_Splat2).rgb;
    col += splat_control.a * tex2D (_Splat3, IN.uv_Splat3).rgb;
    o.Albedo = col;
    o.Alpha = 0.0;
}
ENDCG 
}

// Fallback to Diffuse
Fallback "Diffuse"
}

Now I know that Unity uses this second shader AddPass when the terrain uses more then 4 textures:

Shader "Custom/Splatmap/Lightmap-AddPass" {
Properties {
    _Control ("Control (RGBA)", 2D) = "black" {}
    _Splat3 ("Layer 3 (A)", 2D) = "white" {}
    _Splat2 ("Layer 2 (B)", 2D) = "white" {}
    _Splat1 ("Layer 1 (G)", 2D) = "white" {}
    _Splat0 ("Layer 0 (R)", 2D) = "white" {}
}
   
SubShader {
    Tags {
        "SplatCount" = "4"
        "Queue" = "Geometry-99"
        "IgnoreProjector"="True"
        "RenderType" = "Opaque"
    }
   
CGPROGRAM
#pragma surface surf Lambert decal:add
struct Input {
    float2 uv_Control : TEXCOORD0;
    float2 uv_Splat0 : TEXCOORD1;
    float2 uv_Splat1 : TEXCOORD2;
    float2 uv_Splat2 : TEXCOORD3;
    float2 uv_Splat3 : TEXCOORD4;
};

sampler2D _Control;
sampler2D _Splat0,_Splat1,_Splat2,_Splat3;

void surf (Input IN, inout SurfaceOutput o) {
    fixed4 splat_control = tex2D (_Control, IN.uv_Control);
    fixed3 col;
    col  = splat_control.r * tex2D (_Splat0, IN.uv_Splat0).rgb;
    col += splat_control.g * tex2D (_Splat1, IN.uv_Splat1).rgb;
    col += splat_control.b * tex2D (_Splat2, IN.uv_Splat2).rgb;
    col += splat_control.a * tex2D (_Splat3, IN.uv_Splat3).rgb;
    o.Albedo = col;
    o.Alpha = 0.0;
}
ENDCG 
}

Fallback off
}

But I need some help to get this to work on my planets, how do I get this AddPass to work?
Do I need to set it up from my script? And how do I do this?

I also tried adding more splat maps to the FirstPass shader but then I got out of resources.

Add more materials to Mesh Renderer materials.

ooh wauw! That easy…
Thanks man! I spend so many hours on this, didn’t know you could add more materials… :slight_smile:

Hi,

Nice Work Nieles!!!

I’m pretty interested how you UVMap the sphere to make no seams…

Can you explain me that?

Thanks!!!

In computer graphics, cube mapping is a method of environment mappingthat uses the six faces of a cube as the map shape. The environment is projected onto the sides of a cube and stored as six square textures, or unfolded into six regions of a single texture.

Hi!
I would like to know how to get that kind of shader to work with custom made meshes (like here). I have Unity 2019.4 and downloaded the built-in shaders already, there is a folder “TerrainShaders/Splats” - 12 files in it.
All take only a Basemap, maximum a Holemap. I guess not really suited?