Search Unity

Question How to create a tree billboard in a fragment shader that is affected by directional cookies?

Discussion in 'General Graphics' started by dienat, Jul 5, 2021.

  1. dienat

    dienat

    Joined:
    May 27, 2016
    Posts:
    417
    I want to change the builting tree billboard in unity to support directional cookies and affected by directional lights but don't get it, this is the default shader

    Code (CSharp):
    1.  
    2. Shader "Hidden/TerrainEngine/BillboardTree" {
    3.     Properties {
    4.         _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
    5.     }
    6.  
    7.     SubShader {
    8.         Fog { Mode Off }
    9.         Tags { "Queue" = "Transparent-100" "IgnoreProjector"="True" "RenderType"="TreeBillboard" }
    10.  
    11.         Pass {
    12.             ColorMask rgb
    13.             Blend SrcAlpha OneMinusSrcAlpha
    14.             ZWrite Off Cull Off
    15.  
    16.             CGPROGRAM
    17.             #pragma vertex vert
    18.             #pragma fragment frag
    19.             #pragma multi_compile_fog
    20.             #include "UnityCG.cginc"
    21.             #include "TerrainEngine.cginc"
    22.  
    23.             struct v2f {
    24.                 float4 pos : SV_POSITION;
    25.                 fixed4 color : COLOR0;
    26.                 float2 uv : TEXCOORD0;
    27.                 UNITY_FOG_COORDS(1)
    28.                 UNITY_VERTEX_OUTPUT_STEREO
    29.             };
    30.  
    31.             v2f vert (appdata_tree_billboard v) {
    32.                 v2f o;
    33.                 UNITY_SETUP_INSTANCE_ID(v);
    34.                 UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    35.                 TerrainBillboardTree(v.vertex, v.texcoord1.xy, v.texcoord.y);
    36.                 o.pos = UnityObjectToClipPos(v.vertex);
    37.                 o.uv.x = v.texcoord.x;
    38.                 o.uv.y = v.texcoord.y > 0;
    39.                 o.color = v.color;
    40.                 UNITY_TRANSFER_FOG(o,o.pos);
    41.                 return o;
    42.             }
    43.  
    44.             sampler2D _MainTex;
    45.             fixed4 frag(v2f input) : SV_Target
    46.             {
    47.                 fixed4 col = tex2D( _MainTex, input.uv);
    48.                 col.rgb *= input.color.rgb;
    49.                 clip(col.a);
    50.                 UNITY_APPLY_FOG(input.fogCoord, col);
    51.                 return col;
    52.             }
    53.             ENDCG
    54.         }
    55.     }
    56.  
    57.     Fallback Off
    58. }
    59.