AddSoft-Mult.shader 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
  2. Shader "Particles/Additive (Soft + Mult)" {
  3. Properties{
  4. _MainTex("Particle Texture", 2D) = "white" {}
  5. _InvFade("Soft Particles Factor", Range(0.01,3.0)) = 1.0
  6. _ColourMult("Colour Multiplier", Range(0.0,2.0)) = 1.0
  7. _AlphaMult("Alpha Multiplier", Range(0.0,2.0)) = 1.0
  8. }
  9. Category{
  10. Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane" }
  11. Blend One OneMinusSrcColor
  12. ColorMask RGB
  13. Cull Off Lighting Off ZWrite Off
  14. SubShader{
  15. Pass{
  16. CGPROGRAM
  17. #pragma vertex vert
  18. #pragma fragment frag
  19. #pragma target 2.0
  20. #pragma multi_compile_particles
  21. #pragma multi_compile_fog
  22. #include "UnityCG.cginc"
  23. sampler2D _MainTex;
  24. fixed4 _TintColor;
  25. struct appdata_t {
  26. float4 vertex : POSITION;
  27. fixed4 color : COLOR;
  28. float2 texcoord : TEXCOORD0;
  29. UNITY_VERTEX_INPUT_INSTANCE_ID
  30. };
  31. struct v2f {
  32. float4 vertex : SV_POSITION;
  33. fixed4 color : COLOR;
  34. float2 texcoord : TEXCOORD0;
  35. UNITY_FOG_COORDS(1)
  36. #ifdef SOFTPARTICLES_ON
  37. float4 projPos : TEXCOORD2;
  38. #endif
  39. UNITY_VERTEX_OUTPUT_STEREO
  40. };
  41. float4 _MainTex_ST;
  42. v2f vert(appdata_t v)
  43. {
  44. v2f o;
  45. UNITY_SETUP_INSTANCE_ID(v);
  46. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(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. UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
  58. float _InvFade;
  59. float _ColourMult;
  60. float _AlphaMult;
  61. fixed4 frag(v2f i) : SV_Target
  62. {
  63. #ifdef SOFTPARTICLES_ON
  64. float sceneZ = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
  65. float partZ = i.projPos.z;
  66. float fade = saturate(_InvFade * (sceneZ - partZ));
  67. i.color.a *= fade;
  68. #endif
  69. half4 col = i.color * tex2D(_MainTex, i.texcoord) * _ColourMult;
  70. col.rgb *= col.a * _AlphaMult;
  71. UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0,0,0,0)); // fog towards black due to our blend mode
  72. return col;
  73. }
  74. ENDCG
  75. }
  76. }
  77. }
  78. }