You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.1 KiB

5 years ago
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Fog Volume/Shadow Projector"
  3. {
  4. Properties
  5. {
  6. [NoScaleOffset]_MainTex("ShadowMap", 2D) = "white" {}
  7. displacePower("light Displace intensity", range(.01,.3)) = 0.079
  8. _ShadowColor("ShadowColor", Color)=(0,0,0,0)
  9. _Cutoff("Alpha cutoff", Range(0,1)) = 0.01//TODO: Publish
  10. }
  11. SubShader
  12. { Tags{
  13. "Queue" = "AlphaTest"
  14. "IgnoreProjector" = "True"
  15. "RenderType" = "NeverRenderMe"
  16. }
  17. Pass
  18. {
  19. Fog{ Mode Off }
  20. Blend DstColor OneMinusSrcAlpha
  21. Cull front
  22. ZWrite Off
  23. ZTest Always
  24. Lighting Off
  25. CGPROGRAM
  26. #pragma target 3.0
  27. #pragma vertex vert
  28. #pragma fragment frag
  29. #include "UnityCG.cginc"
  30. struct v2f
  31. {
  32. float4 pos : SV_POSITION;
  33. half2 uv : TEXCOORD0;
  34. float4 screenUV : TEXCOORD1;
  35. float3 ray : TEXCOORD2;
  36. half3 orientation : TEXCOORD3;
  37. };
  38. v2f vert(float3 v : POSITION)
  39. {
  40. v2f o;
  41. o.pos = UnityObjectToClipPos(float4(v,1));
  42. o.uv = v.xz + 0.5;
  43. o.screenUV = ComputeScreenPos(o.pos);
  44. //o.ray = mul(UNITY_MATRIX_MV, float4(v,1)).xyz * float3(-1,-1,1);
  45. //5.6:
  46. o.ray = UnityObjectToViewPos(float4(v, 1) ).xyz* float3(-1, -1, 1);
  47. o.orientation = mul((float3x3)unity_ObjectToWorld, float3(0,1,0));
  48. return o;
  49. }
  50. uniform float3 L;
  51. sampler2D _MainTex, RT_OpacityBlur;
  52. sampler2D_float _CameraDepthTexture;
  53. half displacePower;
  54. half _Cutoff;
  55. half4 _ShadowColor;
  56. fixed4 frag(v2f i) : COLOR0
  57. {
  58. i.ray = i.ray * (_ProjectionParams.z / i.ray.z);
  59. float2 uv = i.screenUV.xy / i.screenUV.w;
  60. // read depth and reconstruct world position
  61. float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv);
  62. depth = Linear01Depth(depth);
  63. float4 vpos = float4(i.ray * depth,1);
  64. float3 wpos = mul(unity_CameraToWorld, vpos).xyz;
  65. float3 opos = mul(unity_WorldToObject, float4(wpos,1)).xyz;
  66. clip(float3(0.5,0.5,0.5) - abs(opos.xyz));
  67. i.uv = opos.xz + 0.5;
  68. i.uv = i.uv + displacePower*L.xz;
  69. fixed4 col = tex2D(RT_OpacityBlur, i.uv).r;
  70. clip(col.a - _Cutoff);
  71. col.rgb = _ShadowColor*( col.a);
  72. //return float4(0,0,0,1);
  73. return float4(col.rgb, col.a);
  74. }
  75. ENDCG
  76. }
  77. }
  78. Fallback Off
  79. }