Search Unity

Adding features and modifying shader

Discussion in 'Shaders' started by RoyalCoder, Mar 14, 2018.

  1. RoyalCoder

    RoyalCoder

    Joined:
    Oct 4, 2013
    Posts:
    301
    Hi guys, I got a nice shader and I want to add more detail textures and modify the colors of them, but I don't have any idea how to achieve this, I never write a shader in my life, can you help or guide me how to do that?

    The shader:
    Code (CSharp):
    1. Shader "Paint/Detail Material" {
    2.     Properties {
    3.         _Color ("Main Color", Color) = (1,1,1,1)
    4.         _Detail ("Detail Texture", 2D) = "black" {} //--->One detail texture I want to have 2 or more & modify the colors of detail textures
    5.         _SpecularMap("Specular Map", 2D) = "white" {}
    6.         _Cube ("Cubemap", CUBE) = "" {}
    7.         _BumpMap ("Bumpmap (RGB Trans)", 2D) = "bump" {}
    8.         _Reflection ("Reflection", Range(0, 1)) = 0.5
    9.         _SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,1)
    10.         _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
    11.         _RimPower ("Rim Power", Range(0.5,8.0)) = 3.0
    12.     }
    13.     SubShader {
    14.         Tags { "RenderType"="Opaque" }
    15.         LOD 200
    16.  
    17.         CGPROGRAM
    18.         #pragma surface surf BlinnPhong
    19.         #pragma target 3.0
    20.  
    21.         sampler2D _SpecularMap;
    22.         samplerCUBE _Cube;
    23.         half4 _Color;
    24.         half4 _DecalColor;
    25.         half _Reflection;
    26.         half _RimPower;
    27.         float _Shininess;
    28.         sampler2D _BumpMap;
    29.         sampler2D _Detail;
    30.  
    31.         struct Input {
    32.             float2 uv_BumpMap;
    33.             float2 uv_Detail;
    34.             float3 worldRefl;
    35.             float3 viewDir;
    36.             float2 uv_SpecularMap;
    37.             INTERNAL_DATA
    38.         };
    39.  
    40.         void surf (Input IN, inout SurfaceOutput o) {
    41.             half4 bump = tex2D(_BumpMap, IN.uv_BumpMap);
    42.             half4 detail = tex2D(_Detail, IN.uv_Detail);
    43.             half3 norm = UnpackNormal (bump);
    44.             half4 grain = tex2D (_SpecularMap, IN.uv_SpecularMap);
    45.             half4 refl = texCUBE (_Cube, WorldReflectionVector (IN, norm));
    46.             half rim1 = saturate(dot(normalize(IN.viewDir), norm));
    47.             half rim2 = 1 - rim1;
    48.             half3 color = lerp(_Color.rgb, detail.rgb, detail.a);
    49.             o.Normal = norm;
    50.             o.Gloss = _SpecColor.rgb * (1 - detail.a);
    51.             o.Albedo = lerp(color, color + refl.rgb * pow(rim1, _RimPower), _Reflection * (1 - detail.a / 2));
    52.             o.Alpha = 1;
    53.             o.Specular = (1 - grain.a * _SpecColor.a) * _Shininess * (1 - detail.a);
    54.             o.Emission = refl * _Reflection * pow(rim2, _RimPower) * (1 - detail.a);
    55.         }
    56.         ENDCG
    57.     }
    58.     FallBack "Specular"
    59. }
    60.