Convert orx-shader-phrases and orx-noise to MPP

This commit is contained in:
Edwin Jakobs
2021-06-24 13:31:27 +02:00
parent 6a45db4491
commit 1cf5c825d6
69 changed files with 813 additions and 741 deletions

View File

@@ -0,0 +1,67 @@
package org.openrndr.extra.noise
import org.openrndr.math.Vector2
private const val SQRT3 = 1.7320508075688772935274463415059
private const val F2 = 0.5 * (SQRT3 - 1.0)
private const val G2 = (3.0 - SQRT3) / 6.0
fun simplex(seed: Int, position: Vector2): Double = simplex(seed, position.x, position.y)
fun simplex(seed: Int, x: Double, y: Double): Double {
var t = (x + y) * F2
val i = (x + t).fastFloor()
val j = (y + t).fastFloor()
t = ((i + j) * G2)
val x0 = x - (i - t)
val y0 = y - (j - t)
val i1: Int
val j1: Int
if (x0 > y0) {
i1 = 1
j1 = 0
} else {
i1 = 0
j1 = 1
}
val x1 = (x0 - i1 + G2)
val y1 = (y0 - j1 + G2)
val x2 = (x0 - 1 + 2 * G2)
val y2 = (y0 - 1 + 2 * G2)
val n0: Double
val n1: Double
val n2: Double
t = 0.5 - x0 * x0 - y0 * y0
if (t < 0)
n0 = 0.0
else {
t *= t
n0 = t * t * gradCoord2D(seed, i, j, x0, y0)
}
t = 0.5 - x1 * x1 - y1 * y1
if (t < 0)
n1 = 0.0
else {
t *= t
n1 = t * t * gradCoord2D(seed, i + i1, j + j1, x1, y1)
}
t = 0.5 - x2 * x2 - y2 * y2
if (t < 0)
n2 = 0.0
else {
t *= t
n2 = t * t * gradCoord2D(seed, i + 1, j + 1, x2, y2)
}
return 50.0 * (n0 + n1 + n2)
}
fun Vector2.Companion.simplex(seed: Int, x: Double): Vector2 = Vector2(simplex(seed, x, 0.0, 0.0, 0.0),
simplex(seed, 0.0, x + 31.3383, 0.0, 0.0))