Tree_leaf.shader 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. Shader "Custom/Tree_leavf"
  2. {
  3. Properties
  4. {
  5. _Color ("Color", Color) = (1,1,1,1)
  6. _MainTex ("Albedo (RGB)", 2D) = "white" {}
  7. _MaskTex("MaskTex",2D) = "white" {}
  8. _BumpMap("Normal",2D)= "bump" {}
  9. _AlphaCut("CutOff",Range(0,1)) = 0.5
  10. _Glossiness ("Smoothness", Range(0,1)) = 0.5
  11. _Metallic ("Metallic", Range(0,1)) = 0.0
  12. _OccColor ("OccColor", Color) = (1,1,1,1)
  13. _NoisTex("NoisTex",2D)="white" {}
  14. _TreeCol1("TreeCol1",Color) = (1,1,1,1)
  15. _TreeCol2("TreeCol2",Color) = (1,1,1,1)
  16. }
  17. SubShader
  18. {
  19. Cull Off
  20. Tags { "RenderType"="Opaque" }
  21. LOD 200
  22. CGPROGRAM
  23. fixed _AlphaCut;
  24. // Physically based Standard lighting model, and enable shadows on all light types
  25. #pragma surface surf Standard addshadow
  26. // Use shader model 3.0 target, to get nicer looking lighting
  27. #pragma target 3.0
  28. sampler2D _MainTex,_BumpMap,_MaskTex,_NoisTex;
  29. float4 _NoisTex_ST;
  30. struct Input
  31. {
  32. float2 uv_MainTex;
  33. float2 uv_BumpMap;
  34. float2 uv_MaskTex;
  35. fixed face : VFACE;
  36. float2 uv2 : TEXCOORD1;
  37. float3 worldPos;
  38. float3 vertexColor:COLOR;
  39. };
  40. half _Glossiness;
  41. half _Metallic;
  42. fixed4 _Color,_OccColor,_TreeCol1,_TreeCol2;
  43. // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
  44. // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
  45. // #pragma instancing_options assumeuniformscaling
  46. UNITY_INSTANCING_BUFFER_START(Props)
  47. //UNITY_DEFINE_INSTANCED_PROP(float4, _WorldPointPos)
  48. UNITY_INSTANCING_BUFFER_END(Props)
  49. void surf (Input IN, inout SurfaceOutputStandard o)
  50. {
  51. // Albedo comes from a texture tinted by color
  52. fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
  53. clip(c.a-_AlphaCut);
  54. //float4 point=UNITY_ACCESS_INSTANCED_PROP(Props, _WorldPointPos);
  55. fixed colfactor = tex2D(_NoisTex,IN.worldPos.xz*_NoisTex_ST.xy+_NoisTex_ST.zw).r;
  56. fixed3 worldcol = lerp(_TreeCol1.rgb,_TreeCol2.rgb,colfactor);
  57. // Metallic and smoothness come from slider variables
  58. o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
  59. o.Normal = IN.face?o.Normal:-o.Normal;
  60. fixed4 mask = tex2D (_MaskTex, IN.uv_MaskTex);
  61. fixed3 acc = lerp(_OccColor.rgb,fixed3(1,1,1),IN.vertexColor.g);
  62. fixed3 updowCol = lerp(_TreeCol1.rgb,_TreeCol2.rgb,IN.worldPos.y/30);
  63. o.Albedo = c.rgb*acc*_Color*worldcol*updowCol;
  64. //o.Albedo=colfactor;
  65. o.Metallic = _Metallic*mask.r;
  66. o.Smoothness = _Glossiness*mask.a;
  67. o.Alpha = c.a;
  68. }
  69. ENDCG
  70. }
  71. FallBack "Diffuse"
  72. }