File shaders/white_noise.glsl changed (mode: 100644) (index cdb1f32..9032974) |
17 |
17 |
* along with this library. If not, see <https://www.gnu.org/licenses/> |
* along with this library. If not, see <https://www.gnu.org/licenses/> |
18 |
18 |
*/ |
*/ |
19 |
19 |
#include "hash.glsl" |
#include "hash.glsl" |
20 |
|
|
|
|
20 |
|
#ifndef HASH_FOO |
|
21 |
|
#error hash function is not defined |
|
22 |
|
#endif |
21 |
23 |
const int PRIMES[] = {1619, 6971, 31337, 193939}; |
const int PRIMES[] = {1619, 6971, 31337, 193939}; |
22 |
24 |
|
|
23 |
25 |
float white_noise(int seed, float x) { |
float white_noise(int seed, float x) { |
24 |
26 |
int hash = PRIMES[0] * (floatBitsToInt(x) ^ (floatBitsToInt(x) >> 16)); |
int hash = PRIMES[0] * (floatBitsToInt(x) ^ (floatBitsToInt(x) >> 16)); |
25 |
|
return hash_float(seed ^ hash); |
|
|
27 |
|
int a = seed ^ hash; |
|
28 |
|
return float_normalized_from_hash(HASH_FOO(a)); |
26 |
29 |
} |
} |
27 |
30 |
float white_noise(int seed, vec2 c) { |
float white_noise(int seed, vec2 c) { |
28 |
31 |
ivec2 hash; |
ivec2 hash; |
29 |
32 |
hash.x = PRIMES[0] * (floatBitsToInt(c.x) ^ (floatBitsToInt(c.x) >> 16)); |
hash.x = PRIMES[0] * (floatBitsToInt(c.x) ^ (floatBitsToInt(c.x) >> 16)); |
30 |
33 |
hash.y = PRIMES[1] * (floatBitsToInt(c.y) ^ (floatBitsToInt(c.y) >> 16)); |
hash.y = PRIMES[1] * (floatBitsToInt(c.y) ^ (floatBitsToInt(c.y) >> 16)); |
31 |
|
return hash_float(seed ^ hash.x ^ hash.y); |
|
|
34 |
|
int a = seed ^ hash.x ^ hash.y; |
|
35 |
|
return float_normalized_from_hash(HASH_FOO(a)); |
32 |
36 |
} |
} |
33 |
37 |
float white_noise(int seed, vec3 c) { |
float white_noise(int seed, vec3 c) { |
34 |
38 |
ivec3 hash; |
ivec3 hash; |
35 |
39 |
hash.x = PRIMES[0] * (floatBitsToInt(c.x) ^ (floatBitsToInt(c.x) >> 16)); |
hash.x = PRIMES[0] * (floatBitsToInt(c.x) ^ (floatBitsToInt(c.x) >> 16)); |
36 |
40 |
hash.y = PRIMES[1] * (floatBitsToInt(c.y) ^ (floatBitsToInt(c.y) >> 16)); |
hash.y = PRIMES[1] * (floatBitsToInt(c.y) ^ (floatBitsToInt(c.y) >> 16)); |
37 |
41 |
hash.z = PRIMES[2] * (floatBitsToInt(c.z) ^ (floatBitsToInt(c.z) >> 16)); |
hash.z = PRIMES[2] * (floatBitsToInt(c.z) ^ (floatBitsToInt(c.z) >> 16)); |
38 |
|
return hash_float(seed ^ hash.x ^ hash.y ^ hash.z); |
|
|
42 |
|
int a = seed ^ hash.x ^ hash.y ^ hash.z; |
|
43 |
|
return float_normalized_from_hash(HASH_FOO(a)); |
39 |
44 |
} |
} |
40 |
45 |
float white_noise(int seed, vec4 c) { |
float white_noise(int seed, vec4 c) { |
41 |
46 |
ivec4 hash; |
ivec4 hash; |
|
... |
... |
ivec4 hash; |
43 |
48 |
hash.y = PRIMES[1] * (floatBitsToInt(c.y) ^ (floatBitsToInt(c.y) >> 16)); |
hash.y = PRIMES[1] * (floatBitsToInt(c.y) ^ (floatBitsToInt(c.y) >> 16)); |
44 |
49 |
hash.z = PRIMES[2] * (floatBitsToInt(c.z) ^ (floatBitsToInt(c.z) >> 16)); |
hash.z = PRIMES[2] * (floatBitsToInt(c.z) ^ (floatBitsToInt(c.z) >> 16)); |
45 |
50 |
hash.w = PRIMES[3] * (floatBitsToInt(c.w) ^ (floatBitsToInt(c.w) >> 16)); |
hash.w = PRIMES[3] * (floatBitsToInt(c.w) ^ (floatBitsToInt(c.w) >> 16)); |
46 |
|
return hash_float(seed ^ hash.x ^ hash.y ^ hash.z ^ hash.w); |
|
|
51 |
|
int a = seed ^ hash.x ^ hash.y ^ hash.z ^ hash.w; |
|
52 |
|
return float_normalized_from_hash(HASH_FOO(a)); |
47 |
53 |
} |
} |
File src/noise_main.cpp changed (mode: 100644) (index 5b692a3..dcbce2f) |
... |
... |
simd_simplex(u32 size, float step, i32 seed, f32 *p_dst) |
86 |
86 |
template<simd::Level L> |
template<simd::Level L> |
87 |
87 |
simd::pfloat<L> |
simd::pfloat<L> |
88 |
88 |
white_simd(simd::pint<L> seed, jm::vector<1, simd::pfloat<L>> pos) { |
white_simd(simd::pint<L> seed, jm::vector<1, simd::pfloat<L>> pos) { |
89 |
|
return noise::white<L>(seed, pos.x); |
|
|
89 |
|
return noise::white<L, noise::hash_fast<L>>(seed, pos.x); |
90 |
90 |
} |
} |
91 |
91 |
template<simd::Level L> |
template<simd::Level L> |
92 |
92 |
simd::pfloat<L> |
simd::pfloat<L> |
93 |
93 |
white_simd(simd::pint<L> seed, jm::vector<2, simd::pfloat<L>> pos) { |
white_simd(simd::pint<L> seed, jm::vector<2, simd::pfloat<L>> pos) { |
94 |
|
return noise::white<L>(seed, pos.x, pos.y); |
|
|
94 |
|
return noise::white<L, noise::hash_fast<L>>(seed, pos.x, pos.y); |
95 |
95 |
} |
} |
96 |
96 |
template<simd::Level L> |
template<simd::Level L> |
97 |
97 |
simd::pfloat<L> |
simd::pfloat<L> |
98 |
98 |
white_simd(simd::pint<L> seed, jm::vector<3, simd::pfloat<L>> pos) { |
white_simd(simd::pint<L> seed, jm::vector<3, simd::pfloat<L>> pos) { |
99 |
|
return noise::white<L>(seed, pos.x, pos.y, pos.z); |
|
|
99 |
|
return noise::white<L, noise::hash_fast<L>>(seed, pos.x, pos.y, pos.z); |
100 |
100 |
} |
} |
101 |
101 |
template<simd::Level L> |
template<simd::Level L> |
102 |
102 |
simd::pfloat<L> |
simd::pfloat<L> |
103 |
103 |
white_simd(simd::pint<L> seed, jm::vector<4, simd::pfloat<L>> pos) { |
white_simd(simd::pint<L> seed, jm::vector<4, simd::pfloat<L>> pos) { |
104 |
|
return noise::white<L>(seed, pos.x, pos.y, pos.z, pos.w); |
|
|
104 |
|
return noise::white<L, noise::hash_fast<L>>(seed, pos.x, pos.y, pos.z, pos.w); |
105 |
105 |
} |
} |
106 |
106 |
template<simd::Level L, int D> |
template<simd::Level L, int D> |
107 |
107 |
void white_simd(u32 size, float step, i32 seed, f32 *p_dst) { |
void white_simd(u32 size, float step, i32 seed, f32 *p_dst) { |