learn GLSL from zero
ToolsCreate with shadersShader MakerFree online shader builderToolkitShader works ready for your siteSketcher LabPaint your landing’s hero with shaders3D StudioThe Three.js editor in your browser
GamesPlay with shadersOnomatoShaderType a word, blow it upThe WatcherAn eye that follows youAetherLiquid glass with an eye insideBloomcoreA word grows a garden of lightPyrokineThrow fire at the wallVoltaicThe pyramid throws lightningSurfSurf a shader ocean

Lesson 3 of 10 · Noise in GLSL

Layers

More layers. More resolution.

A single layer of noise is flat. Stacking layers adds detail: the first gives the big shape, the second adds texture, the third adds grain. They are called octaves.

Bass, mids, treble. The signal has depth.

OctavesEach layer doubles the frequency and halves the amplitude. 3 layers look good.
TryPut // at the start of the b3 line to turn it off, only two layers left, less detail. Turn off b2 too by putting // in front, just the big shape. Change 6. (the b1 frequency) to 12. and the big shape tightens.

The code

void main(){
  vec2 p = (2.*gl_FragCoord.xy - R) / min(R.x, R.y);
  float b1 = step(0.5, sin(p.y*6.+n2(vec2(p.y*2.,1.))*3.)*.5+.5);
  float b2 = step(0.5, sin(p.y*12.+n2(vec2(p.y*4.,2.))*3.)*.5+.5);
  float b3 = step(0.5, sin(p.y*24.+n2(vec2(p.y*8.,3.))*3.)*.5+.5);
  float scan = step(0.5, sin(gl_FragCoord.y*1.5)*.5+.5)*.08;
  vec3 col = vec3(0.01, 0.02, 0.03);
  col += vec3(0.0, 0.4, 0.35) * b1;
  col += vec3(0.5, 0.0, 0.6) * b2 * 0.5;
  col += vec3(0.9, 0.0, 0.4) * b3 * 0.35;
  float peak = b1 * b2 * b3;
  col += vec3(0.9, 0.95, 1.0) * peak * 0.5;
  float edge = abs(b1 - b2) * abs(b2 - b3);
  col += vec3(0.0, 0.8, 0.6) * edge * 0.3;
  col *= 1.0 - scan;
  col += vec3(0.015, 0.01, 0.02);
  col = hueShift(col, 0.0);
  gl_FragColor = vec4(col, 1.);
}
close