EnviroVolumetricCloudsDepthHDRP.shader 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. Shader "Hidden/EnviroVolumetricCloudsDepthHDRP"
  2. {
  3. Properties
  4. {
  5. // _CameraDepthTexture ("Texture", any) = "white" {}
  6. }
  7. SubShader
  8. {
  9. Tags { "RenderType"="Opaque" }
  10. LOD 100
  11. //Pass 1 downsample
  12. Pass
  13. {
  14. Cull Off ZWrite Off ZTest Always
  15. HLSLPROGRAM
  16. #pragma vertex vert
  17. #pragma fragment frag
  18. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
  19. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  20. #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
  21. #include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl"
  22. #include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl"
  23. #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl"
  24. #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUtils.hlsl"
  25. float4 _CameraDepthTexture_TexelSize;
  26. struct appdata
  27. {
  28. uint vertexID : SV_VertexID;
  29. float2 uv : TEXCOORD0;
  30. UNITY_VERTEX_INPUT_INSTANCE_ID
  31. };
  32. struct v2f
  33. {
  34. float2 uv : TEXCOORD0;
  35. float2 uv00 : TEXCOORD1;
  36. float2 uv10 : TEXCOORD2;
  37. float2 uv01 : TEXCOORD3;
  38. float2 uv11 : TEXCOORD4;
  39. float4 vertex : SV_POSITION;
  40. UNITY_VERTEX_OUTPUT_STEREO
  41. };
  42. v2f vert(appdata v)
  43. {
  44. v2f o;
  45. UNITY_SETUP_INSTANCE_ID(v);
  46. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  47. o.vertex = GetFullScreenTriangleVertexPosition(v.vertexID);
  48. o.uv = GetFullScreenTriangleTexCoord(v.vertexID);
  49. o.uv00 = o.uv - 0.5 * _CameraDepthTexture_TexelSize.xy; //v.uv
  50. o.uv10 = o.uv00 + float2(_CameraDepthTexture_TexelSize.x, 0.0);
  51. o.uv01 = o.uv00 + float2(0.0, _CameraDepthTexture_TexelSize.y);
  52. o.uv11 = o.uv00 + _CameraDepthTexture_TexelSize.xy;
  53. return o;
  54. }
  55. float frag(v2f i) : SV_Target
  56. {
  57. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
  58. uint2 positionSS = i.uv * _ScreenSize.xy;
  59. float4 depth;
  60. depth[0] = LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture,i.uv00 * _ScreenSize.xy,0);
  61. depth[1] = LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture,i.uv10 * _ScreenSize.xy,0);
  62. depth[2] = LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture,i.uv01 * _ScreenSize.xy,0);
  63. depth[3] = LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture,i.uv11 * _ScreenSize.xy,0);
  64. return max(depth[0], max(depth[1], max(depth[2], depth[3])));
  65. }
  66. ENDHLSL
  67. }
  68. //Pass 2 Copy
  69. Pass
  70. {
  71. Cull Off ZWrite Off ZTest Always
  72. HLSLPROGRAM
  73. #pragma vertex vert
  74. #pragma fragment frag
  75. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
  76. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  77. #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
  78. #include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl"
  79. #include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl"
  80. #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl"
  81. #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUtils.hlsl"
  82. struct appdata
  83. {
  84. uint vertexID : SV_VertexID;
  85. float2 uv : TEXCOORD0;
  86. UNITY_VERTEX_INPUT_INSTANCE_ID
  87. };
  88. struct v2f
  89. {
  90. float2 uv : TEXCOORD0;
  91. float4 vertex : SV_POSITION;
  92. UNITY_VERTEX_OUTPUT_STEREO
  93. };
  94. v2f vert(appdata v)
  95. {
  96. v2f o;
  97. UNITY_SETUP_INSTANCE_ID(v);
  98. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  99. o.vertex = GetFullScreenTriangleVertexPosition(v.vertexID);
  100. o.uv = GetFullScreenTriangleTexCoord(v.vertexID);
  101. return o;
  102. }
  103. float frag(v2f i) : SV_Target
  104. {
  105. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
  106. return LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture, i.uv * _ScreenSize.xy,0);
  107. }
  108. ENDHLSL
  109. }
  110. }
  111. }