MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu-shadertoys / noise

Function noise

shaders/src/clouds.rs:28–48  ·  view source on GitHub ↗
(p: Vec2)

Source from the content-addressed store, hash-verified

26}
27
28fn noise(p: Vec2) -> f32 {
29 const K1: f32 = 0.366025404; // (sqrt(3)-1)/2;
30 const K2: f32 = 0.211324865; // (3-sqrt(3))/6;
31 let i: Vec2 = (p + Vec2::splat((p.x + p.y) * K1)).floor();
32 let a: Vec2 = p - i + Vec2::splat((i.x + i.y) * K2);
33 let o: Vec2 = if a.x > a.y {
34 vec2(1.0, 0.0)
35 } else {
36 vec2(0.0, 1.0)
37 }; //vec2 of = 0.5 + 0.5*vec2(sign(a.x-a.y), sign(a.y-a.x));
38 let b: Vec2 = a - o + Vec2::splat(K2);
39 let c: Vec2 = a - Vec2::splat(1.0 - 2.0 * K2);
40 let h: Vec3 = (Vec3::splat(0.5) - vec3(a.dot(a), b.dot(b), c.dot(c))).max(Vec3::ZERO);
41 let n: Vec3 = (h * h * h * h)
42 * vec3(
43 a.dot(hash(i + Vec2::ZERO)),
44 b.dot(hash(i + o)),
45 c.dot(hash(i + Vec2::splat(1.0))),
46 );
47 n.dot(Vec3::splat(70.0))
48}
49
50fn fbm(mut n: Vec2) -> f32 {
51 let mut total: f32 = 0.0;

Callers 2

fbmFunction · 0.70
main_imageMethod · 0.70

Calls 1

hashFunction · 0.70

Tested by

no test coverage detected