diff --git a/libs/pcg/include/psemek/pcg/sample.hpp b/libs/pcg/include/psemek/pcg/sample.hpp index 66940ad8..659db515 100644 --- a/libs/pcg/include/psemek/pcg/sample.hpp +++ b/libs/pcg/include/psemek/pcg/sample.hpp @@ -20,6 +20,25 @@ namespace psemek::pcg } } + template + void sample(Gen && gen, util::array & result) + { + for (std::size_t k = 0; k < result.height(); ++k) + { + for (std::size_t j = 0; j < result.height(); ++j) + { + for (std::size_t i = 0; i < result.width(); ++i) + { + float ti = (i + 0.5f) / result.width(); + float tj = (j + 0.5f) / result.height(); + float tk = (k + 0.5f) / result.depth(); + + result(i, j, k) = gen(ti, tj, tk); + } + } + } + } + template auto sample(Gen && gen, std::size_t width, std::size_t height) { @@ -31,5 +50,15 @@ namespace psemek::pcg return result; } + template + auto sample(Gen && gen, std::size_t width, std::size_t height, std::size_t depth) + { + using R = decltype(gen(0.f, 0.f, 0.f)); + + util::array result({width, height, depth}); + + sample(std::forward(gen), result); + return result; + } }