DistortionBase.shader 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. Shader "YXJ/Particles/DistortionBase"
  2. {
  3. Properties
  4. {
  5. _TintColor("Tint Color",color) = (1,1,1,1)
  6. _MaskTex("Mask Tex (A)", 2D) = "white" {}
  7. _NoiseTex("Noise Texture (RG)", 2D) = "white" {}
  8. _HeatTime("Heat Time", range(0,1.5)) = 1
  9. _HeatForce("Heat Force", range(0,5)) = 0.1
  10. }
  11. SubShader
  12. {
  13. Tags{ "Queue" = "Transparent+100" "IgnoreProjector" = "True" "RenderType" = "Transparent" "LightMode" = "Grab_YXJ"}
  14. Cull Off Lighting Off ZWrite Off
  15. Pass
  16. {
  17. Blend SrcAlpha OneMinusSrcAlpha
  18. AlphaTest Greater .01
  19. HLSLPROGRAM
  20. #pragma vertex vert
  21. #pragma fragment frag
  22. #pragma fragmentoption ARB_precision_hint_fastest
  23. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  24. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  25. struct appdata_t
  26. {
  27. float4 vertex : POSITION;
  28. float4 color : COLOR;
  29. float2 texcoord: TEXCOORD0;
  30. };
  31. struct v2f
  32. {
  33. float4 vertex : POSITION;
  34. float4 color : COLOR;
  35. float2 uvMask : TEXCOORD0;
  36. float4 uvGrab : TEXCOORD1;
  37. };
  38. sampler2D _MaskTex; float4 _MaskTex_ST;
  39. sampler2D _NoiseTex; float4 _NoiseTex_ST;
  40. float4 _TintColor;
  41. half _HeatTime;
  42. half _HeatForce;
  43. SAMPLER(_CameraTransparentTexture);
  44. v2f vert (appdata_t v)
  45. {
  46. v2f o;
  47. VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
  48. o.vertex = vertexInput.positionCS;
  49. o.color = v.color;
  50. o.uvMask = TRANSFORM_TEX(v.texcoord, _MaskTex);
  51. #if UNITY_UV_STARTS_AT_TOP
  52. float scale = -1.0;
  53. #else
  54. float scale = 1.0;
  55. #endif
  56. o.uvGrab.xy = (float2(o.vertex.x, o.vertex.y * scale) + o.vertex.w) * 0.5;
  57. o.uvGrab.zw = o.vertex.zw;
  58. return o;
  59. }
  60. half4 frag( v2f i ) : SV_Target
  61. {
  62. //noise effect
  63. half4 offsetColor1 = tex2D(_NoiseTex, i.uvMask + _Time.xz * _HeatTime);
  64. half4 offsetColor2 = tex2D(_NoiseTex, i.uvMask - _Time.yx * _HeatTime);
  65. half distortX = ((offsetColor1.r + offsetColor2.r) - 1) * _HeatForce;
  66. half distorty = ((offsetColor1.g + offsetColor2.g) - 1) * _HeatForce;
  67. half2 screenUV = (i.vertex.xy / _ScreenParams.xy)+ float2(distortX, distorty);
  68. half4 grab = tex2D(_CameraTransparentTexture, screenUV);
  69. half4 mask = tex2D(_MaskTex, i.uvMask);
  70. half maskA = min(mask.r, mask.a);
  71. return _TintColor * i.color * half4(grab.rgb, maskA);
  72. }
  73. ENDHLSL
  74. }
  75. }
  76. SubShader
  77. {
  78. Blend DstColor One
  79. Pass
  80. {
  81. Name "BASE"
  82. SetTexture[_MaskTex]
  83. {
  84. constantColor (0,0,0,0)
  85. combine texture * constant
  86. }
  87. }
  88. }
  89. }