Sphere noise functions - sample three z-slices for independent component evolution
| 92 | |
| 93 | /// Sphere noise functions - sample three z-slices for independent component evolution |
| 94 | HSV16 noiseSphereHSV16(float angle, float phi, u32 time, float radius) { |
| 95 | // Convert spherical coordinates to cartesian |
| 96 | // angle: azimuth (0 to 2π), phi: polar angle from north pole (0 to π) |
| 97 | // x = sin(phi) * cos(angle) |
| 98 | // y = sin(phi) * sin(angle) |
| 99 | // z = cos(phi) |
| 100 | float sin_phi = fl::sinf(phi); |
| 101 | float cos_phi = fl::cosf(phi); |
| 102 | float x = sin_phi * fl::cosf(angle); |
| 103 | float y = sin_phi * fl::sinf(angle); |
| 104 | float z = cos_phi; |
| 105 | |
| 106 | // Map cartesian values from [-1, 1] to [0, 0xFFFF] |
| 107 | // This ensures positive values for uint32_t conversion |
| 108 | u32 nx = static_cast<u32>((x + 1.0f) * 0.5f * radius * 0xffff); |
| 109 | u32 ny = static_cast<u32>((y + 1.0f) * 0.5f * radius * 0xffff); |
| 110 | u32 nz = static_cast<u32>((z + 1.0f) * 0.5f * radius * 0xffff); |
| 111 | |
| 112 | // Sample three different t-slices for H, S, V components |
| 113 | // Using offsets 0x0, 0x10000, 0x20000 to separate them in noise space |
| 114 | u16 h = inoise16(nx, ny, nz, time); |
| 115 | u16 s = inoise16(nx, ny, nz, time + 0x10000); |
| 116 | u16 v = inoise16(nx, ny, nz, time + 0x20000); |
| 117 | |
| 118 | return HSV16(h, s, v); |
| 119 | } |
| 120 | |
| 121 | CHSV noiseSphereHSV8(float angle, float phi, u32 time, float radius) { |
| 122 | HSV16 hsv16 = noiseSphereHSV16(angle, phi, time, radius); |
no test coverage detected