Shader Learn

04 Textures and noise

Textures: look up a colour by address

Give a UV, get a colour from the texture.

0.55
-11

Runs once per pixelDrag numbers, or edit the code

JS sidegl.bindTexture(gl.TEXTURE_2D, texture) gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT) gl.uniform1i(uTextureLocation, 0) // texture unit 0

A sampler2D points to an image; texture2D(tex, uv) looks up a colour at a UV. What happens outside 0–1 is set from JS.

Try it

  • Set the scale to 3: the pattern repeats
  • In the code, replace uv with uv * uv and watch the pattern bend