Last active
August 20, 2022 12:27
-
-
Save septagon/e04204d4cdd59a6c028c70de59bd62b7 to your computer and use it in GitHub Desktop.
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
RWTexture2D<float3> tex : register(u0); | |
// Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs", copied in from Wikipedia | |
uint Xorshift(uint seed) | |
{ | |
uint x = seed; | |
x ^= x << 13; | |
x ^= x >> 17; | |
x ^= x << 5; | |
return x; | |
} | |
static const float primes[13] = | |
{ | |
6143, | |
6229, | |
6311, | |
6373, | |
6481, | |
6577, | |
6679, | |
6763, | |
6841, | |
6947, | |
7001, | |
7109, | |
7211 | |
}; | |
uint ComputeSeed(uint3 DTid) | |
{ | |
return | |
DTid.x * primes[DTid.x % 13] + | |
DTid.y * primes[12 - DTid.y % 13]; | |
} | |
[numthreads(1, 1, 1)] | |
void main(uint3 DTid : SV_DispatchThreadID) | |
{ | |
uint r = Xorshift(ComputeSeed(DTid)); | |
uint g = Xorshift(r); | |
uint b = Xorshift(g); | |
tex[DTid.xy] = float3(r, g, b) / 0xFFFFFFFF; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now reimplemented for WebGL, too:
https://cyos.babylonjs.com/#DJDWJP