PrepareSunShaftsBlur.shader 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Hidden/PrepareSunShaftsBlur" {
  3. Properties {
  4. _MainTex ("Base", 2D) = "" {}
  5. _Skybox ("Skybox", 2D) = "" {}
  6. }
  7. CGINCLUDE
  8. #include "UnityCG.cginc"
  9. struct v2f {
  10. float4 pos : SV_POSITION;
  11. float2 uv : TEXCOORD0;
  12. };
  13. sampler2D _MainTex;
  14. sampler2D _Skybox;
  15. sampler2D_float _CameraDepthTexture;
  16. uniform half _NoSkyBoxMask;
  17. uniform half4 _SunPosition;
  18. v2f vert (appdata_img v) {
  19. v2f o;
  20. o.pos = UnityObjectToClipPos(v.vertex);
  21. o.uv = v.texcoord.xy;
  22. return o;
  23. }
  24. half TransformColor (half4 skyboxValue) {
  25. return max (skyboxValue.a, _NoSkyBoxMask * dot (skyboxValue.rgb, float3 (0.59,0.3,0.11)));
  26. }
  27. half4 frag (v2f i) : SV_Target {
  28. float depthSample = SAMPLE_DEPTH_TEXTURE( _CameraDepthTexture, i.uv.xy);
  29. half4 tex = tex2D (_MainTex, i.uv.xy);
  30. depthSample = Linear01Depth (depthSample);
  31. // consider maximum radius
  32. half2 vec = _SunPosition.xy - i.uv.xy;
  33. half dist = saturate (_SunPosition.w - length (vec.xy));
  34. half4 outColor = 0;
  35. // consider shafts blockers
  36. if (depthSample > 0.99)
  37. outColor = TransformColor (tex) * dist;
  38. return outColor;
  39. }
  40. half4 fragNoDepthNeeded (v2f i) : SV_Target {
  41. float4 sky = (tex2D (_Skybox, i.uv.xy));
  42. float4 tex = (tex2D (_MainTex, i.uv.xy));
  43. // consider maximum radius
  44. half2 vec = _SunPosition.xy - i.uv.xy;
  45. half dist = saturate (_SunPosition.w - length (vec));
  46. half4 outColor = 0;
  47. if (Luminance ( abs(sky.rgb - tex.rgb)) < 0.2)
  48. outColor = TransformColor (sky) * dist;
  49. return outColor;
  50. }
  51. ENDCG
  52. Subshader {
  53. Pass {
  54. ZTest Always Cull Off ZWrite Off
  55. CGPROGRAM
  56. #pragma vertex vert
  57. #pragma fragment frag
  58. ENDCG
  59. }
  60. Pass {
  61. ZTest Always Cull Off ZWrite Off
  62. CGPROGRAM
  63. #pragma vertex vert
  64. #pragma fragment fragNoDepthNeeded
  65. ENDCG
  66. }
  67. }
  68. Fallback off
  69. } // shader