Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Errors in a line my shader hasn't

Discussion in 'Shaders' started by asdfghjkloi87654, Apr 14, 2014.

  1. asdfghjkloi87654

    asdfghjkloi87654

    Joined:
    Feb 16, 2013
    Posts:
    43
    Hi,

    I have created a shader which had 4 textures and should blend them together with the vertex-colors. additionally it should make the projecting tri-planar (I am using uv coords to transport normal values due to several reasons). I am very new to shaders and I got errors I don't understand in line 80-100 but my shader is only 60 lines long !

    I really wrecked my brain about but I hardly know what to do. Please help !

    Here's the code :

    Code (csharp):
    1.  
    2.  
    3. Shader "Custom/Terrain" {
    4.     Properties {
    5.        
    6.         _MainTex ("Texture 1", 2D) = "white" {}
    7.         _MainTex1 ("Texture 2", 2D) = "white" {}
    8.         _MainTex2 ("Texture 3", 2D) = "white" {}
    9.         _MainTex3 ("Texture 4", 2D) = "white" {}
    10.        
    11.         _TextureScale ("Texture Scale",float) = 1
    12.     }
    13.     SubShader {
    14.         // note : some parts are from "voxeland"
    15.        
    16.         CGPROGRAM
    17.        
    18.         #pragma surface surf BlinnPhong
    19.         #pragma target 3.0
    20.  
    21.         struct Input {
    22.            
    23.             float3 worldPos;
    24.             float2 uv_MainTex1;
    25.             float2 uv1_MainTex1;
    26.             float4 color : COLOR;
    27.        
    28.         };
    29.  
    30.         sampler2D _MainTex;
    31.         sampler2D _MainTex1;
    32.         sampler2D _MainTex2;
    33.         sampler2D _MainTex3;
    34.         float _TextureScale;
    35.  
    36.         void surf (Input IN, inout SurfaceOutput o) {
    37.            
    38.             half2 yUV = frac(IN.worldPos.xz / _TextureScale);
    39.             half2 xUV = frac(IN.worldPos.zy / _TextureScale);
    40.             half2 zUV = frac(IN.worldPos.xy / _TextureScale);
    41.            
    42.             half2 fs1 = IN.uv_MainTex1;
    43.             half2 fs2 = IN.uv1_MainTex1;
    44.            
    45.             half3 norm = half3(fs1.y,fs2.x,fs2.y);
    46.             half4 color4 = 1-IN.color.r-IN.color.b-IN.color.g;
    47.            
    48.             fixed4 tex_y = tex2D(_MainTex, yUV)*IN.color.r*norm.y
    49.                 + tex2D(_MainTex1, yUV)*IN.color.g*norm.y
    50.                 + tex2D(_MainTex2, yUV)*IN.color.b*norm.y
    51.                 + tex2D(_MainTex3, yUV)*color4*norm.y;
    52.            
    53.             fixed4 tex_x = tex2D(_MainTex, yUV)*IN.color.r*norm.x
    54.                 + tex2D(_MainTex1, xUV)*IN.color.g*norm.x
    55.                 + tex2D(_MainTex2, xUV)*IN.color.b*norm.x
    56.                 + tex2D(_MainTex3, xUV)*color4*norm.x;
    57.                
    58.             fixed4 tex_z = tex2D(_MainTex, yUV)*IN.color.r*norm.z
    59.                 + tex2D(_MainTex1, zUV)*IN.color.g*norm.z
    60.                 + tex2D(_MainTex2, zUV)*IN.color.b*norm.z
    61.                 + tex2D(_MainTex3, zUV)*color4*norm.z;
    62.                
    63.                
    64.             o.Albedo = tex_x.rgb+tex_y.rgb+tex_z.rgb;
    65.             o.Alpha = 1.0f;
    66.        
    67.         }
    68.        
    69.         ENDCG
    70.     }
    71.    
    72.     Fallback "VertexLit"
    73. }
    74.  
    75.  
    76.