[orx-noise] Add generated and verified documentation
This commit is contained in:
@@ -2,6 +2,21 @@ package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.Vector4
|
||||
|
||||
/**
|
||||
* A precomputed permutation table specifically designed for 4D Simplex noise.
|
||||
*
|
||||
* The `SIMPLEX_4D` byte array contains a sequence of small integers representing
|
||||
* a predefined ordering used to optimize the generation of 4D Simplex noise.
|
||||
* This table helps reduce computations by providing a consistent lookup
|
||||
* for gradients and permutations in the algorithm.
|
||||
*
|
||||
* It is structured in such a way to align with the needs of gradient calculations
|
||||
* and index wrapping, ensuring consistency and performance in Simplex noise generation.
|
||||
*
|
||||
* This array acts as a critical component in the implementation of 4D Simplex noise
|
||||
* algorithms, supporting the reduction of redundant calculations while ensuring
|
||||
* deterministic outputs.
|
||||
*/
|
||||
private val SIMPLEX_4D = byteArrayOf(
|
||||
0, 1, 2, 3, 0, 1, 3, 2, 0, 0, 0, 0, 0, 2, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 0,
|
||||
0, 2, 1, 3, 0, 0, 0, 0, 0, 3, 1, 2, 0, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 2, 0,
|
||||
@@ -16,9 +31,26 @@ private val SIMPLEX_4D = byteArrayOf(
|
||||
private const val F4 = ((2.23606797 - 1.0) / 4.0)
|
||||
private const val G4 = ((5.0 - 2.23606797) / 20.0)
|
||||
|
||||
/**
|
||||
* Computes the 4D Simplex noise value at the given position and seed.
|
||||
*
|
||||
* @param seed A unique seed value used to generate the noise. Different seed values produce different noise patterns.
|
||||
* @param position A 4D vector containing the (x, y, z, w) coordinates where the noise value should be computed.
|
||||
* @return The computed noise value as a Double.
|
||||
*/
|
||||
fun simplex(seed: Int, position: Vector4) =
|
||||
simplex(seed, position.x, position.y, position.z, position.w)
|
||||
|
||||
/**
|
||||
* Generates a 4D Simplex noise value based on the given coordinates and seed.
|
||||
*
|
||||
* @param seed An integer used to initialize the noise generation.
|
||||
* @param x The x-coordinate in 4D space.
|
||||
* @param y The y-coordinate in 4D space.
|
||||
* @param z The z-coordinate in 4D space.
|
||||
* @param w The w-coordinate in 4D space.
|
||||
* @return A double representing the calculated 4D Simplex noise value at the given coordinates.
|
||||
*/
|
||||
fun simplex(seed: Int, x: Double, y: Double, z: Double, w: Double): Double {
|
||||
|
||||
var t = (x + y + z + w) * F4
|
||||
@@ -107,6 +139,14 @@ fun simplex(seed: Int, x: Double, y: Double, z: Double, w: Double): Double {
|
||||
return 27 * (n0 + n1 + n2 + n3 + n4)
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a 4D vector using Simplex noise based on the given seed and 1D input.
|
||||
* Each component of the vector is generated by shifting the input x-coordinate for different noise values.
|
||||
*
|
||||
* @param seed An integer used to initialize the noise generation process.
|
||||
* @param x The x-coordinate for generating the Simplex noise in 4D space.
|
||||
* @return A Vector4 where each component is a 4D Simplex noise value.
|
||||
*/
|
||||
fun Vector4.Companion.simplex(seed: Int, x: Double): Vector4 = Vector4(simplex(seed, x, 0.0, 0.0, 0.0),
|
||||
simplex(seed, 0.0, x + 31.3383, 0.0, 0.0),
|
||||
simplex(seed, 0.0, 0.0, x - 483.23, 0.0),
|
||||
|
||||
Reference in New Issue
Block a user