Convert orx-shader-phrases and orx-noise to MPP
This commit is contained in:
@@ -15,6 +15,7 @@ dependencies {
|
||||
demoImplementation(project(":orx-camera"))
|
||||
demoImplementation("org.openrndr:openrndr-application:$openrndrVersion")
|
||||
demoImplementation("org.openrndr:openrndr-extensions:$openrndrVersion")
|
||||
|
||||
demoRuntimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion")
|
||||
demoRuntimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion")
|
||||
demoImplementation(sourceSets.getByName("main").output)
|
||||
95
orx-noise/build.gradle.kts
Normal file
95
orx-noise/build.gradle.kts
Normal file
@@ -0,0 +1,95 @@
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
kotlin("plugin.serialization")
|
||||
}
|
||||
|
||||
val kotlinxSerializationVersion: String by rootProject.extra
|
||||
val kotestVersion: String by rootProject.extra
|
||||
val junitJupiterVersion: String by rootProject.extra
|
||||
val jvmTarget: String by rootProject.extra
|
||||
val kotlinApiVersion: String by rootProject.extra
|
||||
val openrndrVersion: String by rootProject.extra
|
||||
val openrndrOS: String by rootProject.extra
|
||||
val kluentVersion: String by rootProject.extra
|
||||
val spekVersion: String by rootProject.extra
|
||||
|
||||
kotlin {
|
||||
jvm {
|
||||
compilations {
|
||||
val demo by creating {
|
||||
defaultSourceSet {
|
||||
kotlin.srcDir("src/demo")
|
||||
dependencies {
|
||||
implementation(project(":orx-camera"))
|
||||
implementation("org.openrndr:openrndr-application:$openrndrVersion")
|
||||
implementation("org.openrndr:openrndr-extensions:$openrndrVersion")
|
||||
runtimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion")
|
||||
runtimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion")
|
||||
implementation(compilations["main"]!!.output.allOutputs)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
compilations.all {
|
||||
kotlinOptions.jvmTarget = jvmTarget
|
||||
kotlinOptions.apiVersion = kotlinApiVersion
|
||||
}
|
||||
testRuns["test"].executionTask.configure {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
}
|
||||
|
||||
js(IR) {
|
||||
browser()
|
||||
nodejs()
|
||||
}
|
||||
|
||||
|
||||
sourceSets {
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val commonMain by getting {
|
||||
dependencies {
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlinxSerializationVersion")
|
||||
implementation("org.openrndr:openrndr-math:$openrndrVersion")
|
||||
implementation("org.openrndr:openrndr-shape:$openrndrVersion")
|
||||
implementation("org.openrndr:openrndr-draw:$openrndrVersion")
|
||||
}
|
||||
}
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val commonTest by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("test-common"))
|
||||
implementation(kotlin("test-annotations-common"))
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion")
|
||||
implementation("io.kotest:kotest-assertions-core:$kotestVersion")
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val jvmMain by getting
|
||||
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val jvmTest by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("test-common"))
|
||||
implementation(kotlin("test-annotations-common"))
|
||||
implementation(kotlin("test-junit5"))
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion")
|
||||
runtimeOnly("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion")
|
||||
runtimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion")
|
||||
implementation("org.spekframework.spek2:spek-dsl-jvm:$spekVersion")
|
||||
implementation("org.amshove.kluent:kluent:$kluentVersion")
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val jsMain by getting
|
||||
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val jsTest by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("test-js"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,7 +115,7 @@ inline fun billow(seed: Int, position: Vector4, crossinline noise: (Int, Double,
|
||||
|
||||
inline fun billow(seed: Int, x: Double, y: Double, z: Double, w: Double, crossinline noise: (Int, Double, Double, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
var sum = Math.abs(noise(seed, x, y, z, w) * 2.0 - 1.0)
|
||||
var sum = abs(noise(seed, x, y, z, w) * 2.0 - 1.0)
|
||||
var amp = 1.0
|
||||
|
||||
var x = x
|
||||
@@ -128,7 +128,7 @@ inline fun billow(seed: Int, x: Double, y: Double, z: Double, w: Double, crossin
|
||||
z *= lacunarity
|
||||
w *= lacunarity
|
||||
amp *= gain
|
||||
sum += Math.abs(noise(seed + i, x, y, z, w) * 2.0 - 1.0) * amp
|
||||
sum += abs(noise(seed + i, x, y, z, w) * 2.0 - 1.0) * amp
|
||||
}
|
||||
return sum
|
||||
}
|
||||
@@ -139,7 +139,7 @@ inline fun billow(seed: Int, position: Vector3, crossinline noise: (Int, Double,
|
||||
|
||||
inline fun billow(seed: Int, x: Double, y: Double, z: Double, crossinline noise: (Int, Double, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
var sum = Math.abs(noise(seed, x, y, z) * 2.0 - 1.0)
|
||||
var sum = abs(noise(seed, x, y, z) * 2.0 - 1.0)
|
||||
var amp = 1.0
|
||||
|
||||
var x = x
|
||||
@@ -150,7 +150,7 @@ inline fun billow(seed: Int, x: Double, y: Double, z: Double, crossinline noise:
|
||||
y *= lacunarity
|
||||
z *= lacunarity
|
||||
amp *= gain
|
||||
sum += Math.abs(noise(seed + i, x, y, z) * 2.0 - 1.0) * amp
|
||||
sum += abs(noise(seed + i, x, y, z) * 2.0 - 1.0) * amp
|
||||
}
|
||||
return sum
|
||||
}
|
||||
@@ -219,7 +219,7 @@ inline fun rigid(seed: Int, position: Vector4, crossinline noise: (Int, Double,
|
||||
|
||||
inline fun rigid(seed: Int, x: Double, y: Double, z: Double, w: Double, crossinline noise: (Int, Double, Double, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
var sum = 1.0 - Math.abs(noise(seed, x, y, z, w))
|
||||
var sum = 1.0 - abs(noise(seed, x, y, z, w))
|
||||
var amp = 1.0
|
||||
|
||||
var x = x
|
||||
@@ -243,7 +243,7 @@ inline fun rigid(seed: Int, position: Vector3, crossinline noise: (Int, Double,
|
||||
|
||||
inline fun rigid(seed: Int, x: Double, y: Double, z: Double, crossinline noise: (Int, Double, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
var sum = 1.0 - Math.abs(noise(seed, x, y, z))
|
||||
var sum = 1.0 - abs(noise(seed, x, y, z))
|
||||
var amp = 1.0
|
||||
|
||||
var x = x
|
||||
@@ -265,7 +265,7 @@ inline fun rigid(seed: Int, position: Vector2, crossinline noise: (Int, Double,
|
||||
|
||||
inline fun rigid(seed: Int, x: Double, y: Double, crossinline noise: (Int, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
var sum = 1.0 - Math.abs(noise(seed, x, y))
|
||||
var sum = 1.0 - abs(noise(seed, x, y))
|
||||
var amp = 1.0
|
||||
|
||||
var x = x
|
||||
@@ -274,7 +274,7 @@ inline fun rigid(seed: Int, x: Double, y: Double, crossinline noise: (Int, Doubl
|
||||
x *= lacunarity
|
||||
y *= lacunarity
|
||||
amp *= gain
|
||||
sum -= (1.0 - Math.abs(noise(seed + i, x, y))) * amp
|
||||
sum -= (1.0 - abs(noise(seed + i, x, y))) * amp
|
||||
}
|
||||
return sum
|
||||
}
|
||||
@@ -3,6 +3,9 @@ package org.openrndr.extra.noise
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.math.Vector4
|
||||
import kotlin.math.ln
|
||||
import kotlin.math.log
|
||||
import kotlin.math.sqrt
|
||||
import kotlin.random.Random
|
||||
|
||||
fun gaussian(mean: Double = 0.0, deviation: Double = 1.0, random: Random = Random.Default): Double {
|
||||
@@ -14,7 +17,7 @@ fun gaussian(mean: Double = 0.0, deviation: Double = 1.0, random: Random = Rando
|
||||
v2 = 2 * random.nextDouble() - 1
|
||||
s = v1 * v1 + v2 * v2
|
||||
} while (s >= 1 || s == 0.0)
|
||||
val multiplier = StrictMath.sqrt(-2 * StrictMath.log(s) / s)
|
||||
val multiplier = sqrt(-2 * ln(s) / s)
|
||||
|
||||
return v1 * multiplier * deviation + mean
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
|
||||
fun Double.fastFloor(): Int {
|
||||
return if (this >= 0) this.toInt() else this.toInt() - 1
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
|
||||
fun Double.fastFloor(): Int {
|
||||
return if (this >= 0) this.toInt() else this.toInt() - 1
|
||||
}
|
||||
271
orx-noise/src/commonMain/kotlin/filters/NoiseFilters.kt
Normal file
271
orx-noise/src/commonMain/kotlin/filters/NoiseFilters.kt
Normal file
@@ -0,0 +1,271 @@
|
||||
//package org.openrndr.extra.noise.filters
|
||||
//
|
||||
//import org.openrndr.color.ColorRGBa
|
||||
//import org.openrndr.draw.Filter
|
||||
//import org.openrndr.draw.filterShaderFromUrl
|
||||
//import org.openrndr.extra.parameters.*
|
||||
//import org.openrndr.math.Vector2
|
||||
//import org.openrndr.math.Vector3
|
||||
//import org.openrndr.math.Vector4
|
||||
//import org.openrndr.resourceUrl
|
||||
//
|
||||
///**
|
||||
// * Hash noise filter that produces white-noise-like noise.
|
||||
// */
|
||||
//class HashNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/hash-noise.frag"))) {
|
||||
// /**
|
||||
// * noise gain per channel, default is Vector4(1.0, 1.0, 1.0, 0.0)
|
||||
// */
|
||||
// var gain: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * noise bias per channel, default is Vector4(0.0, 0.0, 0.0, 1.0)
|
||||
// */
|
||||
// var bias: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * is the noise monochrome, default is true
|
||||
// */
|
||||
// @BooleanParameter("Monochrome")
|
||||
// var monochrome: Boolean by parameters
|
||||
//
|
||||
// /**
|
||||
// * noise seed, feed it with time to animate
|
||||
// */
|
||||
// @DoubleParameter("Seed", 0.0, 10000.0)
|
||||
// var seed: Double by parameters
|
||||
//
|
||||
// init {
|
||||
// monochrome = true
|
||||
// gain = Vector4(1.0, 1.0, 1.0, 0.0)
|
||||
// bias = Vector4(0.0, 0.0, 0.0, 1.0)
|
||||
// seed = 0.0
|
||||
// }
|
||||
//}
|
||||
//
|
||||
///**
|
||||
// * Speckle noise filter
|
||||
// */
|
||||
//class SpeckleNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/speckle-noise.frag"))) {
|
||||
//
|
||||
// /**
|
||||
// * The color of the generated speckles
|
||||
// */
|
||||
// @ColorParameter("Color")
|
||||
// var color: ColorRGBa by parameters
|
||||
//
|
||||
// /**
|
||||
// * Density of the speckles, default is 0.1, min, 0.0, max is 1.0
|
||||
// */
|
||||
// @DoubleParameter("Density", 0.0, 1.0)
|
||||
// var density: Double by parameters
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Noisiness of the generated speckles, default is 0.0, min is 0.0, max is 1.0
|
||||
// */
|
||||
// @DoubleParameter("Noise", 0.0, 1.0)
|
||||
// var noise: Double by parameters
|
||||
//
|
||||
// /**
|
||||
// * should the output colors be multiplied by the alpha channel, default is true
|
||||
// */
|
||||
// var premultipliedAlpha: Boolean by parameters
|
||||
//
|
||||
// /**
|
||||
// * noise seed, feed it with time to animate
|
||||
// */
|
||||
// @DoubleParameter("Seed", 0.0, 10000.0)
|
||||
// var seed: Double by parameters
|
||||
//
|
||||
// init {
|
||||
// density = 0.1
|
||||
// color = ColorRGBa.WHITE
|
||||
// seed = 0.0
|
||||
// noise = 0.0
|
||||
// premultipliedAlpha = true
|
||||
// }
|
||||
//}
|
||||
//
|
||||
///**
|
||||
// * Filter that produces cell or Voronoi noise
|
||||
// */
|
||||
//class CellNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/cell-noise.frag"))) {
|
||||
// var seed: Vector2 by parameters
|
||||
//
|
||||
// /**
|
||||
// * base noise scale, default is Vector2(1.0, 1.0)
|
||||
// */
|
||||
// var scale: Vector2 by parameters
|
||||
//
|
||||
// /**
|
||||
// * lacunarity is the amount by which scale is modulated per octave, default is Vector2(2.0, 2.0)
|
||||
// */
|
||||
// var lacunarity: Vector2 by parameters
|
||||
//
|
||||
// /**
|
||||
// * gain is the base intensity per channel, default is Vector2(1.0, 1.0, 1.0, 1.0)
|
||||
// */
|
||||
// var gain: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * decay is the amount by which gain is modulated per octave, default is Vector4(0.5, 0.5, 0.5, 0.5)
|
||||
// */
|
||||
// var decay: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * the number of octaves of noise to generate, default is 4
|
||||
// */
|
||||
// @IntParameter("Octaves", 1, 8)
|
||||
// var octaves: Int by parameters
|
||||
//
|
||||
// /**
|
||||
// * the value to add to the resulting noise
|
||||
// */
|
||||
// var bias: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * should the output colors be multiplied by the alpha channel, default is true
|
||||
// */
|
||||
// var premultipliedAlpha: Boolean by parameters
|
||||
//
|
||||
// init {
|
||||
// seed = Vector2.ZERO
|
||||
// scale = Vector2.ONE
|
||||
// lacunarity = Vector2(2.0, 2.0)
|
||||
// gain = Vector4.ONE
|
||||
// decay = Vector4.ONE / 2.0
|
||||
// octaves = 4
|
||||
// bias = Vector4.ZERO
|
||||
// premultipliedAlpha = true
|
||||
// }
|
||||
//}
|
||||
//
|
||||
///**
|
||||
// * Filter that produces value noise
|
||||
// */
|
||||
//class ValueNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/value-noise.frag"))) {
|
||||
// @DoubleParameter("Seed", 0.0, 10000.0)
|
||||
// var seed: Vector2 by parameters
|
||||
//
|
||||
// /**
|
||||
// * base noise scale, default is Vector2(1.0, 1.0)
|
||||
// */
|
||||
// var scale: Vector2 by parameters
|
||||
//
|
||||
// /**
|
||||
// * lacunarity is the amount by which scale is modulated per octave, default is Vector2(2.0, 2.0)
|
||||
// */
|
||||
// var lacunarity: Vector2 by parameters
|
||||
//
|
||||
// /**
|
||||
// * gain is the base intensity per channel, default is Vector2(1.0, 1.0, 1.0, 1.0)
|
||||
// */
|
||||
// var gain: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * decay is the amount by which gain is modulated per octave, default is Vector4(0.5, 0.5, 0.5, 0.5)
|
||||
// */
|
||||
// var decay: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * the number of octaves of noise to generate, default is 4
|
||||
// */
|
||||
// @IntParameter("Octaves", 1, 8)
|
||||
// var octaves: Int by parameters
|
||||
//
|
||||
// /**
|
||||
// * the value to add to the resulting noise
|
||||
// */
|
||||
// var bias: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * should the output colors be multiplied by the alpha channel, default is true
|
||||
// */
|
||||
// var premultipliedAlpha: Boolean by parameters
|
||||
//
|
||||
// init {
|
||||
// seed = Vector2.ZERO
|
||||
// scale = Vector2.ONE
|
||||
// lacunarity = Vector2(2.0, 2.0)
|
||||
// gain = Vector4.ONE
|
||||
// decay = Vector4.ONE / 2.0
|
||||
// octaves = 4
|
||||
// bias = Vector4.ZERO
|
||||
// premultipliedAlpha = true
|
||||
// }
|
||||
//}
|
||||
//
|
||||
///**
|
||||
// * Filter that produces 3D Simplex Noise
|
||||
// */
|
||||
//@Description("Simplex Noise")
|
||||
//class SimplexNoise3D : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/simplex-noise-3d.frag"))) {
|
||||
// var seed: Vector3 by parameters
|
||||
//
|
||||
// /**
|
||||
// * base noise scale, default is Vector3(1.0, 1.0, 1.0)
|
||||
// */
|
||||
// var scale: Vector3 by parameters
|
||||
//
|
||||
// /**
|
||||
// * lacunarity is the amount by which scale is modulated per octave, default is Vector3(2.0, 2.0, 2.0)
|
||||
// */
|
||||
// var lacunarity: Vector3 by parameters
|
||||
//
|
||||
// /**
|
||||
// * gain is the base intensity per channel, default is Vector2(1.0, 1.0, 1.0, 1.0)
|
||||
// */
|
||||
// var gain: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * decay is the amount by which gain is modulated per octave, default is Vector4(0.5, 0.5, 0.5, 0.5)
|
||||
// */
|
||||
// var decay: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * the number of octaves of noise to generate, default is 4
|
||||
// */
|
||||
// @IntParameter("Octaves", 1, 8)
|
||||
// var octaves: Int by parameters
|
||||
//
|
||||
// /**
|
||||
// * the value to add to the resulting noise
|
||||
// */
|
||||
// var bias: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * should the output colors be multiplied by the alpha channel, default is true
|
||||
// */
|
||||
// @BooleanParameter("Premultiplied alpha")
|
||||
// var premultipliedAlpha: Boolean by parameters
|
||||
//
|
||||
// init {
|
||||
// seed = Vector3.ZERO
|
||||
// scale = Vector3.ONE
|
||||
// lacunarity = Vector3(2.0, 2.0, 2.0)
|
||||
// gain = Vector4.ONE / 2.0
|
||||
// decay = Vector4.ONE / 2.0
|
||||
// octaves = 4
|
||||
// bias = Vector4.ONE / 2.0
|
||||
// premultipliedAlpha = true
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * Filter for Worley Noise
|
||||
// */
|
||||
//@Description("Worley Noise")
|
||||
//class WorleyNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/worley-noise.frag"))) {
|
||||
// @DoubleParameter("Scale", 0.1, 200.0)
|
||||
// var scale: Double by parameters
|
||||
//
|
||||
// @BooleanParameter("Premultiplied alpha")
|
||||
// var premultipliedAlpha: Boolean by parameters
|
||||
//
|
||||
// init {
|
||||
// premultipliedAlpha = true
|
||||
// scale = 5.0
|
||||
// }
|
||||
//}
|
||||
@@ -1,12 +1,12 @@
|
||||
@file:ShaderPhrases(exports = ["hash22","hash21","valueNoise21"])
|
||||
//@file:ShaderPhrases(exports = ["hash22","hash21","valueNoise21"])
|
||||
package org.openrndr.extra.noise.phrases
|
||||
|
||||
import org.openrndr.extra.shaderphrases.annotations.ShaderPhrases
|
||||
//import org.openrndr.extra.shaderphrases.annotations.ShaderPhrases
|
||||
|
||||
val phraseHash22 = """vec2 hash22(vec2 p) {
|
||||
float n = sin(dot(p, vec2(41, 289)));
|
||||
return fract(vec2(262144, 32768)*n);
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
val phraseHash21 = "float hash21(vec2 p) { return fract(1e4 * sin(17.0 * p.x + p.y * 0.1) * (0.1 + abs(sin(p.y * 13.0 + p.x)))); }"
|
||||
@@ -17,11 +17,10 @@ vec3 hash33(vec3 p3) {
|
||||
p3 = fract(p3 * MOD3);
|
||||
p3 += dot(p3, p3.yxz+19.19);
|
||||
return -1.0 + 2.0 * fract(vec3((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y, (p3.y+p3.z)*p3.x));
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
val phraseValueNoise21 = """
|
||||
|
||||
float noise(vec2 x) {
|
||||
vec2 i = floor(x);
|
||||
vec2 f = fract(x);
|
||||
@@ -33,5 +32,5 @@ float noise(vec2 x) {
|
||||
|
||||
vec2 u = f * f * (3.0 - 2.0 * f);
|
||||
return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
7
orx-noise/src/commonMain/kotlin/phrases/Simplex.kt
Normal file
7
orx-noise/src/commonMain/kotlin/phrases/Simplex.kt
Normal file
@@ -0,0 +1,7 @@
|
||||
//@file:ShaderPhrases([])
|
||||
package org.openrndr.extra.noise.phrases
|
||||
//
|
||||
//import org.openrndr.extra.shaderphrases.annotations.ShaderPhrases
|
||||
//import org.openrndr.extra.shaderphrases.phraseResource
|
||||
//
|
||||
//val phraseSimplex3 by phraseResource("/org/openrndr/extra/noise/phrases/gl3/simplex-3.frag")
|
||||
@@ -7,6 +7,7 @@ import org.openrndr.extra.noise.simplex
|
||||
import org.openrndr.math.Vector2
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
|
||||
suspend fun main() {
|
||||
application {
|
||||
program {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.noise.poissonDiskSampling
|
||||
|
||||
@@ -1,271 +0,0 @@
|
||||
package org.openrndr.extra.noise.filters
|
||||
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.Filter
|
||||
import org.openrndr.draw.filterShaderFromUrl
|
||||
import org.openrndr.extra.parameters.*
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.math.Vector4
|
||||
import org.openrndr.resourceUrl
|
||||
|
||||
/**
|
||||
* Hash noise filter that produces white-noise-like noise.
|
||||
*/
|
||||
class HashNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/hash-noise.frag"))) {
|
||||
/**
|
||||
* noise gain per channel, default is Vector4(1.0, 1.0, 1.0, 0.0)
|
||||
*/
|
||||
var gain: Vector4 by parameters
|
||||
|
||||
/**
|
||||
* noise bias per channel, default is Vector4(0.0, 0.0, 0.0, 1.0)
|
||||
*/
|
||||
var bias: Vector4 by parameters
|
||||
|
||||
/**
|
||||
* is the noise monochrome, default is true
|
||||
*/
|
||||
@BooleanParameter("Monochrome")
|
||||
var monochrome: Boolean by parameters
|
||||
|
||||
/**
|
||||
* noise seed, feed it with time to animate
|
||||
*/
|
||||
@DoubleParameter("Seed", 0.0, 10000.0)
|
||||
var seed: Double by parameters
|
||||
|
||||
init {
|
||||
monochrome = true
|
||||
gain = Vector4(1.0, 1.0, 1.0, 0.0)
|
||||
bias = Vector4(0.0, 0.0, 0.0, 1.0)
|
||||
seed = 0.0
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Speckle noise filter
|
||||
*/
|
||||
class SpeckleNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/speckle-noise.frag"))) {
|
||||
|
||||
/**
|
||||
* The color of the generated speckles
|
||||
*/
|
||||
@ColorParameter("Color")
|
||||
var color: ColorRGBa by parameters
|
||||
|
||||
/**
|
||||
* Density of the speckles, default is 0.1, min, 0.0, max is 1.0
|
||||
*/
|
||||
@DoubleParameter("Density", 0.0, 1.0)
|
||||
var density: Double by parameters
|
||||
|
||||
|
||||
/**
|
||||
* Noisiness of the generated speckles, default is 0.0, min is 0.0, max is 1.0
|
||||
*/
|
||||
@DoubleParameter("Noise", 0.0, 1.0)
|
||||
var noise: Double by parameters
|
||||
|
||||
/**
|
||||
* should the output colors be multiplied by the alpha channel, default is true
|
||||
*/
|
||||
var premultipliedAlpha: Boolean by parameters
|
||||
|
||||
/**
|
||||
* noise seed, feed it with time to animate
|
||||
*/
|
||||
@DoubleParameter("Seed", 0.0, 10000.0)
|
||||
var seed: Double by parameters
|
||||
|
||||
init {
|
||||
density = 0.1
|
||||
color = ColorRGBa.WHITE
|
||||
seed = 0.0
|
||||
noise = 0.0
|
||||
premultipliedAlpha = true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter that produces cell or Voronoi noise
|
||||
*/
|
||||
class CellNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/cell-noise.frag"))) {
|
||||
var seed: Vector2 by parameters
|
||||
|
||||
/**
|
||||
* base noise scale, default is Vector2(1.0, 1.0)
|
||||
*/
|
||||
var scale: Vector2 by parameters
|
||||
|
||||
/**
|
||||
* lacunarity is the amount by which scale is modulated per octave, default is Vector2(2.0, 2.0)
|
||||
*/
|
||||
var lacunarity: Vector2 by parameters
|
||||
|
||||
/**
|
||||
* gain is the base intensity per channel, default is Vector2(1.0, 1.0, 1.0, 1.0)
|
||||
*/
|
||||
var gain: Vector4 by parameters
|
||||
|
||||
/**
|
||||
* decay is the amount by which gain is modulated per octave, default is Vector4(0.5, 0.5, 0.5, 0.5)
|
||||
*/
|
||||
var decay: Vector4 by parameters
|
||||
|
||||
/**
|
||||
* the number of octaves of noise to generate, default is 4
|
||||
*/
|
||||
@IntParameter("Octaves", 1, 8)
|
||||
var octaves: Int by parameters
|
||||
|
||||
/**
|
||||
* the value to add to the resulting noise
|
||||
*/
|
||||
var bias: Vector4 by parameters
|
||||
|
||||
/**
|
||||
* should the output colors be multiplied by the alpha channel, default is true
|
||||
*/
|
||||
var premultipliedAlpha: Boolean by parameters
|
||||
|
||||
init {
|
||||
seed = Vector2.ZERO
|
||||
scale = Vector2.ONE
|
||||
lacunarity = Vector2(2.0, 2.0)
|
||||
gain = Vector4.ONE
|
||||
decay = Vector4.ONE / 2.0
|
||||
octaves = 4
|
||||
bias = Vector4.ZERO
|
||||
premultipliedAlpha = true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter that produces value noise
|
||||
*/
|
||||
class ValueNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/value-noise.frag"))) {
|
||||
@DoubleParameter("Seed", 0.0, 10000.0)
|
||||
var seed: Vector2 by parameters
|
||||
|
||||
/**
|
||||
* base noise scale, default is Vector2(1.0, 1.0)
|
||||
*/
|
||||
var scale: Vector2 by parameters
|
||||
|
||||
/**
|
||||
* lacunarity is the amount by which scale is modulated per octave, default is Vector2(2.0, 2.0)
|
||||
*/
|
||||
var lacunarity: Vector2 by parameters
|
||||
|
||||
/**
|
||||
* gain is the base intensity per channel, default is Vector2(1.0, 1.0, 1.0, 1.0)
|
||||
*/
|
||||
var gain: Vector4 by parameters
|
||||
|
||||
/**
|
||||
* decay is the amount by which gain is modulated per octave, default is Vector4(0.5, 0.5, 0.5, 0.5)
|
||||
*/
|
||||
var decay: Vector4 by parameters
|
||||
|
||||
/**
|
||||
* the number of octaves of noise to generate, default is 4
|
||||
*/
|
||||
@IntParameter("Octaves", 1, 8)
|
||||
var octaves: Int by parameters
|
||||
|
||||
/**
|
||||
* the value to add to the resulting noise
|
||||
*/
|
||||
var bias: Vector4 by parameters
|
||||
|
||||
/**
|
||||
* should the output colors be multiplied by the alpha channel, default is true
|
||||
*/
|
||||
var premultipliedAlpha: Boolean by parameters
|
||||
|
||||
init {
|
||||
seed = Vector2.ZERO
|
||||
scale = Vector2.ONE
|
||||
lacunarity = Vector2(2.0, 2.0)
|
||||
gain = Vector4.ONE
|
||||
decay = Vector4.ONE / 2.0
|
||||
octaves = 4
|
||||
bias = Vector4.ZERO
|
||||
premultipliedAlpha = true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter that produces 3D Simplex Noise
|
||||
*/
|
||||
@Description("Simplex Noise")
|
||||
class SimplexNoise3D : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/simplex-noise-3d.frag"))) {
|
||||
var seed: Vector3 by parameters
|
||||
|
||||
/**
|
||||
* base noise scale, default is Vector3(1.0, 1.0, 1.0)
|
||||
*/
|
||||
var scale: Vector3 by parameters
|
||||
|
||||
/**
|
||||
* lacunarity is the amount by which scale is modulated per octave, default is Vector3(2.0, 2.0, 2.0)
|
||||
*/
|
||||
var lacunarity: Vector3 by parameters
|
||||
|
||||
/**
|
||||
* gain is the base intensity per channel, default is Vector2(1.0, 1.0, 1.0, 1.0)
|
||||
*/
|
||||
var gain: Vector4 by parameters
|
||||
|
||||
/**
|
||||
* decay is the amount by which gain is modulated per octave, default is Vector4(0.5, 0.5, 0.5, 0.5)
|
||||
*/
|
||||
var decay: Vector4 by parameters
|
||||
|
||||
/**
|
||||
* the number of octaves of noise to generate, default is 4
|
||||
*/
|
||||
@IntParameter("Octaves", 1, 8)
|
||||
var octaves: Int by parameters
|
||||
|
||||
/**
|
||||
* the value to add to the resulting noise
|
||||
*/
|
||||
var bias: Vector4 by parameters
|
||||
|
||||
/**
|
||||
* should the output colors be multiplied by the alpha channel, default is true
|
||||
*/
|
||||
@BooleanParameter("Premultiplied alpha")
|
||||
var premultipliedAlpha: Boolean by parameters
|
||||
|
||||
init {
|
||||
seed = Vector3.ZERO
|
||||
scale = Vector3.ONE
|
||||
lacunarity = Vector3(2.0, 2.0, 2.0)
|
||||
gain = Vector4.ONE / 2.0
|
||||
decay = Vector4.ONE / 2.0
|
||||
octaves = 4
|
||||
bias = Vector4.ONE / 2.0
|
||||
premultipliedAlpha = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Filter for Worley Noise
|
||||
*/
|
||||
@Description("Worley Noise")
|
||||
class WorleyNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/worley-noise.frag"))) {
|
||||
@DoubleParameter("Scale", 0.1, 200.0)
|
||||
var scale: Double by parameters
|
||||
|
||||
@BooleanParameter("Premultiplied alpha")
|
||||
var premultipliedAlpha: Boolean by parameters
|
||||
|
||||
init {
|
||||
premultipliedAlpha = true
|
||||
scale = 5.0
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
@file:ShaderPhrases([])
|
||||
package org.openrndr.extra.noise.phrases
|
||||
|
||||
import org.openrndr.extra.shaderphrases.annotations.ShaderPhrases
|
||||
import org.openrndr.extra.shaderphrases.phraseResource
|
||||
|
||||
val phraseSimplex3 by phraseResource("/org/openrndr/extra/noise/phrases/gl3/simplex-3.frag")
|
||||
Reference in New Issue
Block a user