#pragma once #include #include "Common.hpp" namespace Math::Random { std::array break_float(F32 f); F32 to_float(U8 u); U8 hash(U8 x); Real random(); template struct Noise { Real at(Vector pos) const { U8 to_hash[D * 4]; for (Int i = 0; i < D; i++) { auto b = break_float(pos[i]); to_hash[i*4] = b[0]; to_hash[i*4+1] = b[1]; to_hash[i*4+2] = b[2]; to_hash[i*4+3] = b[3]; } U8 h = 0; for (Int i = 0; i < D * 4; i++) { h = hash(h) + to_hash[i]; } return to_float(h); } }; }