The Code Therapy

VHS Opening shader

A shader that depicts the opening of a vhs tape (Can reverse time to give closing effect)

Created by mgshadermaster on Fri, 02 Aug 2024 19:38:38 GMT.


#version 300 es
precision highp float;

uniform vec2 resolution;
uniform float time;
out vec4 fragColor;

const float TAN30 = 1.0 / sqrt(3.0);

float p(float t) {
    return t * t * t;
}

vec3 hue(vec3 col, float a) {
  const vec3 k = vec3(TAN30);
  float c = cos(a);
  return col * c + cross(k, col) * sin(a) + k * dot(k, col) * (1.0 - c);
}

void main(void) {
  vec2 uv = (gl_FragCoord.xy / resolution.xy) * 2.0 - 1.0;
  uv.x *= resolution.x / resolution.y;
  uv.y += sin((uv.x + sin(time * 100.0)) * 100.0) / 1500.0;
  float t = p(mod(time * 2.0, 2.0) - 0.9);
  float c = length(uv.y) - t;
  c = clamp(c, 0.0, 1.0);
  c = 0.02 / c;
  c = clamp(c, 0.0, 1.0);

  fragColor = vec4(vec3(c) * vec3(0.4, 0.0, 0.7), 1.0);
}