Add seamless perlin noise
This commit is contained in:
parent
1cfdde033b
commit
3705dac55e
3 changed files with 28 additions and 0 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <psemek/gfx/pixmap.hpp>
|
||||
#include <psemek/geom/vector.hpp>
|
||||
#include <psemek/pcg/seamless.hpp>
|
||||
|
||||
namespace psemek::pcg
|
||||
{
|
||||
|
|
@ -10,6 +11,7 @@ namespace psemek::pcg
|
|||
{
|
||||
perlin() = default;
|
||||
perlin(gfx::basic_pixmap<geom::vector<float, 2>> grad_map);
|
||||
perlin(gfx::basic_pixmap<geom::vector<float, 2>> const & grad_map, seamless_tag);
|
||||
perlin(perlin &&) = default;
|
||||
|
||||
perlin & operator = (perlin &&) = default;
|
||||
|
|
|
|||
10
libs/pcg/include/psemek/pcg/seamless.hpp
Normal file
10
libs/pcg/include/psemek/pcg/seamless.hpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
namespace psemek::pcg
|
||||
{
|
||||
|
||||
struct seamless_tag{};
|
||||
|
||||
constexpr seamless_tag seamless;
|
||||
|
||||
}
|
||||
|
|
@ -11,6 +11,22 @@ namespace psemek::pcg
|
|||
: grad_map_(std::move(grad_map))
|
||||
{}
|
||||
|
||||
perlin::perlin(gfx::basic_pixmap<geom::vector<float, 2>> const & grad_map, seamless_tag)
|
||||
{
|
||||
auto const w = grad_map.width();
|
||||
auto const h = grad_map.height();
|
||||
|
||||
grad_map_.resize({w + 1, h + 1});
|
||||
|
||||
for (std::size_t j = 0; j <= h; ++j)
|
||||
{
|
||||
for (std::size_t i = 0; i <= w; ++i)
|
||||
{
|
||||
grad_map_(i, j) = grad_map(i % w, j % h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static float step(float x0, float x1, float t)
|
||||
{
|
||||
return x0 * (1.f - t) + x1 * t;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue