Search Unity

Maximum ps_4_0 sampler register index (16) exceeded? How to get around having too many textures?

Discussion in 'Shaders' started by markashburner, Apr 4, 2018.

  1. markashburner

    markashburner

    Joined:
    Aug 14, 2015
    Posts:
    212
    So apperantly this shader has exceeded the limit of sampler texts you are allowed to have which is 16.

    Unity is throwing me this error:

    maximum ps_4_0 sampler register index (16) exceeded at line 97 (on d3d11)

    Basically this shader has 6 albedo textures, 6 normal map textures and I want to add occlusion mapping as well and that's when I ran into this error:

    So what are my options, how do I get around this? DO I have to use two materials with two separate shaders?

    Here is the code:

    Code (CSharp):
    1. Shader "Custom/Planet" {
    2.     Properties {
    3.         _Tex1 ("Texture 0 (Beach)", 2D) = "white" {}
    4.         _AOTex1 ("Occlusion", 2D) = "white" {}
    5.         _Color1 ("Color 0", Color) = (1,1,1,1)
    6.         _Nor1 ("Normal 0", 2D) = "bump" {}
    7.         _NorPow1 ("Normal Power", Range(1,1.5)) = 1
    8.         _Glossiness1 ("Smoothness", Range(0,1)) = 0.5
    9.         _Metallic1 ("Metallic", Range(0,1)) = 0.0
    10.         _Brightness1("Brightness", Range(0,1)) = 0.0
    11.         _TexScale1 ("Texture Scale 0", Float) = 1
    12.  
    13.         _Tex2 ("Texture 1", 2D) = "white" {}
    14.         _AOTex2 ("Occlusion", 2D) = "white" {}
    15.         _Color2 ("Color 1", Color) = (1,1,1,1)
    16.         _Nor2 ("Normal 1", 2D) = "bump" {}
    17.         _NorPow2 ("Normal Power", Range(1,1.5)) = 1
    18.         _Glossiness2 ("Smoothness", Range(0,1)) = 0.5
    19.         _Metallic2 ("Metallic", Range(0,1)) = 0.0
    20.         _Brightness2("Brightness", Range(0,1)) = 0.0
    21.         _TexScale2 ("Texture Scale 1", Float) = 1
    22.  
    23.         _Tex3 ("Texture 2", 2D) = "white" {}
    24.         _AOTex3 ("Occlusion", 2D) = "white" {}
    25.         _Color3 ("Color 2", Color) = (1,1,1,1)
    26.         _Nor3 ("Normal 2", 2D) = "bump" {}
    27.         _NorPow3 ("Normal Power", Range(1,1.5)) = 1
    28.         _OccPower3 ("Occlusion Power", Range(0,4)) = 1
    29.         _Glossiness3 ("Smoothness", Range(0,1)) = 0.5
    30.         _Metallic3 ("Metallic", Range(0,1)) = 0.0
    31.         _Brightness3("Brightness", Range(0,1)) = 0.0
    32.         _TexScale3 ("Texture Scale 2", Float) = 1
    33.  
    34.         _Tex4 ("Texture 3", 2D) = "white" {}
    35.         _AOTex4 ("Occlusion", 2D) = "white" {}
    36.         _Color4 ("Color 3", Color) = (1,1,1,1)
    37.         _Nor4 ("Normal 3", 2D) = "bump" {}
    38.         _NorPow4 ("Normal Power", Range(1,1.5)) = 1
    39.         _Glossiness4 ("Smoothness", Range(0,1)) = 0.5
    40.         _Metallic4 ("Metallic", Range(0,1)) = 0.0
    41.         _Brightness4("Brightness", Range(0,1)) = 0.0
    42.         _TexScale4 ("Texture Scale 3", Float) = 1
    43.  
    44.         _Tex5 ("Texture 4", 2D) = "white" {}
    45.         _AOTex5 ("Occlusion", 2D) = "white" {}
    46.         _Color5 ("Color 4", Color) = (1,1,1,1)
    47.         _Nor5 ("Normal 4", 2D) = "bump" {}
    48.         _NorPow5 ("Normal Power", Range(1,1.5)) = 1
    49.         _Glossiness5 ("Smoothness", Range(0,1)) = 0.5
    50.         _Metallic5 ("Metallic", Range(0,1)) = 0.0
    51.         _Brightness5("Brightness", Range(0,1)) = 0.0
    52.         _TexScale5 ("Texture Scale 4", Float) = 1
    53.  
    54.         _Tex6 ("Texture 5", 2D) = "white" {}
    55.         _AOTex6 ("Occlusion", 2D) = "white" {}
    56.         _Color6 ("Color 5", Color) = (1,1,1,1)
    57.         _Nor6 ("Normal 5", 2D) = "bump" {}
    58.         _NorPow6 ("Normal Power", Range(1,1.5)) = 1
    59.         _Glossiness6 ("Smoothness", Range(0,1)) = 0.5
    60.         _Metallic6 ("Metallic", Range(0,1)) = 0.0
    61.         _Brightness6("Brightness", Range(0,1)) = 0.0
    62.         _TexScale6 ("Texture Scale 5", Float) = 1
    63.  
    64.      
    65.  
    66.     }
    67.     SubShader{
    68.  
    69.         Tags { "RenderType"="Opaque" }
    70.         LOD 200
    71.  
    72.         CGPROGRAM
    73.         // Physically based Standard lighting model, and enable shadows on all light types
    74.         #pragma surface surf Standard fullforwardshadows
    75.  
    76.         // Use shader model 3.0 target, to get nicer looking lighting
    77.         #pragma target 4.0
    78.  
    79.  
    80.         sampler2D _Tex1;
    81.         sampler2D _Tex2;
    82.         sampler2D _Tex3;
    83.         sampler2D _Tex4;
    84.         sampler2D _Tex5;
    85.         sampler2D _Tex6;
    86.  
    87.         sampler2D _AOTex1;
    88.         sampler2D _AOTex2;
    89.         sampler2D _AOTex3;
    90.         sampler2D _AOTex4;
    91.         sampler2D _AOTex5;
    92.         sampler2D _AOTex6;
    93.      
    94.  
    95.         sampler2D _Nor1;
    96.         sampler2D _Nor2;
    97.         sampler2D _Nor3;
    98.         sampler2D _Nor4;
    99.         sampler2D _Nor5;
    100.         sampler2D _Nor6;
    101.  
    102.      
    103.  
    104.         float _TexScale1;
    105.         float _TexScale2;
    106.         float _TexScale3;
    107.         float _TexScale4;
    108.         float _TexScale5;
    109.         float _TexScale6;
    110.      
    111.         float _Brightness1;
    112.         float _Brightness2;
    113.         float _Brightness3;
    114.         float _Brightness4;
    115.         float _Brightness5;
    116.         float _Brightness6;
    117.      
    118.      
    119.  
    120.         struct Input {
    121.             float2 uv_Tex1;
    122.             float2 uv4_Tex2;    
    123.             float4 color: Color;
    124.         };
    125.  
    126.         half _Glossiness1;
    127.         half _NorPow1;
    128.         half _Metallic1;
    129.         fixed4 _Color1;
    130.  
    131.         half _Glossiness2;
    132.         half _NorPow2;
    133.         half _Metallic2;
    134.         fixed4 _Color2;
    135.  
    136.         half _Glossiness3;
    137.         half _NorPow3;
    138.         half _OccPower3;
    139.         half _Metallic3;
    140.         fixed4 _Color3;
    141.  
    142.         half _Glossiness4;
    143.         half _NorPow4;
    144.         half _Metallic4;
    145.         fixed4 _Color4;
    146.  
    147.         half _Glossiness5;
    148.         half _NorPow5;
    149.         half _Metallic5;
    150.         fixed4 _Color5;
    151.  
    152.         half _Glossiness6;
    153.         half _NorPow6;
    154.         half _Metallic6;
    155.         fixed4 _Color6;
    156.  
    157.  
    158.  
    159.      
    160.  
    161.         // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
    162.         // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
    163.         // #pragma instancing_options assumeuniformscaling
    164.         UNITY_INSTANCING_BUFFER_START(Props)
    165.             // put more per-instance properties here
    166.         UNITY_INSTANCING_BUFFER_END(Props)
    167.  
    168.         void surf (Input IN, inout SurfaceOutputStandard o) {
    169.  
    170.             fixed4 c1 = tex2D (_Tex1, IN.uv_Tex1 * _TexScale1) * _Color1 * _Brightness1;
    171.             fixed4 c2 = tex2D (_Tex2, IN.uv_Tex1 * _TexScale2) * _Color2 * _Brightness2;
    172.             fixed4 c3 = tex2D (_Tex3, IN.uv_Tex1 * _TexScale3) * _Color3 * _Brightness3;
    173.             fixed4 c4 = tex2D (_Tex4, IN.uv_Tex1 * _TexScale4) * _Color4 * _Brightness4;
    174.             fixed4 c5 = tex2D (_Tex5, IN.uv_Tex1 * _TexScale5) * _Color5 * _Brightness5;
    175.             fixed4 c6 = tex2D (_Tex6, IN.uv_Tex1 * _TexScale6) * _Color6 * _Brightness6;
    176.          
    177.             fixed4 ao1 = tex2D (_AOTex1, IN.uv_Tex1 * _TexScale1);
    178.             fixed4 ao2 = tex2D (_AOTex2, IN.uv_Tex1 * _TexScale1);
    179.             fixed4 ao3 = tex2D (_AOTex3, IN.uv_Tex1 * _TexScale1);
    180.             fixed4 ao4 = tex2D (_AOTex4, IN.uv_Tex1 * _TexScale1);
    181.             fixed4 ao5 = tex2D (_AOTex5, IN.uv_Tex1 * _TexScale1);
    182.             fixed4 ao6 = tex2D (_AOTex6, IN.uv_Tex1 * _TexScale1);
    183.          
    184.          
    185.  
    186.             o.Alpha = ao3.a;
    187.             o.Occlusion = IN.color.r * ao1 + IN.color.g * ao2 + IN.color.b * ao3 + IN.color.a * ao4 + IN.uv4_Tex2.x * ao5 + IN.uv4_Tex2.y * ao6;
    188.          
    189.             //half slopeIntensity = 1 - (IN.color.r + IN.color.g + IN.color.b + IN.color.a + IN.uv4_Tex2.x + IN.uv4_Tex2.y);
    190.  
    191.             o.Albedo = IN.color.r * c1 + IN.color.g * c2 + IN.color.b * c3 + IN.color.a * c4 + IN.uv4_Tex2.x * c5 + IN.uv4_Tex2.y * c6;
    192.             o.Metallic = IN.color.r * _Metallic1 + IN.color.g * _Metallic2 + IN.color.b * _Metallic3 + IN.color.a * _Metallic4 + IN.uv4_Tex2.x * _Metallic5 + IN.uv4_Tex2.y * _Metallic6;
    193.             o.Smoothness = IN.color.r * _Glossiness1 + IN.color.g * _Glossiness2 + IN.color.b * _Glossiness3 + IN.color.a * _Glossiness4 + IN.uv4_Tex2.x * _Glossiness5 + IN.uv4_Tex2.y * _Glossiness6;
    194.          
    195.             o.Normal = UnpackNormal(tex2D(_Nor1, IN.uv_Tex1 * _TexScale1) * _NorPow1) * IN.color.r + UnpackNormal(tex2D(_Nor2, IN.uv_Tex1 * _TexScale2) * _NorPow2) * IN.color.g
    196.             + UnpackNormal(tex2D(_Nor3, IN.uv_Tex1 * _TexScale3) * _NorPow3) * IN.color.b + UnpackNormal(tex2D(_Nor4, IN.uv_Tex1 * _TexScale4) * _NorPow4) * IN.color.a
    197.             + UnpackNormal(tex2D(_Nor5, IN.uv_Tex1 * _TexScale5) * _NorPow5) * IN.uv4_Tex2.x + UnpackNormal(tex2D(_Nor6, IN.uv_Tex1 * _TexScale6) * _NorPow6) * IN.uv4_Tex2.y;
    198.         }
    199.         ENDCG
    200.         }
    201.      
    202.  
    203.     FallBack "Diffuse"
     
    Last edited: Apr 5, 2018
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    Since you're using target 4.0, you should be able to define textures separately from samplers, cutting down on your sampler usage. Unity has macros to make this easier (since different platforms do it differently and it will handle that for you).

    Use UNITY_DECLARE_TEX2D(_SomeTexture); to declare a texture and a sampler. And for all other textures that will share a sampler, define them as UNITY_DECLARE_TEX2D_NOSAMPLER(_SomeOtherTexture);
    Then you can sample them with UNITY_SAMPLE_TEX2D(_SomeTexture, someTextureUV); and UNITY_SAMPLE_TEX2D_SAMPLER(_SomeOtherTexture, _SomeTexture, someTextureUV);


    Code (CSharp):
    1. UNITY_DECLARE_TEX2D(_MainTex);
    2. UNITY_DECLARE_TEX2D_NOSAMPLER(_SomeOtherTex);
    3.  
    4. struct Input
    5. {
    6.     float2 uv_MainTex;
    7. }
    8.  
    9. void surf (Input IN, inout SurfaceOutputStandard o)
    10. {
    11.     float2 uvMain = IN.uv_MainTex;
    12.     float4 col = UNITY_SAMPLE_TEX2D(_MainTex, uvMain);
    13.     float4 someOtherCol = UNITY_SAMPLE_TEX2D_SAMPLER(_SomeOtherTex, _MainTex, uvMain);
    14. }
    UNITY_SAMPLE_TEX2D_SAMPLER is basically saying "Use the sampler from this other Texture Object".
     
    candycat likes this.
  3. markashburner

    markashburner

    Joined:
    Aug 14, 2015
    Posts:
    212
    Ahhhh Invertex!

    You came through for me again! I checked google everywhere and this issue barely comes up but thanks to your solution, no longer throwing me that error.
    Now I just got to work out how to implement the occlusion mapping. I would love to know why this works?

    I thought I had maxed out the textures a shader could possibly have...didn't think there would be a solution. But this works like a charm, does this mean I can have unlimited texture maps?

    For anyone else that runs into this error, you can read more about using sampler states here:
    https://docs.unity3d.com/Manual/SL-SamplerStates.html
     
  4. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    It's not that you run out of amount of textures you can use, it's that you ran out of the amount of "samplers" you can use. On older hardware/APIs, textures and samplers are bound, so your texture count was limited by the sampler limit. But in newer hardware (DX10 compatible and higher), samplers can be defined separately from textures, which is what that TEX2D_NOSAMPLER macro does for you behind the scenes on platforms that can.

    No, you cannot have unlimited textures though. There is still a limit, that varies depending on API, (OpenGL, Vulkan, Metal, D3D11, D3D12, etc..). On D3D11 for example, the max amount of Texture2D in an array is 2048. And the max amount of resource inputs you can have is 128.

    https://msdn.microsoft.com/en-us/library/windows/desktop/ff819065(v=vs.85).aspx
     
    H-Alex and zwcloud like this.
  5. Rensoburro_Taki

    Rensoburro_Taki

    Joined:
    Sep 2, 2011
    Posts:
    274
    Sorry to bother you guys, but I'm getting desperate. As an artist with almost no programming knowledge I am forced to ask you guys for help, with a shader that gives me the same error message. And I am not able to fix this by myself. My whole project is running on the latest stable version (2018.2.18f1 from 30th Nov), and the shader doesn't want to run there. :/

    What are samples? Calculations of certain properties, like blendings, additive and so on?
    Can I fix it myself, without programming skills? I mean even programmers fear shader language, as far as I have noticed.

    Please, someone help me. I thought to post the shader too! Maybe that gives more insight. idk.

    But I really appreciate every help I can get!

    Thanks in advance!


    Error message:
    Shader error in 'Nature/Terrain/TerrBlend': maximum ps_4_0 sampler register index (16) exceeded at line 108 (on d3d11)

    Compiling Fragment program with UNITY_PASS_FORWARDBASE DIRECTIONAL SHADOWS_SCREEN LIGHTPROBE_SH
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_FULL_HDR



    Shader:
    Code (CSharp):
    1. Shader "Nature/Terrain/TerrBlend" {
    2.  
    3. Properties {
    4.     _StoneAdd("StoneAdd", Range(-1, 0.20)) = 0
    5.     _DirtAdd("DirtAdd", Range(-5, 5)) = 0
    6.     _GrassAdd("GrassAdd", Range(0, 5)) = 0
    7.     _SnowAdd("SnowAdd", Range(0, 1)) = 0
    8.     _Color ("Main Color", Color) = (1,1,1,1)
    9.     _ColorGrass0 ("Grass0", Color) = (1,1,1,1)
    10.     _ColorGrass1 ("Grass1", Color) = (1,1,1,1)
    11.     _ColorGrass2 ("Grass2", Color) = (1,1,1,1)
    12.     _ColorGrass3 ("Grass3", Color) = (1,1,1,1)
    13.     _OldGrass("OldGrass", Range(3, 60)) = 14
    14.  
    15.     _ColorStones1 ("Stones1", Color) = (1,1,1,1)
    16.     _ColorStones2 ("Stones2", Color) = (1,1,1,1)
    17.     _ColorStones3 ("Stones2", Color) = (1,1,1,1)
    18.  
    19.     _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
    20.     _Shininess ("Shininess", Range (0.01, 0.2)) = 0.01
    21.    
    22.     [HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
    23.     _Mask1 ("Mask1 (RGBA)", 2D) = "red" {}
    24.     _2Splat2 ("Stones", 2D) = "black" {}
    25.     _3Splat2 ("Moss", 2D) = "black" {}
    26.     [HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "black" {}
    27.     [HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "black" {}
    28.     [HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "black" {}
    29.     [HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
    30.     [HideInInspector] _Normal3 ("Normal 3 (A)", 2D) = "bump" {}
    31.     [HideInInspector] _Normal2 ("Normal 2 (B)", 2D) = "bump" {}
    32.     [HideInInspector] _Normal1 ("Normal 1 (G)", 2D) = "bump" {}
    33.     [HideInInspector] _Normal0 ("Normal 0 (R)", 2D) = "bump" {}
    34.     [HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
    35.     [HideInInspector] _Color ("Main Color", Color) = (1,1,1,1)
    36.  
    37.     _SnowHeight ("SnowHeight", Range (-0.7, 0.19)) = 0
    38.    
    39.     _ColorTex ("ColorMap (RGB)", 2D) = "black" {}
    40.     _Normalmap ("Normalmap (RGB)", 2D) = "white" {}
    41.     _Tiling ("Tiling", Range (0.01, 80)) = 0.05
    42.    
    43.     _HeightSplatAll ("Grass(R) Cliff(G) Stones(B) Snow(a)", 2D) = "black" {}
    44.     _Parallax ("Height", Range (0.005, 0.08)) = 0.02
    45.    
    46.     _Cube ("Reflection Cubemap", Cube) = "" {}
    47.     _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
    48. }
    49.    
    50. SubShader {
    51.     Tags {
    52.         "Queue" = "Geometry-100"
    53.         "RenderType" = "Opaque"
    54.     }
    55.  
    56. CGPROGRAM
    57. #pragma surface surf BlinnPhong vertex:vert
    58. #pragma target 3.5
    59.  
    60. void vert (inout appdata_full v)
    61. {
    62.     v.tangent.xyz = cross(v.normal, float3(0,0,1));
    63.     v.tangent.w = -1;
    64. }
    65.  
    66. sampler2D _Mask1;
    67. sampler2D _Control;
    68. sampler2D _Normalmap;
    69. sampler2D _Splat0,_Splat1,_Splat2,_Splat3,_2Splat2, _3Splat2;
    70. sampler2D _Normal0,_Normal1,_Normal2,_Normal3;
    71.  
    72. float _Parallax;
    73.  
    74. struct Input {
    75.     float2 uv_Mask1 : TEXCOORD0;
    76.  
    77.     float2 uv_Splat0 : TEXCOORD1;
    78.     float2 uv_Splat1 : TEXCOORD2;
    79.     float2 uv_Splat2 : TEXCOORD3;
    80.     float2 uv_Splat3 : TEXCOORD4;
    81.     float3 worldPos;
    82.     float3 worldNormal;
    83.     float _Parallax;
    84.     float3 worldRefl;
    85.     float3 viewDir;
    86.  
    87.     INTERNAL_DATA
    88. };
    89.  
    90.  
    91.         fixed4 _Color;
    92.         fixed4 _ColorGrass1;
    93.         fixed4 _ColorGrass0;
    94.         fixed4 _ColorGrass2;
    95.         fixed4 _ColorGrass3;
    96.         fixed4 _ColorStones1;
    97.         fixed4 _ColorStones2;
    98.         fixed4 _ColorStones3;
    99.         half _OldGrass;
    100.         half _StoneAdd;
    101.         half _DirtAdd;
    102.         half _GrassAdd;
    103.         half _SnowAdd;
    104.         half _Shininess;
    105.         half _SnowHeight;
    106.         sampler2D _ColorTex;
    107.         half _Tiling;
    108.         sampler2D _HeightSplatAll;
    109.         samplerCUBE _Cube;
    110.  
    111. void surf (Input IN, inout SurfaceOutput o) {
    112.  
    113.     o.Normal = float3(0, 0, 1);
    114.     float3 n = WorldNormalVector(IN, o.Normal);
    115.     float3 projNormal = saturate(pow(n * 1.4, 30));
    116.     float2 invertY = float2(1, -1);
    117.  
    118.             half4 h = tex2D (_HeightSplatAll, IN.uv_Splat3).a;
    119.             float2 offset = ParallaxOffset (h, _Parallax, IN.viewDir);
    120.             IN.uv_Splat3 += offset*5;
    121.  
    122.            
    123.             half4 hgrass = tex2D(_HeightSplatAll, IN.uv_Splat0).r;
    124.             float2 offset1 = ParallaxOffset(hgrass, _Parallax, IN.viewDir);
    125.             IN.uv_Splat0 += offset1 * 2;
    126.  
    127.             half4 h2 = tex2D (_HeightSplatAll, IN.uv_Splat1).g;
    128.             float2 offset2 = ParallaxOffset (h2, _Parallax, IN.viewDir);
    129.             IN.uv_Splat1 += offset2*5;
    130.            
    131.             half4 h3 = tex2D (_HeightSplatAll, IN.uv_Splat2).b;
    132.             float2 offset3 = ParallaxOffset (h3, _Parallax, IN.viewDir);
    133.             IN.uv_Splat2 += offset3*2;
    134.  
    135.             half4 ColorTex = tex2D (_ColorTex, IN.uv_Mask1);
    136.             half4 MaskTex = tex2D (_Mask1, IN.uv_Mask1);
    137.             half4 ControlTex = tex2D (_Control, IN.uv_Mask1);
    138.             half4 Normalmap = tex2D (_Normalmap, IN.uv_Mask1);
    139.  
    140.             //-------------------------------------------------------
    141.             // SIDE X
    142.             float4 x = tex2D(_Splat1, frac(IN.worldPos.zy / _Tiling));
    143.             float4 x_n = tex2D(_Normal1, frac(IN.worldPos.zy / _Tiling));
    144.             // TOP / BOTTOM
    145.             float4 y = tex2D(_Splat1, frac(IN.worldPos.zx / _Tiling));
    146.             float4 y_n = tex2D(_Normal1, frac(IN.worldPos.zx / _Tiling));
    147.             // SIDE Z  
    148.             float4 z = tex2D(_Splat1, frac(IN.worldPos.xy / _Tiling));
    149.             float4 z_n = tex2D(_Normal1, frac(IN.worldPos.xy / _Tiling));
    150.             //-------------------------------------------------------
    151.  
    152.             half4 Detail0 = tex2D (_Splat0, IN.uv_Splat0);
    153.             half4 Detail1 = tex2D (_Splat1, IN.worldPos.zy / _Tiling);
    154.             half4 Detail2 = tex2D (_Splat2, IN.uv_Splat2);
    155.             half4 Detail2_2 = tex2D (_2Splat2, IN.uv_Splat2);
    156.             half4 Detail2_3 = tex2D (_3Splat2, IN.uv_Splat2);
    157.             half4 Detail3 = tex2D (_Splat3, IN.uv_Splat3);
    158.  
    159.             //Grass -----------------------------------------------
    160.             float4 textureGrass0 = tex2D (_Splat0, IN.uv_Splat0) * _ColorGrass0;
    161.             float4 textureGrass1 = tex2D (_Splat0, IN.uv_Splat0) * _ColorGrass1 * ColorTex;
    162.             float4 textureGrass2 = tex2D (_Splat0, IN.uv_Splat0) * _ColorGrass2 * ColorTex;
    163.             float4 textureGrass3 = tex2D (_Splat0, IN.uv_Splat0) * _ColorGrass3 * ColorTex;
    164.             //Stones ----------------------------------------------
    165.             float4 textureStones1 = tex2D (_Splat2, IN.uv_Splat2) * _ColorStones1;
    166.             float4 textureStones2 = tex2D (_Splat2, IN.uv_Splat2) * _ColorStones2;
    167.             float4 textureStones3 = tex2D (_Splat3, IN.uv_Splat2) * _ColorStones3;
    168.             float4 textureStones4 = tex2D (_2Splat2, IN.uv_Splat2);
    169.             float4 textureStones5 = tex2D (_3Splat2, IN.uv_Splat2) * ColorTex;
    170.             float4 textureStones5_mask = tex2D(_3Splat2, IN.uv_Mask1);
    171.  
    172.             float a00 = MaskTex.r * (Detail0.a);
    173.             float a0 = MaskTex.r;
    174.             float a1 = MaskTex.g + ControlTex.g;
    175.             float a2 = MaskTex.b+ _StoneAdd + ControlTex.b*2 - MaskTex.g - MaskTex.r/2;
    176.             float a3 = MaskTex.a -_SnowAdd + ControlTex.a;
    177.             float a4 = a2+0.25-MaskTex.r*5-MaskTex.g;
    178.             float a5 = textureStones5_mask.a*MaskTex.r*4- MaskTex.a- MaskTex.b;
    179.  
    180.             half4 HeightSplatTex1 = tex2D (_HeightSplatAll, IN.uv_Splat0).r*1.4;
    181.             half4 HeightSplatTex2 = tex2D (_HeightSplatAll, IN.uv_Splat1).g;
    182.             half4 HeightSplatTex3 = tex2D (_HeightSplatAll, IN.uv_Splat2).b*1.2 +(1.14/20)*5;
    183.             half4 HeightSplatTex4 = tex2D (_HeightSplatAll, IN.uv_Splat3 - offset).a + _SnowHeight +(1.14/20)*1.4;
    184.  
    185.             half4 HeightSplatGrass0 = tex2D (_HeightSplatAll, IN.uv_Splat0).r * MaskTex.b;
    186.             half4 HeightSplatGrass1 = tex2D (_HeightSplatAll, IN.uv_Splat0).r*2 * (Detail0.a)* _ColorGrass1.a;
    187.             half4 HeightSplatGrass2 = tex2D (_HeightSplatAll, IN.uv_Splat1).r + 0.72;
    188.             half4 HeightSplatGrass3 = tex2D (_HeightSplatAll, IN.uv_Splat1).r + 0.72;
    189.  
    190.             half4 HeightSplatStones1 = tex2D (_HeightSplatAll, IN.uv_Splat1).b;
    191.             half4 HeightSplatStones2 = tex2D (_HeightSplatAll, IN.uv_Splat2).b;
    192.             half4 HeightSplatStones3 = tex2D (_HeightSplatAll, IN.uv_Splat3).b;
    193.  
    194.             float mgrass = (max(max(max(HeightSplatGrass0.rgb + a00*_OldGrass*(1.14*0.5), HeightSplatGrass1.rgb + a0), HeightSplatGrass2.rgb + a1*8), HeightSplatGrass3.rgb + a2*5)) - 0.05;
    195.  
    196.             float mStones = (max(max(HeightSplatStones1.rgb + a1, HeightSplatStones2.rgb + a2), HeightSplatStones3.rgb + a3)) - 0.05;
    197.  
    198.             float g00 = max(HeightSplatGrass0.rgb + a00*_OldGrass*(1.14*0.5) - mgrass, 0) * ColorTex.a;
    199.             float g0 = max(HeightSplatGrass1.rgb + a0 - mgrass, 0);
    200.             float g1 = max(HeightSplatGrass2.rgb + a1*8 - mgrass, 0) + ControlTex.g;
    201.             float g2 = max(HeightSplatGrass2.rgb + a2*5 - mgrass, 0) + MaskTex.a/1.2;
    202.  
    203.  
    204.             float s0 = max(HeightSplatStones1.rgb + a1 - mStones, 0);
    205.             float s1 = max(HeightSplatStones2.rgb + a2 - mStones, 0);
    206.             float s2 = max(HeightSplatStones3.rgb + a3 - mStones, 0);
    207.             float s3 = max(HeightSplatStones3.rgb + a4  - mStones, 0);
    208.  
    209.             float4 Grass0Tex = textureGrass0;
    210.             float4 Grass1Tex = textureGrass1;
    211.             float4 Grass2Tex = textureGrass2;
    212.             float4 Grass3Tex = textureGrass3;
    213.  
    214.             float4 Stones1Tex = textureStones1;
    215.             float4 Stones2Tex = textureStones2;
    216.             float4 Stones3Tex = textureStones3;
    217.             float4 Stones4Tex = textureStones4;
    218.             float4 Stones5Tex = textureStones5;
    219.  
    220.             fixed4 texGrass = (Grass0Tex * g00 +  Grass1Tex * g0 + Grass2Tex * g1 + Grass3Tex * g2) / (g00 + g0 + g1 + g2);
    221.  
    222.             fixed4 texStones = (Stones1Tex * s0 + Stones2Tex * s1 + Stones3Tex * s2 + Stones4Tex * s3) / (s0 + s1 + s2 + s3);
    223.            
    224.             float ma = (max(max(max(HeightSplatTex1.rgb + a0, HeightSplatTex2.rgb + a1), HeightSplatTex3.rgb + a2), HeightSplatTex4.rgb + a3)) - 0.05;
    225.  
    226.             float b0 = max(HeightSplatTex1.rgb + a0 - ma, 0)+ _GrassAdd;
    227.             float b1 = max(HeightSplatTex2.rgb + a1 - ma, 0)*50;
    228.             float b2 = max(HeightSplatTex3.rgb + a2 - ma, 0)*4;
    229.             float b3 = max(HeightSplatTex4.rgb + a3 - ma, 0)*20;
    230.             float b4 = max(HeightSplatTex4.rgb + ColorTex.a/5 +g0+ g1- g2*50 + _DirtAdd/30 - ma, 0)*50;
    231.             float b5 = max(HeightSplatTex4.rgb + a5+(g2*3.5*a0) - ma, 0);
    232.             float b6 = max(HeightSplatTex4.rgb + (g2*2*a0) - ma, 0);
    233.            
    234.             float4 texture0 = texGrass;
    235.             float4 texture1 = Detail1;
    236.             float4 texture2 = texStones;
    237.             float4 texture3 = Detail3;
    238.             float4 texture4 = textureStones4;
    239.             float4 texture5 = textureStones5;
    240.  
    241.             fixed4 tex = (texture0 * b0 + texture1 * b1*5 + texture2 * b2 + texture3 * b3 + texture4 * b4 + texture5 * b5 + texture2 * b6) / (b0 + b1*5 + b2 + b3 + b4 + b5 + b6);
    242.  
    243.             tex = tex;
    244.  
    245.             texture0 = tex2D (_Normal0, IN.uv_Splat0);
    246.             texture1 = tex2D (_Normal1, IN.worldPos.zy / _Tiling);
    247.             texture2 = tex2D (_Normal2, IN.uv_Splat2);
    248.             texture3 = tex2D (_Normal3, IN.uv_Splat3);
    249.             float4 mixnormal = (texture0 * b0 + texture1 * b1 + texture2 * b2 + texture3 * b3 + texture2 * b4 + texture2 * b5) / (b0 + b1 + b2 + b3 + b4 + b5);
    250.  
    251.             o.Normal = normalize(UnpackNormal(mixnormal)*1.5);
    252.  
    253.             o.Albedo = z.rgb;
    254.             o.Albedo = lerp(o.Albedo, x.rgb, projNormal.x);
    255.             o.Albedo = lerp(o.Albedo, y.rgb, projNormal.y);
    256.             o.Albedo = lerp(tex.rgb, o.Albedo, a1)*_Color;
    257.  
    258.             o.Gloss = 0.1 * MaskTex.a- MaskTex.r + ControlTex.a;
    259.             o.Alpha = _Color.a;
    260.             o.Specular = _Shininess;
    261.            
    262.     float3 worldRefl = WorldReflectionVector (IN, UnpackNormal(mixnormal));
    263.     fixed4 reflcol_dirt = texCUBE (_Cube, worldRefl)*10;
    264.     reflcol_dirt *= ColorTex.a;
    265.  
    266.     reflcol_dirt *= b2;
    267.     reflcol_dirt *= b1;
    268.  
    269.     reflcol_dirt *= tex2D(_ColorTex, IN.uv_Mask1);
    270.     reflcol_dirt *= tex2D(_Mask1, IN.uv_Mask1).a;
    271.     reflcol_dirt += tex2D(_Mask1, IN.uv_Mask1).b;
    272.    
    273.     fixed4 reflcol_snow = texCUBE (_Cube, worldRefl)*20;
    274.     reflcol_snow *= (tex2D(_Splat3, IN.uv_Splat3/1.5).a * tex2D(_Splat3, IN.uv_Splat3/2 + _Time/800).a);
    275.     reflcol_snow *= b3;
    276.     o.Emission = reflcol_dirt.rgb + (reflcol_snow.rgb);
    277. }
    278. ENDCG
    279.  
    280. }
    281.  
    282. //Dependency "AddPassShader" = "Hidden/Nature/Terrain/TerrSuperBlendSpec AddPass"
    283. Dependency "BaseMapShader" = "Specular"
    284.  
    285. Fallback "Nature/Terrain/Diffuse"
    286. }
     
  6. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
  7. Rensoburro_Taki

    Rensoburro_Taki

    Joined:
    Sep 2, 2011
    Posts:
    274
  8. Rensoburro_Taki

    Rensoburro_Taki

    Joined:
    Sep 2, 2011
    Posts:
    274
    How much money would such a change be worth ? I have to outsource that problem, cause I really need to finish my project.
     
  9. H-Alex

    H-Alex

    Joined:
    Oct 2, 2012
    Posts:
    26
    Hi and thanks for you answer :)
    What is the downside of sharing samplers across textures ? is it better to have one sampler for all ? or as many samplers as possible ?
     
  10. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    There isn't much downside, you'll just have to be aware that these samplers will be sharing the same sampling parameters, for example if a sampler is made as Point sampled and Clamped, then any texture you sample with it will be treated that way regardless of your texture import settings.

    Also I'm not sure on the numbers but I believe most modern GPUs can process multiple samplers in parallel, so there can be some advantage to at least spread some of them out across separate samplers, but i'd imagine it's probably negligible though I've not done any serious tests on it.
     
  11. H-Alex

    H-Alex

    Joined:
    Oct 2, 2012
    Posts:
    26
    Thanks for the feedback. I understand for the sampler parameters part of course. My question was actually mainly about your second point. Having them work in parallel can change performance by a great deal, if you ever happen to find something about that, please share ;) Thanks !
     
  12. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    399
    thanks for this info - very helpful!
     
  13. Double-V

    Double-V

    Joined:
    Aug 13, 2016
    Posts:
    21
    Is there a way to fix this same problem in shader graph?
     
  14. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    399
  15. Double-V

    Double-V

    Joined:
    Aug 13, 2016
    Posts:
    21
    Oh thanks, that's exactly what was happening. I didn't know that when you leave the sampler state at default it's a new one for every SampleTexture node.
     
    jamespaterson likes this.
  16. Liderangel

    Liderangel

    Joined:
    Jul 8, 2018
    Posts:
    101
    jamespaterson likes this.