Worley noise, Syphon and noise filter parameters...
This commit is contained in:
committed by
edwin
parent
1eaf8607db
commit
bb7439db54
@@ -1,3 +1,7 @@
|
||||
dependencies {
|
||||
compile "org.openrndr:openrndr-core:$openrndrVersion"
|
||||
compile "org.openrndr:openrndr-gl3:$openrndrVersion"
|
||||
compile "org.openrndr:openrndr-gl3-natives-macos:$openrndrVersion"
|
||||
implementation project(":orx-shader-phrases")
|
||||
implementation project(":orx-gui")
|
||||
}
|
||||
@@ -3,6 +3,7 @@ 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
|
||||
@@ -25,11 +26,13 @@ class HashNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/no
|
||||
/**
|
||||
* 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 {
|
||||
@@ -48,18 +51,20 @@ class SpeckleNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra
|
||||
/**
|
||||
* 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
|
||||
|
||||
/**
|
||||
@@ -70,6 +75,7 @@ class SpeckleNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra
|
||||
/**
|
||||
* noise seed, feed it with time to animate
|
||||
*/
|
||||
@DoubleParameter("Seed", 0.0, 10000.0)
|
||||
var seed: Double by parameters
|
||||
|
||||
init {
|
||||
@@ -110,6 +116,7 @@ class CellNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/no
|
||||
/**
|
||||
* the number of octaves of noise to generate, default is 4
|
||||
*/
|
||||
@IntParameter("Octaves", 1, 8)
|
||||
var octaves: Int by parameters
|
||||
|
||||
/**
|
||||
@@ -138,6 +145,7 @@ class CellNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/no
|
||||
* 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
|
||||
|
||||
/**
|
||||
@@ -163,6 +171,7 @@ class ValueNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/n
|
||||
/**
|
||||
* the number of octaves of noise to generate, default is 4
|
||||
*/
|
||||
@IntParameter("Octaves", 1, 8)
|
||||
var octaves: Int by parameters
|
||||
|
||||
/**
|
||||
@@ -190,6 +199,7 @@ class ValueNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/n
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -216,6 +226,7 @@ class SimplexNoise3D : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/ext
|
||||
/**
|
||||
* the number of octaves of noise to generate, default is 4
|
||||
*/
|
||||
@IntParameter("Octaves", 1, 8)
|
||||
var octaves: Int by parameters
|
||||
|
||||
/**
|
||||
@@ -226,6 +237,7 @@ class SimplexNoise3D : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/ext
|
||||
/**
|
||||
* should the output colors be multiplied by the alpha channel, default is true
|
||||
*/
|
||||
@BooleanParameter("Premultiplied alpha")
|
||||
var premultipliedAlpha: Boolean by parameters
|
||||
|
||||
init {
|
||||
@@ -238,4 +250,22 @@ class SimplexNoise3D : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/ext
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
#version 330
|
||||
|
||||
// uniforms
|
||||
//uniform vec4 gain;
|
||||
//uniform vec4 bias;
|
||||
//uniform vec3 seed;
|
||||
uniform float scale;
|
||||
//
|
||||
//uniform vec3 lacunarity;
|
||||
//uniform vec4 decay;
|
||||
//uniform int octaves;
|
||||
uniform bool premultipliedAlpha;
|
||||
|
||||
// varyings
|
||||
in vec2 v_texCoord0;
|
||||
|
||||
// outputs
|
||||
out vec4 o_output;
|
||||
|
||||
|
||||
vec3 permute(vec3 x) {
|
||||
return mod((34.0 * x + 1.0) * x, 289.0);
|
||||
}
|
||||
|
||||
vec3 dist(vec3 x, vec3 y, bool manhattanDistance) {
|
||||
return manhattanDistance ? abs(x) + abs(y) : (x * x + y * y);
|
||||
}
|
||||
|
||||
vec2 worley(vec2 P, float jitter, bool manhattanDistance) {
|
||||
float K= 0.142857142857; // 1/7
|
||||
float Ko= 0.428571428571 ;// 3/7
|
||||
vec2 Pi = mod(floor(P), 289.0);
|
||||
vec2 Pf = fract(P);
|
||||
vec3 oi = vec3(-1.0, 0.0, 1.0);
|
||||
vec3 of = vec3(-0.5, 0.5, 1.5);
|
||||
vec3 px = permute(Pi.x + oi);
|
||||
vec3 p = permute(px.x + Pi.y + oi); // p11, p12, p13
|
||||
vec3 ox = fract(p*K) - Ko;
|
||||
vec3 oy = mod(floor(p*K),7.0)*K - Ko;
|
||||
vec3 dx = Pf.x + 0.5 + jitter*ox;
|
||||
vec3 dy = Pf.y - of + jitter*oy;
|
||||
vec3 d1 = dist(dx,dy, manhattanDistance); // d11, d12 and d13, squared
|
||||
p = permute(px.y + Pi.y + oi); // p21, p22, p23
|
||||
ox = fract(p*K) - Ko;
|
||||
oy = mod(floor(p*K),7.0)*K - Ko;
|
||||
dx = Pf.x - 0.5 + jitter*ox;
|
||||
dy = Pf.y - of + jitter*oy;
|
||||
vec3 d2 = dist(dx,dy, manhattanDistance); // d21, d22 and d23, squared
|
||||
p = permute(px.z + Pi.y + oi); // p31, p32, p33
|
||||
ox = fract(p*K) - Ko;
|
||||
oy = mod(floor(p*K),7.0)*K - Ko;
|
||||
dx = Pf.x - 1.5 + jitter*ox;
|
||||
dy = Pf.y - of + jitter*oy;
|
||||
vec3 d3 = dist(dx,dy, manhattanDistance); // d31, d32 and d33, squared
|
||||
// Sort out the two smallest distances (F1, F2)
|
||||
vec3 d1a = min(d1, d2);
|
||||
d2 = max(d1, d2); // Swap to keep candidates for F2
|
||||
d2 = min(d2, d3); // neither F1 nor F2 are now in d3
|
||||
d1 = min(d1a, d2); // F1 is now in d1
|
||||
d2 = max(d1a, d2); // Swap to keep candidates for F2
|
||||
d1.xy = (d1.x < d1.y) ? d1.xy : d1.yx; // Swap if smaller
|
||||
d1.xz = (d1.x < d1.z) ? d1.xz : d1.zx; // F1 is in d1.x
|
||||
d1.yz = min(d1.yz, d2.yz); // F2 is now not in d2.yz
|
||||
d1.y = min(d1.y, d1.z); // nor in d1.z
|
||||
d1.y = min(d1.y, d2.x); // F2 is in d1.y, we're done.
|
||||
return sqrt(d1.xy);
|
||||
}
|
||||
|
||||
|
||||
void main() {
|
||||
vec2 F = worley(v_texCoord0 * scale, 1.0, false);
|
||||
float F1 = F.x;
|
||||
float F2 = F.y;
|
||||
|
||||
o_output = vec4(vec3(F2-F1), 1.0);
|
||||
|
||||
if (premultipliedAlpha) {
|
||||
o_output.rgb *= o_output.a;
|
||||
}
|
||||
}
|
||||
29
orx-noise/src/test/kotlin/TestSimplex.kt
Normal file
29
orx-noise/src/test/kotlin/TestSimplex.kt
Normal file
@@ -0,0 +1,29 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.draw.renderTarget
|
||||
import org.openrndr.extra.gui.*
|
||||
import org.openrndr.extra.noise.filters.SimplexNoise3D
|
||||
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 1000
|
||||
height = 1000
|
||||
}
|
||||
|
||||
program {
|
||||
val gui = GUI()
|
||||
|
||||
val simplexNoise3D = SimplexNoise3D()
|
||||
val target = renderTarget(width, height) {
|
||||
colorBuffer()
|
||||
}
|
||||
|
||||
gui.add(simplexNoise3D)
|
||||
|
||||
extend(gui)
|
||||
|
||||
extend {
|
||||
simplexNoise3D.apply(target.colorBuffer(0), target.colorBuffer(0))
|
||||
drawer.image(target.colorBuffer(0))
|
||||
}
|
||||
}
|
||||
}
|
||||
30
orx-noise/src/test/kotlin/TestWorley.kt
Normal file
30
orx-noise/src/test/kotlin/TestWorley.kt
Normal file
@@ -0,0 +1,30 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.draw.renderTarget
|
||||
import org.openrndr.extra.noise.filters.CellNoise
|
||||
import org.openrndr.extra.noise.filters.WorleyNoise
|
||||
import org.openrndr.extra.gui.*
|
||||
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 1000
|
||||
height = 1000
|
||||
}
|
||||
|
||||
program {
|
||||
val gui = GUI()
|
||||
|
||||
val worleyNoise = WorleyNoise()
|
||||
val target = renderTarget(width, height) {
|
||||
colorBuffer()
|
||||
}
|
||||
|
||||
gui.add(worleyNoise)
|
||||
|
||||
extend(gui)
|
||||
|
||||
extend {
|
||||
worleyNoise.apply(target.colorBuffer(0), target.colorBuffer(0))
|
||||
drawer.image(target.colorBuffer(0))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user