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

Question Unity Combining Two Shader

Discussion in 'Shaders' started by Vanlotr, Sep 22, 2022.

  1. Vanlotr

    Vanlotr

    Joined:
    Aug 11, 2019
    Posts:
    11
    How?

    Code (CSharp):
    1. Shader "Unlit/CurvedUnlit"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture", 2D) = "white" {}
    6.     }
    7.     SubShader
    8.     {
    9.         Tags { "RenderType"="Opaque" }
    10.         LOD 100
    11.  
    12.         Pass
    13.         {
    14.             CGPROGRAM
    15.             #pragma vertex vert
    16.             #pragma fragment frag
    17.             // make fog work
    18.             #pragma multi_compile_fog
    19.                
    20.             #include "CurvedCode.cginc"
    21.  
    22.             ENDCG
    23.         }
    24.     }
    25. }
    Code (CSharp):
    1. Shader "Custom/chr_outline"{
    2.     Properties {
    3.         _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
    4.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
    5.         _OutlineColor ("Outline Color", Color) = (0,0,0,1)
    6.         _OutlineWidth ("Outline Width", Range(1,5)) = 1
    7.     }
    8.  
    9.     CGINCLUDE
    10.  
    11.     #include "UnityCG.cginc"
    12.  
    13.     struct appdata
    14.     {
    15.         float4 vertex : POSITION;
    16.         float3 normal : NORMAL;
    17.     };
    18.  
    19.     struct v2f
    20.     {
    21.         float4 pos : POSITION;
    22.         float3 normal : NORMAL;
    23.     };
    24.    
    25.     float _OutlineWidth;
    26.     float4 _OutlineColor;
    27.  
    28.     v2f vert (appdata v)
    29.     {
    30.         v.vertex.xyz *= _OutlineWidth;
    31.  
    32.         v2f o;
    33.         o.pos = UnityObjectToClipPos(v.vertex);
    34.         return o;
    35.     }
    36.     ENDCG
    37.  
    38.     Subshader
    39.     {
    40.  
    41.     Tags { "Queue" = "Transparent"}
    42.         LOD 3000
    43.         Pass //Rendering Outlines
    44.         {
    45.             Zwrite Off
    46.  
    47.     CGPROGRAM
    48.     #pragma vertex vert
    49.     #pragma fragment frag
    50.  
    51.     half4 frag(v2f i) : COLOR
    52.     {
    53.         return _OutlineColor;
    54.     }
    55.             ENDCG
    56.         }
    57.         Pass // Normal Render
    58.         {
    59.             ZWrite On
    60.  
    61.             Material
    62.             {
    63.                 Diffuse[_Color]
    64.                 Ambient[_Color]
    65.             }
    66.  
    67.             Lighting On  
    68.            
    69.             SetTexture[_MainTex]
    70.             {
    71.                 ConstantColor[_Color]
    72.             }
    73.  
    74.             SetTexture[_MainTex]
    75.             {
    76.                 Combine previous * primary DOUBLE
    77.             }
    78.  
    79.         }
    80.     }
    81.  
    82.     }