Classic Perlin Noise

This is based on the classic variant (not the periodic).

Ported from: https://github.com/ashima/webgl-noise/blob/master/src/classicnoise2D.glsl

Demo

▶ Click to play

The noise function is imported, but we then need to set up a proxy function. This is because the macro system relies on inlining, and we want to create a function definition, not just inline the noise code at the point of use.

inline def fragment =
  Shader[FragmentEnv] { env =>
    import ultraviolet.noise.*

    def proxy: vec2 => Float =
      p => perlin(p)

    def fragment(color: vec4): vec4 =
      vec4(vec3(proxy(env.UV * 8.0f)), 1.0f)
  }