DeferredFog.shader 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. Shader "Hidden/PostProcessing/DeferredFog"
  2. {
  3. HLSLINCLUDE
  4. #pragma multi_compile __ FOG_LINEAR FOG_EXP FOG_EXP2
  5. #include "../StdLib.hlsl"
  6. #include "Fog.hlsl"
  7. TEXTURE2D_SAMPLER2D(_MainTex, sampler_MainTex);
  8. TEXTURE2D_SAMPLER2D(_CameraDepthTexture, sampler_CameraDepthTexture);
  9. #define SKYBOX_THREASHOLD_VALUE 0.9999
  10. float4 Frag(VaryingsDefault i) : SV_Target
  11. {
  12. half4 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoordStereo);
  13. float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoordStereo);
  14. depth = Linear01Depth(depth);
  15. float dist = ComputeFogDistance(depth);
  16. half fog = 1.0 - ComputeFog(dist);
  17. return lerp(color, _FogColor, fog);
  18. }
  19. float4 FragExcludeSkybox(VaryingsDefault i) : SV_Target
  20. {
  21. half4 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoordStereo);
  22. float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoordStereo);
  23. depth = Linear01Depth(depth);
  24. float skybox = depth < SKYBOX_THREASHOLD_VALUE;
  25. float dist = ComputeFogDistance(depth);
  26. half fog = 1.0 - ComputeFog(dist);
  27. return lerp(color, _FogColor, fog * skybox);
  28. }
  29. ENDHLSL
  30. SubShader
  31. {
  32. Cull Off ZWrite Off ZTest Always
  33. Pass
  34. {
  35. HLSLPROGRAM
  36. #pragma vertex VertDefault
  37. #pragma fragment Frag
  38. ENDHLSL
  39. }
  40. Pass
  41. {
  42. HLSLPROGRAM
  43. #pragma vertex VertDefault
  44. #pragma fragment FragExcludeSkybox
  45. ENDHLSL
  46. }
  47. }
  48. }