Created
March 1, 2015 18:24
-
-
Save Pentan/6256f338041db69d31ab to your computer and use it in GitHub Desktop.
The mysterious random number generator that was used in Toshiya Hachisuka's seminar at Tokyo Demo Fest 2015.
This file contains hidden or 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
/* | |
The mysterious random number generator that was used in Toshiya Hachisuka's seminar at Tokyo Demo Fest 2015. | |
He said that don't know detail of this algorithm. | |
http://www.ci.i.u-tokyo.ac.jp/~hachisuka/tdf2015.pdf | |
origin (404) http://gpgpu.org/forums/viewtopic.php?t=2591&sid=17051481b9f78fb49fba5b98a5e0f1f3 | |
*/ | |
#ifdef GL_ES | |
precision mediump float; | |
#endif | |
uniform vec2 resolution; | |
uniform vec2 mouse; | |
uniform float time; | |
float GPURnd(inout vec4 state) { | |
const vec4 q = vec4( 1225.0, 1585.0, 2457.0, 2098.0); | |
const vec4 r = vec4( 1112.0, 367.0, 92.0, 265.0); | |
const vec4 a = vec4( 3423.0, 2646.0, 1707.0, 1999.0); | |
const vec4 m = vec4(4194287.0, 4194277.0, 4194191.0, 4194167.0); | |
vec4 beta = floor(state / q); | |
vec4 p = a * (state - beta * q) - beta * r; | |
beta = (sign(-p) + vec4(1.0)) * vec4(0.5) * m; | |
state = (p + beta); | |
return fract(dot(state / m, vec4(1.0, -1.0, 1.0, -1.0))); | |
} | |
float hash(float x) { | |
return fract(sin(x)*43758.5453123); | |
} | |
void main(void) { | |
vec2 uv = (gl_FragCoord.xy * 2.0 - resolution) / resolution.y; | |
vec4 st; | |
st.x = hash(uv.x); | |
st.y = hash(uv.y + st.x); | |
st.z = hash(st.x + st.y); | |
st.w = hash(time + dot(st.xyz, vec3(1.0))); | |
float n; | |
for(int i = 0; i < 4; i++) { | |
n = GPURnd(st); | |
} | |
//gl_FragColor = vec4(n, n, n, 1.0); | |
gl_FragColor = vec4(GPURnd(st), GPURnd(st), GPURnd(st), 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found at http://web.archive.org/web/20100613092208/http://gpgpu.org/forums/viewtopic.php?t=2591