Lux URP WindComposite.shader 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // http://www.iquilezles.org/www/articles/dynclouds/dynclouds.htm
  2. Shader "Hidden/Lux URP WindComposite"
  3. {
  4. Properties
  5. {
  6. _MainTex ("Texture", 2D) = "white" {}
  7. }
  8. SubShader
  9. {
  10. Tags { "RenderPipeline" = "LightweightPipeline" }
  11. Pass
  12. {
  13. HLSLPROGRAM
  14. // Required to compile gles 2.0 with standard SRP library
  15. #pragma prefer_hlslcc gles
  16. #pragma exclude_renderers d3d11_9x
  17. #pragma target 2.0
  18. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  19. // Global Inputs
  20. float3 _LuxLWRPWindDir;
  21. float2 _LuxLWRPWindUVs;
  22. float2 _LuxLWRPWindUVs1;
  23. float2 _LuxLWRPWindUVs2;
  24. float2 _LuxLWRPWindUVs3;
  25. float2 _LuxLWRPGust;
  26. half3 _GustMixLayer;
  27. TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex); float4 _MainTex_ST;
  28. #pragma vertex vert
  29. #pragma fragment frag
  30. struct VertexInput
  31. {
  32. float4 positionOS : POSITION;
  33. half2 texcoord : TEXCOORD0;
  34. };
  35. struct VertexOutput
  36. {
  37. float4 positionCS : SV_POSITION;
  38. float2 uv : TEXCOORD0;
  39. };
  40. VertexOutput vert( VertexInput v )
  41. {
  42. VertexOutput output;
  43. output.positionCS = TransformObjectToHClip(v.positionOS.xyz);
  44. output.uv = v.texcoord;
  45. return output;
  46. }
  47. half4 frag(VertexOutput i) : SV_Target {
  48. half4 n1 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + _LuxLWRPWindUVs);
  49. half4 n2 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + _LuxLWRPWindUVs1);
  50. half4 n3 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + _LuxLWRPWindUVs2);
  51. half4 n4 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv * _LuxLWRPGust.x + _LuxLWRPWindUVs3);
  52. half4 sum = half4(n1.r, n1.g + n2.g, n1.b + n2.b + n3.b, n1.a + n2.a + n3.a + n4.a);
  53. const half4 weights = half4(0.5000, 0.2500 , 0.1250 , 0.0625 );
  54. half2 WindStrengthGustNoise;
  55. // WindStrength
  56. WindStrengthGustNoise.x = dot(sum, weights);
  57. // GrassGustNoise / _LuxLWRPGust.y comes in as 0.5 - 1.5
  58. WindStrengthGustNoise.y = lerp(1.0h, (n4.a + dot(half3(n1.a, n2.a, n3.a), _GustMixLayer)) * 0.85h, _LuxLWRPGust.y - 0.5h);
  59. // Sharpen WindStrengthGustNoise according to turbulence
  60. WindStrengthGustNoise = (WindStrengthGustNoise - half2(0.5h, 0.5h)) * _LuxLWRPGust.yy + half2(0.5h, 0.5h);
  61. return half4(
  62. WindStrengthGustNoise,
  63. //n4.a,
  64. //0
  65. (n3.a + abs(WindStrengthGustNoise.y)) * 0.5h + n2.a * 0.0h,
  66. 0
  67. );
  68. }
  69. ENDHLSL
  70. }
  71. }
  72. }