Lesson 10 of 10 · Shader patterns

Your pattern

Chladni, star, spiral, rings. All visible.

This lesson does not teach anything new. It brings together everything you learned in Patterns: stripes, fract, polar, spiral, mirror, radials, Chladni.

Your variables. Your frequencies. Your signature.

Look at the code. You already know every line:

  • → abs(p)   mirror (lesson 07)
  • → atan(p.y, p.x)   polar coordinates (lesson 05)
  • → 1. / (d + 0.12)   tunnel, 1/distance compresses to center (Start Here 10)
  • → sin(n * ang + inv * 8.)   Chladni in polar with tunnel (lesson 09 + 05)
  • → exp(-d * 2.0)   center glow, light emerges

This is your pattern. Make it yours.

TryChange 5. for more or fewer radials. Change 8. for more or fewer spiral twists. Change the colors. This pattern is yours now.
Freebie

AUTOPILOT

Replace the line col += vec3(.12,.08,.2) * chladni * (1.-star); with this:
col += iri(chladni * 0.4 + T * 0.05) * chladni * (1.-star);

The background breathes.

The code

void main(){
  vec2 p = (2.*gl_FragCoord.xy - R) / min(R.x, R.y);
  float ang = atan(p.y, p.x);
  float d = length(p);
  float z = sin(5.*3.14*p.x)*sin(3.*3.14*p.y)+sin(3.*3.14*p.x)*sin(5.*3.14*p.y);
  float chladni = pow(abs(z), 0.8);
  float r = 0.6 + 0.2 * sin(ang*5.+T*0.3);
  float star = smoothstep(0.02, -0.02, d-r);
  float spiral = step(0.5, sin(ang*3.+d*8.-T*0.5)*.5+.5);
  float rings = smoothstep(0.03,0.0, abs(fract(d*4.)-.5)-.3);
  vec3 col = vec3(0.02, 0.015, 0.04);
  col += vec3(.12,.08,.2) * chladni * (1.-star);
  col += vec3(.95,.3,.15) * star * spiral;
  col += vec3(0.,.85,.75) * star * (1.-spiral);
  col += vec3(.95,.8,.15) * rings * .3;
  col += vec3(.5,.15,.08) * exp(-abs(d-r)*4.) * .5;
  col += vec3(.8,.6,.95) * exp(-d*3.) * .4;
  gl_FragColor = vec4(col, 1.);
}