[orx-noise] Bring back GLSL NoiseFilters.kt (#277)

This commit is contained in:
Abe Pazos
2022-10-20 19:15:32 +00:00
committed by GitHub
parent 390dcf620c
commit 51096e50f6
19 changed files with 891 additions and 280 deletions

View File

@@ -1,15 +1,9 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.LineJoin
import org.openrndr.extensions.SingleScreenshot
import org.openrndr.extra.noise.perturb
import org.openrndr.extra.noise.simplex
import org.openrndr.extra.noise.simplex1D
import org.openrndr.extra.noise.simplex2D
import org.openrndr.extra.noise.gradient
import org.openrndr.extra.noise.simplex3D
import org.openrndr.extra.noise.withVector2Output
import org.openrndr.extra.noise.gradient
import org.openrndr.shape.contour
fun main() = application {
configure {

View File

@@ -0,0 +1,66 @@
import org.openrndr.application
import org.openrndr.draw.colorBuffer
import org.openrndr.extra.noise.filters.*
import org.openrndr.math.Vector2
import org.openrndr.math.Vector3
import org.openrndr.math.Vector4
import kotlin.math.sin
/**
* Render existing GLSL noise algorithms side by side.
* Re-use the same color buffer for the rendering.
* Not all noise properties are used. Explore each noise class
* to find out more adjustable properties.
* The noise color can be set using a `color` or a `gain` property.
*/
fun main() = application {
program {
val noises = listOf(
HashNoise(), SpeckleNoise(), CellNoise(),
ValueNoise(), SimplexNoise3D(), WorleyNoise()
)
val img = colorBuffer(width / noises.size, height * 8 / 10)
extend {
val seed = seconds * 0.1
val scale = 1.0 + sin(seed) * 0.5
noises.forEach { noise ->
when (noise) {
is HashNoise -> {
noise.seed = seed
noise.gain = Vector4(0.5 + sin(seconds) * 0.5)
noise.monochrome = frameCount % 100 < 50
}
is SpeckleNoise -> {
noise.seed = seed
noise.density = 0.1 + sin(seconds) * 0.1
}
is CellNoise -> {
noise.seed = Vector2(seed)
noise.scale = Vector2(scale)
}
is ValueNoise -> {
noise.seed = Vector2(seed)
noise.scale = Vector2(scale)
noise.gain = Vector4(0.5)
}
is SimplexNoise3D -> {
noise.seed = Vector3(seed)
noise.scale = Vector3(scale)
}
is WorleyNoise -> {
noise.scale = scale
noise.offset = Vector2(seed)
}
}
noise.apply(emptyArray(), img)
drawer.image(img)
drawer.translate(
width / noises.size * 1.0,
height * 2 / 10 / (noises.size - 1.0)
)
}
}
}
}

View File

@@ -0,0 +1,34 @@
import org.openrndr.application
import org.openrndr.draw.colorBuffer
import org.openrndr.extra.gui.GUI
import org.openrndr.extra.noise.filters.*
/**
* Render existing GLSL noise algorithms side by side.
* Use the GUI to explore the effects.
*/
fun main() = application {
configure {
width = 200 * 6 + 200
height = 500
}
program {
val noises = listOf(
HashNoise(), SpeckleNoise(), CellNoise(),
ValueNoise(), SimplexNoise3D(), WorleyNoise()
)
val img = colorBuffer(200, 460)
val gui = GUI()
noises.forEach { gui.add(it) }
extend(gui)
extend {
noises.forEachIndexed { i, noise ->
noise.apply(emptyArray(), img)
drawer.image(img, 200.0 + i * 200.0, 20.0)
}
}
}
}

View File

@@ -0,0 +1,47 @@
import org.openrndr.application
import org.openrndr.color.rgb
import org.openrndr.draw.colorBuffer
import org.openrndr.extra.noise.Random
import org.openrndr.extra.noise.filters.*
import org.openrndr.math.Vector3
import org.openrndr.math.Vector4
import kotlin.math.sin
/**
* A sine oscillator with randomized parameters
*/
class SinOsc {
private val freq = Random.double(0.1, 2.0)
private val phase = Random.double(0.0, 6.28)
private val add = Random.double(0.0, 1.0)
private val mul = Random.double(0.0, 1.0 - add)
operator fun invoke() = sin(System.currentTimeMillis() * 0.0001 * freq + phase) * mul + add
}
/**
* Render an animated Simplex3D texture using shaders.
*
* The uniforms in the shader are controlled by
* randomized sine oscillators.
*/
fun main() = application {
program {
val noise = SimplexNoise3D()
val img = colorBuffer(width, height)
val wav = List(21) { SinOsc() }
extend {
noise.seed = Vector3(wav[0](), wav[1](), wav[2]()) // = position
noise.scale = Vector3(wav[3](), wav[4](), wav[5]())
noise.lacunarity = Vector3(wav[6](), wav[7](), wav[8]())
noise.gain = Vector4(wav[9](), wav[10](), wav[11](), wav[12]())
noise.decay = Vector4(wav[13](), wav[14](), wav[15](), wav[16]())
noise.octaves = 4
noise.bias = Vector4(wav[17](), wav[18](), wav[19](), wav[20]())
noise.apply(emptyArray(), img)
drawer.clear(rgb(0.20, 0.18, 0.16))
drawer.image(img)
}
}
}