Lesson 9 of 10 · Shader animation

Rhythm

The hexagon beats. Peak and rest. Heart, not metronome.

A sin() rises and falls evenly. A pulse has a strong peak then rest, like a heartbeat.

pow(x, 8.), everything crushes except the peak. Surgical pulse.

pow(sin(T) * 0.5 + 0.5, 8.), normalize the sine to 0-1, raise it to a high power. Values near 1 survive. Everything else gets crushed.

pow() as shaperpow(x, n) where x goes from 0 to 1: high powers (8., 16.) concentrate all energy in the peak. The trick for turning any wave into a rhythmic pulse.
TryChange 6. (power) to 2., soft pulse. To 20., ultra brief flash. Change T * 1.8 to T * 4. and the heart races.

The code

void main(){
  vec2 p = (2.*gl_FragCoord.xy - R) / min(R.x, R.y);
  float beat = pow(sin(T * 1.8) * 0.5 + 0.5, 6.);
  float r = 0.25 + beat * 0.15;
  vec2 ap = abs(p);
  float d = max(ap.x * 0.866 + ap.y * 0.5, ap.y) - r;
  float shape = smoothstep(0.02, -0.02, d);
  vec2 sp = abs(p + vec2(.05, -.08));
  float shadow = smoothstep(0.0, 0.25+beat*.15, max(sp.x*.866+sp.y*.5,sp.y)-r*1.1);
  float glow = exp(-max(d,0.)*(4.-beat*2.)) * 0.5;
  vec3 col = vec3(0.04, 0.02, 0.01) * shadow;
  col += vec3(0.95, 0.75, 0.2) * shape;
  col += vec3(0.9, 0.6, 0.1) * glow * (0.3 + beat * 0.7);
  col = hueShift(col, 0.0);
  gl_FragColor = vec4(col, 1.);
}