Skip to content

Basic Examples

Articdive edited this page Sep 13, 2022 · 5 revisions

Perlin Noise

JNoise.newBuilder().perlin(1077, Interpolation.LINEAR, FadeFunction.IMPROVED_PERLIN_NOISE)
    .scale(1 / 16.0)
    .addModifier(v -> (v + 1) / 2.0)
    .clamp(0.0, 1.0)
    .build();

TO NOTE:

  • Use a scale to make the coordinates be non-integers, integer coordinates ALWAYS have the output value 0.0 (This is expected for Perlin Noise).
  • Then use a custom modifier to shift the interval [-1, 1] to [0, 1] (This is the v -> (v + 1) / 2.0 ).
  • Then clamp between 0.0 and 1.0 just to be sure, since Perlin Noise actually has a more complicated interval (It's not exactly [-1, 1]).

Value Noise

JNoise.newBuilder().value(1077, Interpolation.CUBIC, FadeFunction.NONE)
    .scale(1 / 16.0)
    .addModifier(v -> (v + 1) / 2.0)
    .build();

TO NOTE:

  • The scale is basically the zoom, zooming out (scale > 1) can allow you to achieve better gradients.
  • Custom modifier to shift the interval [-1, 1] to [0, 1].

White Noise

JNoise.newBuilder().white(1077)
    .scale(1 / 16.0)
    .addModifier(v -> (v + 1) / 2.0)
    .build();

TO NOTE:

  • If it looks similar to value noise, that's because it is value noise without interpolation and fading.
  • If you want to achieve static noise (What most people believe is white noise from a TV), then you can use a custom modifier to round up, e.g. x < 0.5 --> 0.0 && x >= 0.5 --> 1.0.

FastSimplex Noise

JNoise.newBuilder().fastSimplex(FastSimplexNoiseGenerator.newBuilder().setSeed(1077).build())
    .scale(1 / 16.0)
    .addModifier(v -> (v + 1) / 2.0)
    .build();

TO NOTE:

  • Exactly the same for SuperSimplex (Noise quality difference!).

Worley Noise

JNoise.newBuilder().worley(WorleyNoiseGenerator.newBuilder().setSeed(1077).build())
    .scale(1 / 16.0)
    .clamp(0.0, 1.0)
    .build();

TO NOTE:

  • Output is in the interval [0, Double.MAX_VALUE) (Depends on the configuration, default is [0, 1.5]).
  • If you see black spots inside of white sections, this is a sign of the output value not being clamped!
Clone this wiki locally