Advertisement
ensiferum888

TreeLeaf-Seasonal-Red

Nov 12th, 2013
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.06 KB | None | 0 0
  1. Shader "Hidden/Nature/Tree Creator Leaves Optimized Snow-Red" {
  2. Properties {
  3.     _Color ("Main Color", Color) = (1,1,1,1)
  4.     _TranslucencyColor ("Translucency Color", Color) = (0.73,0.85,0.41,1) // (187,219,106,255)
  5.     _Cutoff ("Alpha cutoff", Range(0,1)) = 0.3
  6.     _TranslucencyViewDependency ("View dependency", Range(0,1)) = 0.7
  7.     _ShadowStrength("Shadow Strength", Range(0,1)) = 0.8
  8.     _ShadowOffsetScale ("Shadow Offset Scale", Float) = 1
  9.    
  10.     _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
  11.     _ShadowTex ("Shadow (RGB)", 2D) = "white" {}
  12.     _BumpSpecMap ("Normalmap (GA) Spec (R) Shadow Offset (B)", 2D) = "bump" {}
  13.     _TranslucencyMap ("Trans (B) Gloss(A)", 2D) = "white" {}
  14.    
  15.     // These are here only to provide default values
  16.     _Scale ("Scale", Vector) = (1,1,1,1)
  17.     _SquashAmount ("Squash", Float) = 1
  18. }
  19.  
  20.  
  21. SubShader {
  22.     Tags {
  23.         "IgnoreProjector"="True"
  24.         "RenderType"="TreeLeaf"
  25.     }
  26.     LOD 200
  27.    
  28. CGPROGRAM
  29.  
  30. #pragma surface surf TreeLeaf vertex:TreeVertLeafSnow nolightmap
  31. #pragma exclude_renderers flash
  32. #pragma glsl_no_auto_normalization
  33. #pragma target 3.0
  34.  
  35. #include "TreeSnow.cginc"
  36.  
  37. float _LeafCut; //_LeafCut is a float that allows you to fade the leaves in/out
  38. sampler2D _MainTex;
  39. sampler2D _BumpSpecMap;
  40. sampler2D _TranslucencyMap;
  41. float _Cutoff;
  42.  
  43. // all these have to be send via script = CustomTerrainScriptAtsV3Snow.cs
  44. sampler2D _SnowTexture;
  45. float4 _RedColor; //_RedColor is the color to blend
  46. float _snowShininess;
  47. float _SnowAmount;
  48. float _SnowStartHeight;
  49.  
  50.  
  51. struct Input {
  52.     float2 uv_MainTex;
  53.     fixed4 color : COLOR; // color.a = AO
  54.     float3 worldPos;
  55. };
  56.  
  57. void surf (Input IN, inout LeafSurfaceOutput o) {
  58.     fixed4 col = tex2D(_MainTex, IN.uv_MainTex);
  59.     fixed4 trngls = tex2D (_TranslucencyMap, IN.uv_MainTex);
  60.     o.Translucency = trngls.b;
  61.     o.Alpha = col.a;
  62.    
  63.     // get snow texture
  64.     half3 snowtex = tex2D( _SnowTexture, IN.uv_MainTex).rgb;
  65.    
  66.     // lerp = allows snow even on orthogonal surfaces // (1-col.g) = take the blue channel to get some kind of heightmap // worldNormal is stored in IN.color
  67.     float snowAmount = lerp(_SnowAmount * IN.color.y, 1, _SnowAmount) * (1-col.g) * .65 + o.Normal.y * _SnowAmount *.25 * IN.color.a * trngls.b;
  68.    
  69.     // clamp snow to _SnowStartHeight
  70.     // billboards do not get effected by snowStartHeight anyway...
  71.     snowAmount = snowAmount * clamp((IN.worldPos.y - _SnowStartHeight)*.0125, 0, 1);
  72.    
  73.     // sharpen snow mask
  74.     snowAmount = clamp( pow(snowAmount,6)*256, 0, 0.63);
  75.    
  76.     // mix all together
  77.     o.Gloss = trngls.a * _Color.r ;
  78.     o.Albedo = col.rgb * _RedColor  * IN.color.a ;
  79.     half4 norspc = tex2D (_BumpSpecMap, IN.uv_MainTex);
  80.     o.Specular = norspc.r;
  81.    
  82.     clip(o.Alpha - (_Cutoff + _LeafCut));
  83.     o.Normal = UnpackNormalDXT5nm(norspc);
  84.  
  85.     // smooth normal
  86.     o.Normal = normalize(lerp(o.Normal, float3(0,0,1), snowAmount*.50));
  87. }
  88. ENDCG
  89.  
  90.     // Pass to render object as a shadow caster
  91.     Pass {
  92.         Name "ShadowCaster"
  93.         Tags { "LightMode" = "ShadowCaster" }
  94.        
  95.         Fog {Mode Off}
  96.         ZWrite On ZTest LEqual Cull Off
  97.         Offset 1, 1
  98.  
  99.         CGPROGRAM
  100.         #pragma vertex vert_surf
  101.         #pragma fragment frag_surf
  102.         #pragma exclude_renderers noshadows flash
  103.         #pragma glsl_no_auto_normalization
  104.         #pragma fragmentoption ARB_precision_hint_fastest
  105.         #pragma multi_compile_shadowcaster
  106.         #include "HLSLSupport.cginc"
  107.         #include "UnityCG.cginc"
  108.         #include "Lighting.cginc"
  109.  
  110.         #define INTERNAL_DATA
  111.         #define WorldReflectionVector(data,normal) data.worldRefl
  112.  
  113.         #include "Tree.cginc"
  114.  
  115.         sampler2D _ShadowTex;
  116.         float _LeafCut;
  117.  
  118.         struct Input {
  119.             float2 uv_MainTex;
  120.         };
  121.  
  122.         struct v2f_surf {
  123.             V2F_SHADOW_CASTER;
  124.             float2 hip_pack0 : TEXCOORD1;
  125.         };
  126.         float4 _ShadowTex_ST;
  127.         v2f_surf vert_surf (appdata_full v) {
  128.             v2f_surf o;
  129.             TreeVertLeaf (v);
  130.             o.hip_pack0.xy = TRANSFORM_TEX(v.texcoord, _ShadowTex);
  131.             TRANSFER_SHADOW_CASTER(o)
  132.             return o;
  133.         }
  134.         fixed _Cutoff;
  135.         float4 frag_surf (v2f_surf IN) : COLOR {
  136.             half alpha = tex2D(_ShadowTex, IN.hip_pack0.xy).r;
  137.             clip (alpha - (_Cutoff + _LeafCut) );
  138.             SHADOW_CASTER_FRAGMENT(IN)
  139.         }
  140.         ENDCG
  141.     }
  142.    
  143.     // Pass to render object as a shadow collector
  144.     Pass {
  145.         Name "ShadowCollector"
  146.         Tags { "LightMode" = "ShadowCollector" }
  147.        
  148.         Fog {Mode Off}
  149.         ZWrite On ZTest LEqual
  150.  
  151.         CGPROGRAM
  152.         #pragma vertex vert_surf
  153.         #pragma fragment frag_surf
  154.         #pragma exclude_renderers noshadows flash
  155.         #pragma fragmentoption ARB_precision_hint_fastest
  156.         #pragma multi_compile_shadowcollector
  157.         #pragma glsl_no_auto_normalization
  158.         #include "HLSLSupport.cginc"
  159.         #define SHADOW_COLLECTOR_PASS
  160.         #include "UnityCG.cginc"
  161.         #include "Lighting.cginc"
  162.  
  163.         #define INTERNAL_DATA
  164.         #define WorldReflectionVector(data,normal) data.worldRefl
  165.  
  166.         #include "Tree.cginc"
  167.  
  168.         sampler2D _MainTex;
  169.         sampler2D _BumpSpecMap;
  170.         sampler2D _TranslucencyMap;
  171.         float _ShadowOffsetScale;
  172.         float _LeafCut;
  173.  
  174.         struct Input {
  175.             float2 uv_MainTex;
  176.         };
  177.  
  178.         struct v2f_surf {
  179.             V2F_SHADOW_COLLECTOR;
  180.             float2 hip_pack0 : TEXCOORD5;
  181.             float3 normal : TEXCOORD6;
  182.         };
  183.        
  184.         float4 _MainTex_ST;
  185.        
  186.         v2f_surf vert_surf (appdata_full v) {
  187.             v2f_surf o;
  188.             TreeVertLeaf (v);
  189.             o.hip_pack0.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
  190.            
  191.             float3 worldN = mul((float3x3)_Object2World, SCALED_NORMAL);
  192.             o.normal = mul(_World2Shadow, half4(worldN, 0)).xyz;
  193.  
  194.             TRANSFER_SHADOW_COLLECTOR(o)
  195.             return o;
  196.         }
  197.        
  198.         fixed _Cutoff;
  199.        
  200.         half4 frag_surf (v2f_surf IN) : COLOR {
  201.             half alpha = tex2D(_MainTex, IN.hip_pack0.xy).a;
  202.  
  203.             float3 shadowOffset = _ShadowOffsetScale * IN.normal * tex2D (_BumpSpecMap, IN.hip_pack0.xy).b;
  204.             clip (alpha - (_Cutoff + _LeafCut));
  205.  
  206.             IN._ShadowCoord0 += shadowOffset;
  207.             IN._ShadowCoord1 += shadowOffset;
  208.             IN._ShadowCoord2 += shadowOffset;
  209.             IN._ShadowCoord3 += shadowOffset;
  210.  
  211.             SHADOW_COLLECTOR_FRAGMENT(IN)
  212.         }
  213.         ENDCG
  214.     }
  215. }
  216.  
  217. SubShader {
  218.     Tags {
  219.         "IgnoreProjector"="True"
  220.         "RenderType"="TreeLeaf"
  221.     }
  222.    
  223.     ColorMask RGB
  224.     Lighting On
  225.    
  226.     Pass {
  227.         CGPROGRAM
  228.         #pragma vertex TreeVertLit
  229.         #pragma exclude_renderers shaderonly
  230.        
  231.         #include "UnityCG.cginc"
  232.         #include "Tree.cginc"
  233.         float _LeafCut;
  234.        
  235.         struct v2f {
  236.             float4 pos : SV_POSITION;
  237.             fixed4 color : COLOR;
  238.             float4 uv : TEXCOORD0;
  239.         };
  240.        
  241.         v2f TreeVertLit (appdata_full v) {
  242.             v2f o;
  243.             TreeVertLeaf(v);
  244.  
  245.             o.color.rgb = ShadeVertexLights (v.vertex, v.normal);
  246.                
  247.             o.pos = mul (UNITY_MATRIX_MVP, v.vertex);  
  248.             o.uv = v.texcoord;
  249.             o.color.a = 1.0f;
  250.             return o;
  251.         }
  252.         ENDCG
  253.  
  254.         AlphaTest Greater [_LeafCut]
  255.         SetTexture [_MainTex] { combine texture * primary DOUBLE, texture }
  256.         SetTexture [_MainTex] {
  257.             ConstantColor [_RedColor]
  258.             Combine previous * constant, previous
  259.         }
  260.     }
  261. }
  262.  
  263. SubShader {
  264.     Tags { "RenderType"="TreeLeaf" }
  265.     Pass {
  266.         ColorMask RGB
  267.        
  268.         Material {
  269.             Diffuse (1,1,1,1)
  270.             Ambient (1,1,1,1)
  271.         }
  272.         Lighting On
  273.        
  274.        
  275.         AlphaTest Greater [_LeafCut]
  276.         SetTexture [_MainTex] { Combine texture * primary DOUBLE, texture }
  277.         SetTexture [_MainTex] {
  278.             ConstantColor [_RedColor]
  279.             Combine previous * constant, previous
  280.         }
  281.     }
  282. }
  283.  
  284. Dependency "BillboardShader" = "Hidden/Nature/Tree Creator Leaves Rendertex Snow-Red"
  285. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement