Gradient Noise

Ported from: https://www.iquilezles.org/www/articles/gradientnoise/gradientnoise.htm

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 => vec3 =
      p => gradient(p)

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