mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
~ | Weird random, needs to be upgrade
This commit is contained in:
@ -1,28 +1,44 @@
|
||||
float rand_seed = 0;
|
||||
|
||||
float seed = 1.0;
|
||||
float getRandom(vec2 uv, int frameCount)
|
||||
{
|
||||
float seed = dot(uv, vec2(12.9898, 78.233)) + float(frameCount);
|
||||
return fract(sin(seed) * 43758.5453);
|
||||
}
|
||||
vec3 randomVec3(vec2 uv, int frameCount)
|
||||
{
|
||||
return vec3(
|
||||
getRandom(uv + vec2(0.1, 0.1), frameCount),
|
||||
getRandom(uv + vec2(0.2, 0.2), frameCount),
|
||||
getRandom(uv + vec2(0.3, 0.3), frameCount)
|
||||
);
|
||||
uint hash( uint x ) {
|
||||
x += ( x << 10u );
|
||||
x ^= ( x >> 6u );
|
||||
x += ( x << 3u );
|
||||
x ^= ( x >> 11u );
|
||||
x += ( x << 15u );
|
||||
return x;
|
||||
}
|
||||
|
||||
vec3 randomVec3Mixed(vec2 uv, int frameCount, float min_val, float max_val)
|
||||
uint hash( uvec2 v ) { return hash( v.x ^ hash(v.y) ); }
|
||||
uint hash( uvec3 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ); }
|
||||
uint hash( uvec4 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ^ hash(v.w) ); }
|
||||
|
||||
float floatConstruct( uint m ) {
|
||||
const uint ieeeMantissa = 0x007FFFFFu;
|
||||
const uint ieeeOne = 0x3F800000u;
|
||||
|
||||
m &= ieeeMantissa;
|
||||
m |= ieeeOne;
|
||||
|
||||
float f = uintBitsToFloat( m );
|
||||
return f - 1.0;
|
||||
}
|
||||
|
||||
|
||||
float randombis( float x ) { return floatConstruct(hash(floatBitsToUint(x))); }
|
||||
float randombis( vec2 v ) { return floatConstruct(hash(floatBitsToUint(v))); }
|
||||
float randombis( vec3 v ) { return floatConstruct(hash(floatBitsToUint(v))); }
|
||||
float randombis( vec4 v ) { return floatConstruct(hash(floatBitsToUint(v))); }
|
||||
|
||||
float random(vec2 uv, float time)
|
||||
{
|
||||
float randomX = getRandom(uv + vec2(0.1, 0.1), frameCount);
|
||||
float randomY = getRandom(uv + vec2(0.2, 0.2), frameCount);
|
||||
float randomZ = getRandom(uv + vec2(0.3, 0.3), frameCount);
|
||||
|
||||
return vec3(
|
||||
mix(min_val, max_val, randomX),
|
||||
mix(min_val, max_val, randomY),
|
||||
mix(min_val, max_val, randomZ)
|
||||
);
|
||||
}
|
||||
if (rand_seed == 0)
|
||||
rand_seed = time;
|
||||
rand_seed *= 2;
|
||||
return randombis(vec3(uv.xy, time * rand_seed));
|
||||
}
|
||||
|
||||
vec3 randomVec3(vec2 uv, float time)
|
||||
{
|
||||
return (vec3((random(uv, time) - 0.5) * 2, (random(uv, time) - 0.5) * 2, (random(uv, time) - 0.5) * 2));
|
||||
}
|
||||
|
Reference in New Issue
Block a user