Giter VIP home page Giter VIP logo

noise's Introduction

Noise

GitHub Workflow Status (branch) MIT License Maven Central Sonatype Nexus (Snapshots)

Noise generation library for Java, based on the libnoise C++ library by Jason Bevins. It is used to generate coherent noise, a type of smoothly-changing noise. It can also generate Perlin noise, ridged multifractal noise, and other types of coherent noise.

Prerequisites

  • Java 8

Building from Source

In order to build math you simply need to run the ./gradlew build command. You can find the compiled JAR file in ./build/libs labeled similarly to 'noise-x.x.x-SNAPSHOT.jar'.

Contributing

Are you a talented programmer looking to contribute some code? We'd love the help!

  • Open a pull request with your changes, following our guidelines.

Usage

Noise publishes releases on Maven Central and Sponge's own repository. Snapshots are published on Sonatype OSSRH and Sponge's repository.

If you're using Gradle to manage project dependencies, simply include the following in your build.gradle file:

repositories {
  // releases
  mavenCentral()
  // snapshots
  maven {
    url "https://repo.spongepowered.org/repository/maven-public/"
  }
}

dependencies {
  implementation "org.spongepowered:noise:2.0.0-SNAPSHOT"
}

If you're using Maven to manage project dependencies, simply include the following in your pom.xml file:

<dependency>
  <groupId>org.spongepowered</groupId>
  <artifactId>noise</artifactId>
  <version>2.0.0-SNAPSHOT</version>
</dependency>

Credits

  • Jason Bevins and contributors of the original libnoise C++ library.
  • Spout and contributors - where we all began, and for much of the re-licensed code.
  • All the people behind Java, Maven, and Gradle.

noise's People

Contributors

afforess avatar barteks2x avatar ddos avatar dlobi avatar kdotjpg avatar lukespragg avatar netzwergx avatar razaekel avatar renovate-bot avatar renovate[bot] avatar royawesome avatar sleepyswords avatar zml2008 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

noise's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): Update patch dependency changes to v5.10.3 (org.junit.jupiter:junit-jupiter-engine, org.junit.jupiter:junit-jupiter-api)
  • chore(deps): Update dependency net.ltgt.errorprone to v4

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/check-spotless.yaml
.github/workflows/ci.yaml
.github/workflows/codeql-analysis.yaml
gradle
gradle.properties
settings.gradle
  • org.gradle.toolchains.foojay-resolver-convention 0.8.0
build.gradle
doclet-extras/build.gradle
gradle/libs.versions.toml
  • com.google.errorprone:error_prone_core 2.27.1
  • com.google.errorprone:error_prone_annotations 2.27.1
  • org.junit.jupiter:junit-jupiter-api 5.10.2
  • org.junit.jupiter:junit-jupiter-engine 5.10.2
  • net.ltgt.errorprone 3.1.0
  • net.kyori.indra 3.1.3
  • net.kyori.indra.crossdoc 3.1.3
  • net.kyori.indra.publishing.sonatype 3.1.3
  • org.spongepowered.gradle.sponge.dev 2.2.0
  • com.diffplug.spotless 6.25.0
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 8.7

  • Check this box to trigger a request for Renovate to run again on this repository

Detach fork relationship from jlibnoise

With PR #5, flow noise will look less and less similar its parent, jlibnoise. The only similarity would be several commits early in history, meaning that the "forked from" label is not really necessary. The last commit to jlibnoise was in August 2013, meaning that flow noise has become its spritual successor, and its own project.

Removing the "fork" relationship to jlibnoise allows a few other perks, like searching code.

This can be done, as explained by Github:

To detach the fork and turn it into a standalone repository on GitHub, contact GitHub support.

Version number

Hey. Thanks for working on the library still and publishing new changes. That's greatly appreciated.

But wtf were you thinking pushing breaking changes to the repository under the same version number? It just broke our whole world generation project. We can't even revert to an older version because of this.

Please use the version number what it's intended for and bump it on uploads. Thanks!

divide by zero error

In modifiers/Curve.getValue(), there's a divide by zero error:

    // Compute the alpha value used for cubic interpolation.
    double input0 = controlPoints.get(indexPos).inputValue;
    double input1 = controlPoints.get(indexPos).inputValue;
    double alpha = (sourceModuleValue - input0) / (input1 - input0);

Because input0 = input1 since they're getting the same indexPos, input1 - input0 = 0, thus the divide by zero error.

It needs to be replaced with the following:

    // Compute the alpha value used for cubic interpolation.
    double input0 = controlPoints.get(index1).inputValue;
    double input1 = controlPoints.get(index2).inputValue;
    double alpha = (sourceModuleValue - input0) / (input1 - input0);

Why value range 0-1?

Why flow noise has value range 0-1? Why not leave it as -1 to 1?

This value range is very counterintuitive when using it for terrain generation, and annoying to work with, where the average value specifies average terrain height (especially when used as 3d noise):

  • Scaling the noise generator output changes average value
  • Changing almost any parameters when using multiple octaves (except frequency) changes average value

With value range 0-1, there is a very simple way to make 3d noise based terrain generator: multiply the noise output by desired height variation, add average height, and use the output as "heightmap" that also depends on height.

The only situation I see where values 0 to 1 are simpler is when outputting to image, which is done only sometimes for testing. And when using noise output for interpolation, where it can be easily changed into 0-1 range.

Perlin noise value range isn't actually 0 to 1

Well, technically it is. But technically it's also between -infinity and +infinity. After testing with 64 million samples (not random, some predefined area) I got min=0.30759661550127604, max=0.692403384498724. It seems safe to say that the actual value range that happens in practice is 0.3 to 0.7. When eriting terrain generator using it with the assumption that the value range will be 0 to 1, the terrain will never reach values even halfway through to the intended max height and depth.

I also did an experiment replacing the RANDOM_VECTORS array (I currently use that "hack" in my code) with the values Minecarft uses internally - which is all possibilities with 2 coordinates being +/-1 and one coordinate being zero - prescaled down by 0.5 to make halve the value range so that after adding 0.5 - the resulting range is 0-1. After testing with the same 64 million samples, I got the exact value range of 0 to 1. Not 0.00000001 to 0.999999999, exactly 0.0 to 1.0. There are actually 12 such vectors, so I choose them randomly to fill the whole array.

