-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[orx-noise] Add uniform hash glsl phrases
- Loading branch information
Showing
2 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} |