AVProMovieCapture_Plasma.shader 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. Shader "Hidden/AVProMovieCapture/Plasma"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Texture", 2D) = "white" {}
  6. }
  7. SubShader
  8. {
  9. Tags { "RenderType"="Opaque" }
  10. LOD 100
  11. Pass
  12. {
  13. CGPROGRAM
  14. #pragma vertex vert
  15. #pragma fragment frag
  16. // #pragma exclude_renderers gles
  17. #pragma target 2.5
  18. #include "UnityCG.cginc"
  19. struct appdata
  20. {
  21. float4 vertex : POSITION;
  22. float2 uv : TEXCOORD0;
  23. };
  24. struct v2f
  25. {
  26. float2 uv : TEXCOORD0;
  27. float4 vertex : SV_POSITION;
  28. };
  29. sampler2D _MainTex;
  30. float4 _MainTex_ST;
  31. //dave hoskins hash
  32. float2 hash(float2 p)
  33. {
  34. float3 HASHSCALE3 = float3(0.1031, 0.1030, 0.0973);
  35. float3 p3 = frac(float3(p.xyx) * HASHSCALE3);
  36. p3 += dot(p3, p3.yzx + 19.19);
  37. return frac((p3.xx+p3.yz)*p3.zy);
  38. }
  39. float voronoi(float2 p, float gap)
  40. {
  41. p *= 1.0 / gap;
  42. float2 n = floor(p);
  43. float2 f = frac(p);
  44. float min_dist = 99999.0;
  45. for (int j = -1; j <= 1; j++)
  46. for (int i = -1; i <= 1; i++)
  47. {
  48. float2 pos = float2(float(i), float(j));
  49. float2 jitter = (hash(n + pos) - 0.5) * 2.0;
  50. jitter = 0.5 + sin(_Time.y + 6.2831 * jitter) * 0.5;
  51. float2 r = pos + jitter - f;
  52. float d = length(r);
  53. if (d < min_dist)
  54. {
  55. min_dist = d;
  56. }
  57. }
  58. return pow(min_dist, 3.0) * gap * 10;
  59. }
  60. float3 tonemap(float3 color)
  61. {
  62. color = max(float3(0, 0, 0), color - float3(0.004, 0.004, 0.004));
  63. color = (color * (6.2 * color + .5)) / (color * (6.2 * color + 1.7) + 0.06);
  64. return color;
  65. }
  66. float plasma(float2 p)
  67. {
  68. float gap = 0.5;
  69. float norm_factor = 0.0;
  70. float total_val = 0.0;
  71. [unroll(8)]
  72. for (int i = 0; i < 8; ++i)
  73. {
  74. total_val += voronoi(p, gap) / 16.0;
  75. norm_factor += gap;
  76. gap /= 2.0;
  77. }
  78. return total_val / norm_factor;
  79. }
  80. v2f vert (appdata v)
  81. {
  82. v2f o;
  83. o.vertex = UnityObjectToClipPos(v.vertex);
  84. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  85. return o;
  86. }
  87. fixed4 frag (v2f i) : SV_Target
  88. {
  89. i.uv += float2(0, -_Time.y * 0.1);
  90. float r = abs(frac(i.uv.y) - 0.5) * 2.0;
  91. float b = 1 - r;
  92. float g = 1.0 - 2 * abs(i.uv.x - 0.5);
  93. fixed4 col = fixed4(r, g, b, 1) * plasma(i.uv);
  94. col.rgb = tonemap(col.rgb);
  95. col.a = 1;
  96. return col;
  97. }
  98. ENDCG
  99. }
  100. }
  101. Fallback Off
  102. }