Support sampling 3D texture generators
This commit is contained in:
parent
f3184a0f62
commit
b7fdc4959e
1 changed files with 29 additions and 0 deletions
|
|
@ -20,6 +20,25 @@ namespace psemek::pcg
|
|||
}
|
||||
}
|
||||
|
||||
template <typename Gen, typename R>
|
||||
void sample(Gen && gen, util::array<R, 3> & 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 <typename Gen>
|
||||
auto sample(Gen && gen, std::size_t width, std::size_t height)
|
||||
{
|
||||
|
|
@ -31,5 +50,15 @@ namespace psemek::pcg
|
|||
return result;
|
||||
}
|
||||
|
||||
template <typename Gen>
|
||||
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<R, 3> result({width, height, depth});
|
||||
|
||||
sample(std::forward<Gen>(gen), result);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue