Advertisement
anthonytrianh

Circuit Function

Nov 22nd, 2020 (edited)
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. float remap(float s, float a1, float a2, float b1, float b2)
  2.         {
  3.             return b1 + (s - a1) * (b2 - b1) / (a2 - a1);
  4.         }
  5.  
  6. fixed4 circuit(fixed2 uv, sampler2D tex, fixed4 color, half delay, half speed, half range, half dir) {
  7.             //half pivot = frac(_Time.y / speed) * _MainTex_ST.x + delay;
  8.  
  9.             // Goes from 0 to 1 over 1/speed total duration
  10.             half pivot = frac((_Time.y - delay) / speed) * _MainTex_ST.x;
  11.  
  12.             fixed comp = (dir == 0) ? uv.x : uv.y;
  13.             fixed4 mask = tex2D(tex, uv) * color;
  14.  
  15.             fixed min = pivot - range;
  16.             fixed max = pivot + range;
  17.  
  18.             // Ramp color
  19.             fixed2 rampUV = fixed2(remap(comp, min, max, 0, 1), 0);
  20.             fixed4 rampColor = tex2D(_ColorRamp, rampUV * _ColorRamp_ST.xy);
  21.             mask *= rampColor.r;
  22.  
  23.             if (comp >= pivot - range && comp <= pivot + range)
  24.                 return mask;
  25.  
  26.             if (pivot + range > 1.0)
  27.                 if (comp >= pivot - range || comp <= pivot + range - 1.0)
  28.                     return mask;
  29.  
  30.             if (pivot - range < 0)
  31.                 if (comp >= pivot - range + 1.0 || comp <= pivot + range)
  32.                     return mask;
  33.  
  34.             return fixed4(0, 0, 0, 0);
  35.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement