Search Unity

Custom splat map terrain with more then 4 textures

Discussion in 'Editor & General Support' started by Nieles, Sep 7, 2014.

  1. Nieles

    Nieles

    Joined:
    Dec 27, 2010
    Posts:
    50
    I'm currently working a planet generator and so far it's coming of pretty good:


    But I'm having trouble getting more then 4 textures on the planet.
    As a shader I use the splat map shader from the unity terrain: FirstPass.

    I know that the Unity terrain engine used the AddPass terrain shader to add more then 4 textures but I have no idea how to do the same on my custom planes.

    How do I add the second AddPAss shader to my material and then add that texture on top of the first layer?

    Or any other ideas to add more textures to my terrain are welcome! :)
     
  2. frogsbo

    frogsbo

    Joined:
    Jan 16, 2014
    Posts:
    79
    i wrote one with 6 textures controlled by height and z axis, you can try 8 with that addPass shader by doubling it, i dunno if it would exceed sampler2d limit.

    if you double the code that is in that shader, you can have 2 rgb values at the end from 8 textures, and figure out a different control map system. use 8 colors on the control map, for example. what does control map use at the moment?

    check if 8 textures work on that shader prior to anything, just add them on the the 4 to see if it runs past the limits. it isnt 16 sampler2d instances, its 16 sampler2d variables in the compiler for the whole shader.
     
  3. Nieles

    Nieles

    Joined:
    Dec 27, 2010
    Posts:
    50
    Currently it uses the r,g,b,a values.

    This was my first thought as well but this is not possible.
    My shader looked like this:
    Code (CSharp):
    1. Shader "Custom/Splatmap/Lightmap-FirstPass" {
    2. Properties {
    3.     _Control ("Control (RGBA)", 2D) = "red" {}
    4.     _Control2 ("Control 2 (RGBA)", 2D) = "red" {}
    5.     _Splat7 ("Layer 7 (A)", 2D) = "white" {}
    6.     _Splat6 ("Layer 6 (B)", 2D) = "white" {}
    7.     _Splat5 ("Layer 5 (G)", 2D) = "white" {}
    8.     _Splat4 ("Layer 4 (R)", 2D) = "white" {}
    9.     _Splat3 ("Layer 3 (A)", 2D) = "white" {}
    10.     _Splat2 ("Layer 2 (B)", 2D) = "white" {}
    11.     _Splat1 ("Layer 1 (G)", 2D) = "white" {}
    12.     _Splat0 ("Layer 0 (R)", 2D) = "white" {}
    13.     // used in fallback on old cards
    14.     _MainTex ("BaseMap (RGB)", 2D) = "white" {}
    15.     _Color ("Main Color", Color) = (1,1,1,1)
    16. }
    17.  
    18. SubShader {
    19.     Tags {
    20.         "SplatCount" = "8"
    21.         "Queue" = "Geometry-100"
    22.         "RenderType" = "Opaque"
    23.     }
    24.  
    25.     //first pass
    26. CGPROGRAM
    27. #pragma surface surf Lambert
    28. struct Input {
    29.     float2 uv_Control : TEXCOORD0;
    30.     float2 uv_Control2 : TEXCOORD1;
    31.     float2 uv_Splat0 : TEXCOORD2;
    32.     float2 uv_Splat1 : TEXCOORD3;
    33.     float2 uv_Splat2 : TEXCOORD4;
    34.     float2 uv_Splat3 : TEXCOORD5;
    35.     float2 uv_Splat4 : TEXCOORD6;
    36.     float2 uv_Splat5 : TEXCOORD7;
    37.     float2 uv_Splat6 : TEXCOORD8;
    38.     float2 uv_Splat7 : TEXCOORD9;
    39. };
    40.  
    41. sampler2D _Control, _Control2;
    42. sampler2D _Splat0,_Splat1,_Splat2,_Splat3,_Splat4,_Splat5,_Splat6,_Splat7;
    43.  
    44. void surf (Input IN, inout SurfaceOutput o) {
    45.     fixed4 splat_control = tex2D (_Control, IN.uv_Control);
    46.     fixed4 splat_control2 = tex2D (_Control2, IN.uv_Control2);
    47.     fixed3 col;
    48.     col  = splat_control.r * tex2D (_Splat0, IN.uv_Splat0).rgb;
    49.     col += splat_control.g * tex2D (_Splat1, IN.uv_Splat1).rgb;
    50.     col += splat_control.b * tex2D (_Splat2, IN.uv_Splat2).rgb;
    51.     col += splat_control.a * tex2D (_Splat3, IN.uv_Splat3).rgb;
    52.     col += splat_control2.r * tex2D (_Splat4, IN.uv_Splat4).rgb;
    53.     col += splat_control2.g * tex2D (_Splat5, IN.uv_Splat5).rgb;
    54.     col += splat_control2.b * tex2D (_Splat6, IN.uv_Splat6).rgb;
    55.     col += splat_control2.a * tex2D (_Splat7, IN.uv_Splat7).rgb;
    56.     o.Albedo = col;
    57.     o.Alpha = 0.0;
    58. }
    59. ENDCG
    60. }
    61.  
    62. // Fallback to Diffuse
    63. Fallback "Diffuse"
    64. }
    Unity is then giving me these errors:
    Shader error in 'Custom/Splatmap/Lightmap-FirstPass': Program 'SurfShaderInternalFunc', cannot locate suitable resource to bind parameter "Albedo" at line 60

    Shader error in 'Custom/Splatmap/Lightmap-FirstPass': Program 'SurfShaderInternalFunc', cannot locate suitable resource to bind parameter "Emission" at line 60

    Shader error in 'Custom/Splatmap/Lightmap-FirstPass': Program 'SurfShaderInternalFunc', cannot locate suitable resource to bind parameter "Normal" at line 60

    I believe that this is the reason that it has to be done in 2 passes, but I don't know how to call the second pass and how to set it's values in code. (Or how shaders work at all :) )
     
    IgorAherne likes this.