Lux URP Wind Visualize.shader 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. Shader "Lux URP/Vegetation/Wind Visualize"
  2. {
  3. Properties
  4. {
  5. [Header(Select Mode)]
  6. [KeywordEnum(Combined Wind, Wind Strength, Wind Gust)]
  7. _Visualize ("Visualize", Float) = 0
  8. }
  9. SubShader
  10. {
  11. Tags
  12. {
  13. "RenderPipeline" = "UniversalPipeline"
  14. "RenderType"="Transparent"
  15. "Queue"="Transparent"
  16. }
  17. Pass
  18. {
  19. Name "StandardUnlit"
  20. Tags{"LightMode" = "UniversalForward"}
  21. //Blend One One
  22. Blend SrcAlpha OneMinusSrcAlpha
  23. Cull Back
  24. ZTest LEqual
  25. ZWrite Off
  26. HLSLPROGRAM
  27. // Required to compile gles 2.0 with standard srp library
  28. #pragma prefer_hlslcc gles
  29. #pragma exclude_renderers d3d11_9x
  30. #pragma target 3.0
  31. // -------------------------------------
  32. // Unity defined keywords
  33. //--------------------------------------
  34. // GPU Instancing
  35. #pragma vertex vert
  36. #pragma fragment frag
  37. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  38. CBUFFER_START(UnityPerMaterial)
  39. float _Visualize;
  40. CBUFFER_END
  41. TEXTURE2D(_LuxLWRPWindRT); SAMPLER(sampler_LuxLWRPWindRT); float4 _LuxLWRPWindRT_TexelSize;
  42. float4 _LuxLWRPWindDirSize;
  43. struct VertexInput
  44. {
  45. float4 vertex : POSITION;
  46. UNITY_VERTEX_INPUT_INSTANCE_ID
  47. };
  48. struct VertexOutput
  49. {
  50. float4 positionCS : SV_POSITION;
  51. float3 positionWS : TEXCOORD0;
  52. UNITY_VERTEX_INPUT_INSTANCE_ID
  53. UNITY_VERTEX_OUTPUT_STEREO
  54. };
  55. VertexOutput vert (VertexInput v)
  56. {
  57. VertexOutput o = (VertexOutput)0;
  58. UNITY_SETUP_INSTANCE_ID(v);
  59. UNITY_TRANSFER_INSTANCE_ID(v, o);
  60. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  61. o.positionCS = TransformObjectToHClip(v.vertex.xyz);
  62. o.positionWS = mul(UNITY_MATRIX_M,v.vertex).xyz;
  63. return o;
  64. }
  65. half3 getResult(half4 sample) {
  66. half full = sample.r * (sample.g * 2.0h - 0.243h); // - 0.24376f /* not a "real" normal as we want to keep the base direction */ );
  67. half neg = saturate(-full);
  68. switch(_Visualize) {
  69. case 0:
  70. half3 result = (neg == 0) ? full.xxx : half3(neg, full.xx);
  71. return result;
  72. case 1:
  73. return sample.rrr;
  74. case 2:
  75. return sample.ggg;
  76. default:
  77. return sample.rgb;
  78. }
  79. }
  80. half4 frag (VertexOutput input ) : SV_Target
  81. {
  82. UNITY_SETUP_INSTANCE_ID(input);
  83. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  84. half4 sample = SAMPLE_TEXTURE2D(_LuxLWRPWindRT, sampler_LuxLWRPWindRT, input.positionWS.xz * _LuxLWRPWindDirSize.w);
  85. half3 finalCol = getResult(sample);
  86. return half4(finalCol, .5);
  87. }
  88. ENDHLSL
  89. }
  90. }
  91. FallBack "Hidden/InternalErrorShader"
  92. }