NoFog-Alpha.shader 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. Shader "Mirza Beig/Particles/No Fog/Alpha Blended"
  2. {
  3. Properties
  4. {
  5. _TintColor("Tint Color", Color) = (0.5, 0.5, 0.5, 0.5)
  6. _MainTex("Particle Texture", 2D) = "white" {}
  7. _InvFade("Soft Particles Factor", Range(0.01, 8.0)) = 1.0
  8. }
  9. Category
  10. {
  11. Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
  12. Blend SrcAlpha OneMinusSrcAlpha
  13. ColorMask RGB
  14. Cull Off Lighting Off ZWrite Off
  15. SubShader
  16. {
  17. Pass
  18. {
  19. CGPROGRAM
  20. #pragma vertex vert
  21. #pragma fragment frag
  22. #pragma multi_compile_particles
  23. #pragma multi_compile_fog
  24. #include "UnityCG.cginc"
  25. sampler2D _MainTex;
  26. fixed4 _TintColor;
  27. struct appdata_t
  28. {
  29. float4 vertex : POSITION;
  30. fixed4 color : COLOR;
  31. float2 texcoord : TEXCOORD0;
  32. };
  33. struct v2f
  34. {
  35. float4 vertex : SV_POSITION;
  36. fixed4 color : COLOR;
  37. float2 texcoord : TEXCOORD0;
  38. #ifdef SOFTPARTICLES_ON
  39. float4 projPos : TEXCOORD1;
  40. #endif
  41. UNITY_FOG_COORDS(2)
  42. };
  43. float4 _MainTex_ST;
  44. v2f vert(appdata_t v)
  45. {
  46. v2f o;
  47. o.vertex = UnityObjectToClipPos(v.vertex);
  48. #ifdef SOFTPARTICLES_ON
  49. o.projPos = ComputeScreenPos(o.vertex);
  50. COMPUTE_EYEDEPTH(o.projPos.z);
  51. #endif
  52. o.color = v.color;
  53. o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
  54. UNITY_TRANSFER_FOG(o, o.vertex);
  55. return o;
  56. }
  57. sampler2D_float _CameraDepthTexture;
  58. float _InvFade;
  59. // ...
  60. fixed4 frag(v2f i) : SV_Target
  61. {
  62. // Get texture colour.
  63. float4 texColour = tex2D(_MainTex, i.texcoord);
  64. // Tint.
  65. fixed4 colour = _TintColor * texColour;
  66. #ifdef SOFTPARTICLES_ON
  67. // Scene depth.
  68. //float sceneZ = LinearEyeDepth(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)).r);
  69. float sceneZ = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
  70. // Distance to the camera.
  71. float partZ = i.projPos.z;
  72. // Soft particles (soft factor).
  73. // "Comparing depth values of the particle with depth values of world geometry (in view space)." - Special Effects with Depth (Siggraph, 2011).
  74. // float softFactor = saturate((depthEye - zEye) * fade)
  75. // Inverse fade: 0.0f = off.
  76. float fade = saturate(_InvFade * (sceneZ - partZ));
  77. colour.a *= fade;
  78. #endif
  79. // Input colour.
  80. colour *= i.color * 2.0f;
  81. // Fog towards nothing.
  82. //UNITY_APPLY_FOG(i.fogCoord, colour);
  83. return colour;
  84. }
  85. ENDCG
  86. }
  87. }
  88. }
  89. }