LightCone.shader 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "FX/LightCone" {
  3. Properties{
  4. _TintColor("Tint Color", Color) = (0.5,0.5,0.5,0.5)
  5. _InvFade("Soft Particles Factor", Range(0.01,3.0)) = 1.0
  6. _Rim ("rim power", Range(0,10)) = 1.0
  7. }
  8. Category{
  9. Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
  10. Blend SrcAlpha One
  11. ColorMask RGB
  12. Cull Off Lighting Off ZWrite Off Fog{ Color(0,0,0,0) }
  13. ZTest Off
  14. SubShader{
  15. Pass{
  16. CGPROGRAM
  17. #pragma vertex vert
  18. #pragma fragment frag
  19. #pragma multi_compile_particles
  20. #if UNITY_VERSION >= 201810
  21. #pragma multi_compile_instancing
  22. #endif
  23. #include "UnityCG.cginc"
  24. sampler2D _MainTex;
  25. fixed4 _TintColor;
  26. uniform fixed _BWEffectOn;
  27. float _InvFade;
  28. half _Rim;
  29. struct appdata_t {
  30. float4 vertex : POSITION;
  31. float3 normal : NORMAL;
  32. fixed4 color : COLOR;
  33. fixed4 viewDir : TEXCOORD0;
  34. #if UNITY_VERSION >= 201810
  35. UNITY_VERTEX_INPUT_INSTANCE_ID
  36. #endif
  37. };
  38. struct v2f {
  39. float4 vertex : SV_POSITION;
  40. fixed4 color : COLOR;
  41. #ifdef SOFTPARTICLES_ON
  42. float4 projPos : TEXCOORD0;
  43. #endif
  44. float3 normal : NORMAL;
  45. float3 viewDir : TEXCOORD1;
  46. #if UNITY_VERSION >= 201810
  47. UNITY_VERTEX_OUTPUT_STEREO //Insert
  48. #endif
  49. };
  50. #if UNITY_VERSION >= 201810
  51. v2f vert(appdata_t v)
  52. {
  53. v2f o;
  54. UNITY_SETUP_INSTANCE_ID(v); //Insert
  55. UNITY_INITIALIZE_OUTPUT(v2f, o); //Insert
  56. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); //Insert
  57. o.vertex = UnityObjectToClipPos(v.vertex);
  58. #ifdef SOFTPARTICLES_ON
  59. o.projPos = ComputeScreenPos(o.vertex);
  60. COMPUTE_EYEDEPTH(o.projPos.z);
  61. #endif
  62. o.color = v.color;
  63. o.normal = v.normal;
  64. o.viewDir = normalize(ObjSpaceViewDir(v.vertex));
  65. return o;
  66. }
  67. UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
  68. fixed4 frag(v2f i) : SV_Target
  69. {
  70. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); //Insert
  71. #ifdef SOFTPARTICLES_ON
  72. float sceneZ = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
  73. float partZ = i.projPos.z;
  74. float fade = 1 - saturate(_InvFade * (partZ - sceneZ));
  75. i.color.a *= fade;
  76. #endif
  77. i.color = pow(i.color,3);
  78. half rim = saturate(pow(saturate(abs(dot(i.viewDir, i.normal))),_Rim));
  79. i.color.a *= rim;
  80. fixed4 finalCol = 2.0f * i.color * _TintColor;
  81. fixed lum = Luminance(finalCol.xyz);
  82. return finalCol;
  83. }
  84. #else
  85. sampler2D_float _CameraDepthTexture;
  86. v2f vert(appdata_t v)
  87. {
  88. v2f o;
  89. o.vertex = UnityObjectToClipPos(v.vertex);
  90. #ifdef SOFTPARTICLES_ON
  91. o.projPos = ComputeScreenPos(o.vertex);
  92. COMPUTE_EYEDEPTH(o.projPos.z);
  93. #endif
  94. o.color = v.color;
  95. o.normal = v.normal;
  96. o.viewDir = normalize(ObjSpaceViewDir(v.vertex));
  97. return o;
  98. }
  99. fixed4 frag(v2f i) : SV_Target
  100. {
  101. #ifdef SOFTPARTICLES_ON
  102. float sceneZ = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
  103. float partZ = i.projPos.z;
  104. float fade = 1 - saturate(_InvFade * (partZ - sceneZ));
  105. i.color.a *= fade;
  106. #endif
  107. i.color = pow(i.color,3);
  108. half rim = saturate(pow(saturate(abs(dot(i.viewDir, i.normal))),_Rim));
  109. i.color.a *= rim;
  110. fixed4 finalCol = 2.0f * i.color * _TintColor;
  111. fixed lum = Luminance(finalCol.xyz);
  112. return finalCol;
  113. }
  114. #endif
  115. ENDCG
  116. }
  117. }
  118. }
  119. }