GroundCover.shader 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  2. Shader "Custom/GroundCover" {
  3. Properties {
  4. _Color ("Color", Color) = (1,1,1,1)
  5. _MainTex ("Albedo", 2D) = "white" {}
  6. [NoScaleOffset]_MetallicSmooth ("_MetallicSmooth", 2D) = "white" {}
  7. _Glossiness ("Smoothness", Range(0,1)) = 0.5
  8. _Metallic ("Metallic", Range(0,1)) = 0.0
  9. [NoScaleOffset]_Normal("Normal", 2D) = "bump" {}
  10. _NormalScale ("Normal Scale", Float) = 1.0
  11. [NoScaleOffset]_Occlusion ("Occlusion", 2D) = "white" {}
  12. _OcclusionScale ("Occlusion Scale", Range(0, 1)) = 1.0
  13. [NoScaleOffset]_WindNoise ("_WindNoise", 2D) = "white" {}
  14. _NoiseAmount ("Noise Amount", Vector) = (0,0,0,0)
  15. _NoiseScale ("Noise Texture Scale", Float) = 1.0
  16. }
  17. SubShader {
  18. Tags { "RenderType"="Opaque" }
  19. LOD 200
  20. Cull off
  21. CGPROGRAM
  22. // Physically based Standard lighting model, and enable shadows on all light types
  23. #pragma surface surf Standard fullforwardshadows vertex:vert addshadow
  24. // Use shader model 3.0 target, to get nicer looking lighting
  25. #pragma target 3.0
  26. sampler2D _MainTex, _WindNoise, _Normal, _MetallicSmooth, _Occlusion;
  27. struct Input {
  28. float2 uv_MainTex;
  29. float3 worldPos;
  30. float4 vertCol : COLOR;
  31. INTERNAL_DATA
  32. };
  33. half _Glossiness;
  34. half _NormalScale, _OcclusionScale;
  35. half _Metallic, _NoiseScale;
  36. fixed4 _Color;
  37. half4 _NoiseAmount;
  38. void vert (inout appdata_full v, out Input o) {
  39. UNITY_INITIALIZE_OUTPUT(Input,o);
  40. float3 worldPos = mul (unity_ObjectToWorld, v.vertex).xyz;
  41. float3 offset = float3(0, 0.1, 0.2);
  42. float2 UV = worldPos.xz;
  43. UV.xy += _Time*2;
  44. float3 windNoise = tex2Dlod(_WindNoise, float4(UV, 0, 0) * _NoiseScale).rgb;
  45. v.vertex.z += sin(_Time*20) * v.color.a * _NoiseAmount.z * v.color.r * windNoise.g;
  46. v.vertex.z += sin(_Time*15) * v.color.a * _NoiseAmount.z * v.color.g * windNoise.g;
  47. v.vertex.z += sin(_Time*25) * v.color.a * _NoiseAmount.z * v.color.b * windNoise.g;
  48. v.vertex.x += sin(_Time*20) * v.color.a * _NoiseAmount.x * v.color.r * windNoise.r;
  49. v.vertex.x += sin(_Time*15) * v.color.a * _NoiseAmount.x * v.color.g * windNoise.r;
  50. v.vertex.x += sin(_Time*25) * v.color.a * _NoiseAmount.x * v.color.b * windNoise.r;
  51. v.vertex.y += windNoise.r * _NoiseAmount.y * v.color.a * v.color.r;
  52. v.vertex.y += windNoise.g * _NoiseAmount.y * v.color.a * v.color.g;
  53. v.vertex.y += windNoise.b * _NoiseAmount.y * v.color.a * v.color.b;
  54. }
  55. // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
  56. // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
  57. // #pragma instancing_options assumeuniformscaling
  58. UNITY_INSTANCING_BUFFER_START(Props)
  59. // put more per-instance properties here
  60. UNITY_INSTANCING_BUFFER_END(Props)
  61. void surf (Input IN, inout SurfaceOutputStandard o) {
  62. // Albedo comes from a texture tinted by color
  63. fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
  64. fixed4 noiseTex = tex2D (_WindNoise, IN.worldPos.xz * 0.1);
  65. c.rgb *= lerp(_Color, float4(1,1,1,1), noiseTex);
  66. o.Albedo = c.rgb;
  67. o.Normal = UnpackScaleNormal(tex2D(_Normal, IN.uv_MainTex), _NormalScale);
  68. o.Occlusion = lerp(1, tex2D (_Occlusion, IN.uv_MainTex), _OcclusionScale);
  69. fixed4 metallicSmooth = tex2D (_MetallicSmooth, IN.uv_MainTex);
  70. o.Metallic = _Metallic * metallicSmooth.r;
  71. o.Smoothness = _Glossiness * metallicSmooth.a;
  72. o.Alpha = c.a;
  73. clip(c.a - 0.5);
  74. }
  75. ENDCG
  76. }
  77. FallBack "Diffuse"
  78. }