Implement in-place sampling (without allocations) in pcg
This commit is contained in:
parent
9191ab68cc
commit
66a72b89bd
1 changed files with 17 additions and 11 deletions
|
|
@ -5,6 +5,21 @@
|
||||||
namespace psemek::pcg
|
namespace psemek::pcg
|
||||||
{
|
{
|
||||||
|
|
||||||
|
template <typename Gen, typename R>
|
||||||
|
void sample(Gen && gen, gfx::basic_pixmap<R> & result)
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
|
||||||
|
result(i, j) = gen(ti, tj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Gen>
|
template <typename Gen>
|
||||||
auto sample(Gen && gen, std::size_t width, std::size_t height)
|
auto sample(Gen && gen, std::size_t width, std::size_t height)
|
||||||
{
|
{
|
||||||
|
|
@ -12,18 +27,9 @@ namespace psemek::pcg
|
||||||
|
|
||||||
gfx::basic_pixmap<R> result({width, height});
|
gfx::basic_pixmap<R> result({width, height});
|
||||||
|
|
||||||
for (std::size_t j = 0; j < height; ++j)
|
sample(std::forward<Gen>(gen), result);
|
||||||
{
|
|
||||||
for (std::size_t i = 0; i < width; ++i)
|
|
||||||
{
|
|
||||||
float ti = (i + 0.5f) / width;
|
|
||||||
float tj = (j + 0.5f) / height;
|
|
||||||
|
|
||||||
result(i, j) = gen(ti, tj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue