MultiScaleVO.shader 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. Shader "Hidden/PostProcessing/MultiScaleVO"
  2. {
  3. HLSLINCLUDE
  4. #pragma exclude_renderers gles gles3 d3d11_9x
  5. #pragma target 4.5
  6. #include "../StdLib.hlsl"
  7. #include "Fog.hlsl"
  8. TEXTURE2D_SAMPLER2D(_CameraDepthTexture, sampler_CameraDepthTexture);
  9. TEXTURE2D_SAMPLER2D(_MSVOcclusionTexture, sampler_MSVOcclusionTexture);
  10. float3 _AOColor;
  11. ENDHLSL
  12. SubShader
  13. {
  14. Cull Off ZWrite Off ZTest Always
  15. // 0 - Depth copy with procedural draw
  16. Pass
  17. {
  18. HLSLPROGRAM
  19. #pragma vertex VertDefault
  20. #pragma fragment Frag
  21. float4 Frag(VaryingsDefault i) : SV_Target
  22. {
  23. return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoordStereo);
  24. }
  25. ENDHLSL
  26. }
  27. // 1 - Composite to G-buffer with procedural draw
  28. Pass
  29. {
  30. Blend Zero OneMinusSrcColor, Zero OneMinusSrcAlpha
  31. HLSLPROGRAM
  32. #pragma vertex VertDefault
  33. #pragma fragment Frag
  34. struct Output
  35. {
  36. float4 gbuffer0 : SV_Target0;
  37. float4 gbuffer3 : SV_Target1;
  38. };
  39. Output Frag(VaryingsDefault i)
  40. {
  41. float ao = 1.0 - SAMPLE_TEXTURE2D(_MSVOcclusionTexture, sampler_MSVOcclusionTexture, i.texcoordStereo).r;
  42. Output o;
  43. o.gbuffer0 = float4(0.0, 0.0, 0.0, ao);
  44. o.gbuffer3 = float4(ao * _AOColor, 0.0);
  45. return o;
  46. }
  47. ENDHLSL
  48. }
  49. // 2 - Composite to the frame buffer
  50. Pass
  51. {
  52. Blend Zero OneMinusSrcColor, Zero OneMinusSrcAlpha
  53. HLSLPROGRAM
  54. #pragma multi_compile _ APPLY_FORWARD_FOG
  55. #pragma multi_compile _ FOG_LINEAR FOG_EXP FOG_EXP2
  56. #pragma vertex VertDefault
  57. #pragma fragment Frag
  58. float4 Frag(VaryingsDefault i) : SV_Target
  59. {
  60. half ao = 1.0 - SAMPLE_TEXTURE2D(_MSVOcclusionTexture, sampler_MSVOcclusionTexture, i.texcoordStereo).r;
  61. // Apply fog when enabled (forward-only)
  62. #if (APPLY_FORWARD_FOG)
  63. float d = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoordStereo));
  64. d = ComputeFogDistance(d);
  65. ao *= ComputeFog(d);
  66. #endif
  67. return float4(ao * _AOColor, 0.0);
  68. }
  69. ENDHLSL
  70. }
  71. // 3 - Debug overlay
  72. Pass
  73. {
  74. HLSLPROGRAM
  75. #pragma vertex VertDefault
  76. #pragma fragment Frag
  77. float4 Frag(VaryingsDefault i) : SV_Target
  78. {
  79. half ao = SAMPLE_TEXTURE2D(_MSVOcclusionTexture, sampler_MSVOcclusionTexture, i.texcoordStereo).r;
  80. return float4(ao.rrr, 1.0);
  81. }
  82. ENDHLSL
  83. }
  84. }
  85. }