Skip to content

Commit

Permalink
[orx-noise] Add uniform hash glsl phrases
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinRNDR committed Oct 21, 2024
1 parent 1b9264c commit 7f60cc5
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 0 deletions.
117 changes: 117 additions & 0 deletions orx-noise/src/commonMain/kotlin/phrases/UHash.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package org.openrndr.extra.noise.phrases

/**
* uniform hash shader phrase
*/
val uhash11 = """
#ifndef PHRASE_UHASH11
#define PHRASE_UHASH11
uint uhash11(uint x) {
uint a = x;
a = a ^ (a >> 16);
a *= 0x7feb352du;
a = a ^ (a >> 15);
a *= 0x846ca68bu;
a = a ^ (a >> 16);
return a;
}
#endif
"""

/**
* uniform hash shader phrase
*/
val fhash11 = """
$uhash11
#ifndef PHRASE_FHASH11
#define PHRASE_FHASH11
float fhash11(float x) {
uint a = uhash11(floatBitsToUint(x));
return float(a) / 4294967296.0;
}
#endif
"""

/**
* uniform hash shader phrase
*/
val uhash12 = """
$uhash11
#ifndef PHRASE_UHASH12
#define PHRASE_UHASH12
uint uhash12(uvec2 x) {
uint a = uhash11(x.y + uhash11(x.x));
return a;
}
#endif
"""

/**
* uniform hash shader phrase
*/
val fhash12 = """
$uhash12
#ifndef PHRASE_FHASH12
#define PHRASE_FHASH12
float fhash12(vec2 x) {
uint a = uhash12(floatBitsToUint(x));
return float(a) / 4294967296.0;
}
#endif
"""

/**
* uniform hash shader phrase
*/
val uhash13 = """
$uhash11
#ifndef PHRASE_UHASH13
#define PHRASE_UHASH13
uint uhash13(uvec3 x) {
uint a = uhash11(x.z + uhash11(x.y + uhash11(x.x)));
return a;
}
#endif
"""

/**
* uniform hash shader phrase
*/
val fhash13 = """
$uhash13
#ifndef PHRASE_FHASH13
#define PHRASE_FHASH13
float fhash13(vec3 x) {
uint a = uhash13(floatBitsToUint(x));
return float(a) / 4294967296.0;
}
#endif
"""

/**
* uniform hash shader phrase
*/
val uhash14 = """
$uhash11
#ifndef PHRASE_UHASH14
#define PHRASE_UHASH14
uint uhash14(uvec4 x) {
uint a = uhash11(x.w + uhash11(x.z + uhash11(x.y + uhash11(x.x))));
return a;
}
#endif
"""

/**
* uniform hash shader phrase
*/
val fhash14 = """
$uhash14
#ifndef PHRASE_FHASH14
#define PHRASE_FHASH14
float fhash14(vec4 x) {
uint a = uhash14(floatBitsToUint(x));
return float(a) / 4294967296.0;
}
#endif
"""
28 changes: 28 additions & 0 deletions orx-noise/src/jvmDemo/kotlin/phrases/DemoUHashPhrase01.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package phrases

import org.openrndr.application
import org.openrndr.draw.shadeStyle
import org.openrndr.extra.noise.phrases.*

/**
* Demonstrate uniform hashing function phrase in a shadestyle
*/
fun main() {
application {
program {
extend {
/** A custom shadestyle */
val ss = shadeStyle {
fragmentPreamble = """$fhash13"""
fragmentTransform = """
float cf = fhash13(vec3(c_screenPosition, p_time));
x_fill = vec4(cf, cf, cf, 1.0);
""".trimIndent()
parameter("time", seconds)
}
drawer.shadeStyle = ss
drawer.circle(drawer.bounds.center, 100.0)
}
}
}
}

0 comments on commit 7f60cc5

Please sign in to comment.