And some images (this is the frequency I used for sampling, just 8k by 8k image, pixel color intensity is clamp(floor(value * 256), 0, 1):
Current values:
bad
"fixed" values:
good

Unfortunately, fixing this will break compatibility with existing code, so maybe another option would be updating documentation to say that?

getMaxValue returns NaN on Perlin module

[20:36:56] [Sponge-AsyncScheduler-0/INFO] [rustmesponge]: Initializing ProceduralGenerator with following settings: 
[20:36:56] [Sponge-AsyncScheduler-0/INFO] [rustmesponge]: Frequency: 0.00390625, OctaveCount: 5, Persistence: 1.0, Seed: 123
[20:36:56] [Sponge-AsyncScheduler-0/INFO] [rustmesponge]: Initializing height map task from (-100, 0, -100) to (100, 255, 100)
[20:36:56] [Sponge-AsyncScheduler-0/WARN] [rustmesponge]: Max Value: NaN
[20:36:56] [Sponge-AsyncScheduler-0/INFO] [rustmesponge]: Found height: 310.84143196993296. Noise: 2.428448687265101

This is how I initialize Perlin module:

        var perlinModule = new Perlin();
        perlinModule.setFrequency(frequency);
        perlinModule.setOctaveCount(octaveCount);
        perlinModule.setPersistence(persistence);
        perlinModule.setSeed(seed);

        this.MAX_VALUE = perlinModule.getMaxValue();
        this.proceduralModel = new Plane(perlinModule);

Later I get the MAX_VALUE and it turns out to be NaN.
Full code:
Initialization https://ptero.co/apezygamas.java
Runnable I use to retrieve values https://ptero.co/ujuvamadub.java

Utils.makeInt32Range is implemented incorrectly

This has been found by DaPorkchop_ while working on another project

This method:

public static double makeInt32Range(double n) {
if (n >= 1073741824.0) {
return (2.0 * n % 1073741824.0) - 1073741824.0;
} else if (n <= -1073741824.0) {
return (2.0 * n % 1073741824.0) + 1073741824.0;
} else {
return n;
}
}

has been originally ported from the following C code in libnoise:

  inline double MakeInt32Range (double n)
  {
    if (n >= 1073741824.0) {
      return (2.0 * fmod (n, 1073741824.0)) - 1073741824.0;
    } else if (n <= -1073741824.0) {
      return (2.0 * fmod (n, 1073741824.0)) + 1073741824.0;
    } else {
      return n;
    }
  }

But because of operator precedence in java, the java code is actually equivalent to this

    public static double makeInt32Range(double n) {
        if (n >= 1073741824.0) {
            return ((2.0 * n) % 1073741824.0) - 1073741824.0;
        } else if (n <= -1073741824.0) {
            return ((2.0 * n) % 1073741824.0) + 1073741824.0;
        } else {
            return n;
        }
    }

Where in the original C code, modulo should take precedence.

For values of n between k * 1073741824 and k * 1073741824 + 536870912 for integer k >= 1 (and similar for negative range) this just happens to output the same values, but otherwise for n > 1073741824 the result will be always negative (and similarly for n < -1073741824 the result will be always positive) instead of repeating the entire range from -1073741824 to 1073741824.

Changing this now may be considered a breaking change as there could be terrain generators that would generate different terrain with this fixed.

Perlin noise value is the same for every point

Here is snippet of noise value examples from 10x10x10 cuboid:

[16:05:17] [Server thread/INFO] [ens3]: Value for [8, -4, 0] is 1.6301681263765515
[16:05:17] [Server thread/INFO] [ens3]: Value for [8, -3, 0] is 1.6301681263765515
[16:05:17] [Server thread/INFO] [ens3]: Value for [8, -2, 0] is 1.6301681263765515
[16:05:17] [Server thread/INFO] [ens3]: Value for [8, -1, 0] is 1.6301681263765515
[16:05:17] [Server thread/INFO] [ens3]: Value for [8, 0, 0] is 1.6301681263765515
[16:05:17] [Server thread/INFO] [ens3]: Value for [8, 1, 0] is 1.6301681263765515
[16:05:17] [Server thread/INFO] [ens3]: Value for [8, 2, 0] is 1.6301681263765515
[16:05:17] [Server thread/INFO] [ens3]: Value for [8, 3, 0] is 1.6301681263765515
[16:05:17] [Server thread/INFO] [ens3]: Value for [8, 4, 0] is 1.6301681263765515
[16:05:17] [Server thread/INFO] [ens3]: Value for [8, 5, 0] is 1.6301681263765515
[16:05:17] [Server thread/INFO] [ens3]: Value for [8, 6, 0] is 1.6301681263765515
[16:05:17] [Server thread/INFO] [ens3]: Value for [8, 7, 0] is 1.6301681263765515
[16:05:17] [Server thread/INFO] [ens3]: Value for [8, 8, 0] is 1.6301681263765515
[16:05:17] [Server thread/INFO] [ens3]: Value for [8, 9, 0] is 1.6301681263765515
[16:05:17] [Server thread/INFO] [ens3]: Value for [8, -10, 1] is 1.6301681263765515

Code I use for initializing Perlin noise module:

public class ProceduralGenerator {
    private final Module heightGenerator;

    public ProceduralGenerator() {
        var perlinModule = new Perlin();
        perlinModule.setPersistence(0.714);
        perlinModule.setOctaveCount(8);
        heightGenerator = perlinModule;

    }

    public double applyCoordinates(Vector3d position) {
        return heightGenerator.getValue(position.x(), position.y(), position.z());
    }
}

As pointed out by Diggy in SpongePowered Discord (https://discord.com/channels/142425412096491520/142425521391665153/893802421703278622) issue also seems to affect billow and ridged multi.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.