Advanced Grass Standard.shader 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. Shader "NatureManufacture Shaders/Grass/Advanced Grass Standard"
  2. {
  3. Properties
  4. {
  5. _Cutoff( "Mask Clip Value", Float ) = 0.051
  6. _HealthyColor("Healthy Color", Color) = (1,1,1,1)
  7. _DryColor("Dry Color", Color) = (0.875,0.8280551,0.7270221,1)
  8. _ColorNoiseSpread("Color Noise Spread", Float) = 15
  9. _MainTex("MainTex", 2D) = "white" {}
  10. [NoScaleOffset]_BumpMap("BumpMap", 2D) = "bump" {}
  11. _BumpScale("BumpScale", Range( 0 , 2)) = 1
  12. [NoScaleOffset]_AmbientOcclusionG("AO (G) Sm (A)", 2D) = "white" {}
  13. _AmbientOcclusionPower("Ambient Occlusion Power", Range( 0 , 1)) = 0
  14. _Metallic("Metallic", Range( 0 , 1)) = 0
  15. _SmoothnessPower("Smoothness Power", Range( 0 , 2)) = 0
  16. _NewNormal("Vertex Normal Multiply", Vector) = (0,0,0,0)
  17. _InitialBend("Wind Initial Bend", Float) = 1
  18. _Stiffness("Wind Stiffness", Float) = 1
  19. _Drag("Wind Drag", Float) = 1
  20. _ShiverDrag("Wind Shiver Drag", Float) = 0.05
  21. _ShiverDirectionality("Wind Shiver Directionality", Range( 0 , 1)) = 0.5
  22. _WindColorInfluence("Wind Color Influence", Vector) = (0,0,0,0)
  23. _WindColorThreshold("Wind Color Threshold", Range( 0 , 10)) = 1
  24. _WindNormalInfluence("Wind Normal Influence", Float) = 0
  25. _CullFarStart("CullFarStart", Range( 0 , 10000)) = 40
  26. _CullFarDistance("CullFarDistance", Range( 0 , 10000)) = 5
  27. [Toggle]_BackFaceMirrorNormal("BackFace Mirror Normal", Float) = 1
  28. [Toggle(_TOUCHREACTACTIVE_ON)] _TouchReactActive("TouchReactActive", Float) = 0
  29. [HideInInspector] _texcoord( "", 2D ) = "white" {}
  30. [HideInInspector] __dirty( "", Int ) = 1
  31. }
  32. SubShader
  33. {
  34. Tags{ "RenderType" = "Transparent" "Queue" = "Geometry+0" }
  35. Cull Off
  36. CGPROGRAM
  37. #include "UnityStandardUtils.cginc"
  38. #include "UnityShaderVariables.cginc"
  39. #pragma target 3.0
  40. #pragma multi_compile_instancing
  41. #pragma shader_feature _TOUCHREACTACTIVE_ON
  42. #include "NMWind.cginc"
  43. #include "NM_indirect.cginc"
  44. #pragma vertex vert
  45. #pragma multi_compile GPU_FRUSTUM_ON __
  46. #pragma instancing_options procedural:setup
  47. #pragma surface surf Standard keepalpha addshadow fullforwardshadows
  48. struct Input
  49. {
  50. half2 uv_texcoord;
  51. half ASEVFace : VFACE;
  52. float3 worldPos;
  53. float4 vertexColor : COLOR;
  54. };
  55. uniform half _BackFaceMirrorNormal;
  56. uniform half _BumpScale;
  57. uniform sampler2D _BumpMap;
  58. uniform sampler2D _MainTex;
  59. uniform float4 _MainTex_ST;
  60. uniform half4 _HealthyColor;
  61. uniform half4 _DryColor;
  62. uniform half _ColorNoiseSpread;
  63. uniform half3 _WindColorInfluence;
  64. uniform half _WindColorThreshold;
  65. uniform half _Metallic;
  66. uniform sampler2D _AmbientOcclusionG;
  67. uniform half _SmoothnessPower;
  68. uniform half _AmbientOcclusionPower;
  69. uniform float _Cutoff = 0.051;
  70. float3 mod2D289( float3 x ) { return x - floor( x * ( 1.0 / 289.0 ) ) * 289.0; }
  71. float2 mod2D289( float2 x ) { return x - floor( x * ( 1.0 / 289.0 ) ) * 289.0; }
  72. float3 permute( float3 x ) { return mod2D289( ( ( x * 34.0 ) + 1.0 ) * x ); }
  73. float snoise( float2 v )
  74. {
  75. const float4 C = float4( 0.211324865405187, 0.366025403784439, -0.577350269189626, 0.024390243902439 );
  76. float2 i = floor( v + dot( v, C.yy ) );
  77. float2 x0 = v - i + dot( i, C.xx );
  78. float2 i1;
  79. i1 = ( x0.x > x0.y ) ? float2( 1.0, 0.0 ) : float2( 0.0, 1.0 );
  80. float4 x12 = x0.xyxy + C.xxzz;
  81. x12.xy -= i1;
  82. i = mod2D289( i );
  83. float3 p = permute( permute( i.y + float3( 0.0, i1.y, 1.0 ) ) + i.x + float3( 0.0, i1.x, 1.0 ) );
  84. float3 m = max( 0.5 - float3( dot( x0, x0 ), dot( x12.xy, x12.xy ), dot( x12.zw, x12.zw ) ), 0.0 );
  85. m = m * m;
  86. m = m * m;
  87. float3 x = 2.0 * frac( p * C.www ) - 1.0;
  88. float3 h = abs( x ) - 0.5;
  89. float3 ox = floor( x + 0.5 );
  90. float3 a0 = x - ox;
  91. m *= 1.79284291400159 - 0.85373472095314 * ( a0 * a0 + h * h );
  92. float3 g;
  93. g.x = a0.x * x0.x + h.x * x0.y;
  94. g.yz = a0.yz * x12.xz + h.yz * x12.yw;
  95. return 130.0 * dot( m, g );
  96. }
  97. void surf( Input i , inout SurfaceOutputStandard o )
  98. {
  99. float2 uv0_MainTex = i.uv_texcoord * _MainTex_ST.xy + _MainTex_ST.zw;
  100. half3 tex2DNode4 = UnpackScaleNormal( tex2D( _BumpMap, uv0_MainTex ), _BumpScale );
  101. float3 switchResult436 = (((i.ASEVFace>0)?(tex2DNode4):(( tex2DNode4 * float3( -1,-1,-1 ) ))));
  102. o.Normal = lerp(tex2DNode4,switchResult436,_BackFaceMirrorNormal);
  103. float3 ase_worldPos = i.worldPos;
  104. float2 appendResult427 = (half2(ase_worldPos.x , ase_worldPos.z));
  105. float simplePerlin2D430 = snoise( ( appendResult427 / _ColorNoiseSpread ) );
  106. float4 lerpResult432 = lerp( _HealthyColor , _DryColor , simplePerlin2D430);
  107. half4 tex2DNode3 = tex2D( _MainTex, uv0_MainTex );
  108. float clampResult424 = clamp( i.vertexColor.r , 0.0 , 1.0 );
  109. float3 lerpResult441 = lerp( ( float3( 1,1,1 ) - _WindColorInfluence ) , ( float3( 1,1,1 ) + _WindColorInfluence ) , pow( clampResult424 , _WindColorThreshold ));
  110. o.Albedo = ( ( lerpResult432 * tex2DNode3 ) * half4( lerpResult441 , 0.0 ) ).rgb;
  111. o.Metallic = _Metallic;
  112. half4 tex2DNode98 = tex2D( _AmbientOcclusionG, uv0_MainTex );
  113. o.Smoothness = ( tex2DNode98.a * _SmoothnessPower );
  114. float clampResult150 = clamp( tex2DNode98.g , ( 1.0 - _AmbientOcclusionPower ) , 1.0 );
  115. o.Occlusion = clampResult150;
  116. o.Alpha = 1;
  117. //clip( ( ( 1.0 - saturate( ( ( distance( ase_worldPos , _WorldSpaceCameraPos ) - _CullFarStart ) / _CullFarDistance ) ) ) * tex2DNode3.a ) - _Cutoff );
  118. clip( tex2DNode3.a - _Cutoff );
  119. }
  120. ENDCG
  121. }
  122. Fallback "Diffuse"
  123. }