Better hash RNG

This commit is contained in:
Joshua Barretto 2020-07-31 15:00:58 +01:00 committed by scott-c
parent 1a263834e7
commit 3f7667352d
2 changed files with 3 additions and 3 deletions

View File

@ -1,5 +1,5 @@
float hash(vec4 p) {
p = fract(p * 0.3183099 + 0.1);
p = fract(p * 0.3183099 + 0.1) - fract(p + 23.22121);
p *= 17.0;
return (fract(p.x * p.y * p.z * p.w * (p.x + p.y + p.z + p.w)) - 0.5) * 2.0;
}

View File

@ -94,10 +94,10 @@ float is_star_at(vec3 dir) {
vec3 pos = (floor(dir * star_scale) - 0.5) / star_scale;
// Noisy offsets
pos += (3.0 / star_scale) * rand_perm_3(pos);
pos += (3.0 / star_scale) * (1.0 + hash(pos.yxzz) * 0.85);
// Find distance to fragment
float dist = length(normalize(pos) - dir);
float dist = length(pos - dir);
// Star threshold
if (dist < 0.0015) {