n/basis: add seed accessor method
This commit is contained in:
parent
83f23fe836
commit
be2317b605
@ -27,15 +27,16 @@ namespace util { namespace noise { namespace basis {
|
|||||||
template <typename T, lerp_t<T> L>
|
template <typename T, lerp_t<T> L>
|
||||||
struct perlin {
|
struct perlin {
|
||||||
perlin (seed_t);
|
perlin (seed_t);
|
||||||
perlin ();
|
|
||||||
|
|
||||||
range<T> bounds (void) const;
|
range<T> bounds (void) const;
|
||||||
constexpr T operator() (point<2,T>) const;
|
constexpr T operator() (point<2,T>) const;
|
||||||
|
|
||||||
seed_t seed;
|
constexpr seed_t seed (void) const;
|
||||||
|
seed_t seed (seed_t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
constexpr vector<2,T> gradient (point<2,intmax_t>) const;
|
constexpr vector<2,T> gradient (point<2,intmax_t>) const;
|
||||||
|
seed_t m_seed;
|
||||||
};
|
};
|
||||||
} } }
|
} } }
|
||||||
|
|
||||||
|
@ -25,14 +25,7 @@ namespace util { namespace noise { namespace basis {
|
|||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
template <typename T, util::noise::lerp_t<T> L>
|
template <typename T, util::noise::lerp_t<T> L>
|
||||||
perlin<T,L>::perlin (seed_t _seed):
|
perlin<T,L>::perlin (seed_t _seed):
|
||||||
seed (_seed)
|
m_seed (_seed)
|
||||||
{ ; }
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
template <typename T, util::noise::lerp_t<T> L>
|
|
||||||
perlin<T,L>::perlin ():
|
|
||||||
seed (time (nullptr))
|
|
||||||
{ ; }
|
{ ; }
|
||||||
|
|
||||||
|
|
||||||
@ -48,6 +41,24 @@ namespace util { namespace noise { namespace basis {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
template <typename T, lerp_t<T> L>
|
||||||
|
constexpr seed_t
|
||||||
|
perlin<T,L>::seed (void) const
|
||||||
|
{
|
||||||
|
return m_seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
template <typename T, lerp_t<T> L>
|
||||||
|
seed_t
|
||||||
|
perlin<T,L>::seed (seed_t _seed)
|
||||||
|
{
|
||||||
|
return m_seed = _seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
template <typename T, util::noise::lerp_t<T> L>
|
template <typename T, util::noise::lerp_t<T> L>
|
||||||
constexpr T
|
constexpr T
|
||||||
@ -93,8 +104,8 @@ namespace util { namespace noise { namespace basis {
|
|||||||
{
|
{
|
||||||
using util::hash::murmur2::mix;
|
using util::hash::murmur2::mix;
|
||||||
|
|
||||||
auto u = mix (seed, mix (uint64_t (p.x), uint64_t (p.y)));
|
auto u = mix (m_seed, mix (uint64_t (p.x), uint64_t (p.y)));
|
||||||
auto v = mix (u, seed);
|
auto v = mix (u, m_seed);
|
||||||
|
|
||||||
auto r = util::vector<2,T> {
|
auto r = util::vector<2,T> {
|
||||||
(u & 0xffff) / T{0xffff},
|
(u & 0xffff) / T{0xffff},
|
||||||
|
@ -27,15 +27,17 @@ namespace util { namespace noise { namespace basis {
|
|||||||
template <typename T, lerp_t<T>>
|
template <typename T, lerp_t<T>>
|
||||||
struct value {
|
struct value {
|
||||||
value (seed_t);
|
value (seed_t);
|
||||||
value ();
|
|
||||||
|
|
||||||
range<T> bounds (void) const;
|
range<T> bounds (void) const;
|
||||||
constexpr T operator() (util::point<2,T>) const;
|
constexpr T operator() (util::point<2,T>) const;
|
||||||
|
|
||||||
seed_t seed;
|
constexpr seed_t seed (void) const;
|
||||||
|
seed_t seed (seed_t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
constexpr T generate (point<2,intmax_t>) const;
|
constexpr T generate (point<2,intmax_t>) const;
|
||||||
|
|
||||||
|
seed_t m_seed;
|
||||||
};
|
};
|
||||||
} } }
|
} } }
|
||||||
|
|
||||||
|
@ -25,14 +25,7 @@ namespace util { namespace noise { namespace basis {
|
|||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
template <typename T, util::noise::lerp_t<T> L>
|
template <typename T, util::noise::lerp_t<T> L>
|
||||||
value<T,L>::value (seed_t _seed):
|
value<T,L>::value (seed_t _seed):
|
||||||
seed (_seed)
|
m_seed (_seed)
|
||||||
{ ; }
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
template <typename T, util::noise::lerp_t<T> L>
|
|
||||||
value<T,L>::value ():
|
|
||||||
seed (time (nullptr))
|
|
||||||
{ ; }
|
{ ; }
|
||||||
|
|
||||||
|
|
||||||
@ -45,6 +38,24 @@ namespace util { namespace noise { namespace basis {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
template <typename T, lerp_t<T> L>
|
||||||
|
constexpr seed_t
|
||||||
|
value<T,L>::seed (void) const
|
||||||
|
{
|
||||||
|
return m_seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
template <typename T, lerp_t<T> L>
|
||||||
|
seed_t
|
||||||
|
value<T,L>::seed (seed_t _seed)
|
||||||
|
{
|
||||||
|
return m_seed = _seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
template <typename T, util::noise::lerp_t<T> L>
|
template <typename T, util::noise::lerp_t<T> L>
|
||||||
constexpr T
|
constexpr T
|
||||||
@ -87,7 +98,7 @@ namespace util { namespace noise { namespace basis {
|
|||||||
using util::hash::murmur2::mix;
|
using util::hash::murmur2::mix;
|
||||||
|
|
||||||
T v = mix (
|
T v = mix (
|
||||||
seed,
|
m_seed,
|
||||||
mix (
|
mix (
|
||||||
uint64_t (p.y),
|
uint64_t (p.y),
|
||||||
uint64_t (p.x)
|
uint64_t (p.x)
|
||||||
|
@ -26,15 +26,16 @@ namespace util { namespace noise { namespace basis {
|
|||||||
template <typename T, size_t F = 0>
|
template <typename T, size_t F = 0>
|
||||||
struct worley {
|
struct worley {
|
||||||
worley (seed_t);
|
worley (seed_t);
|
||||||
worley ();
|
|
||||||
|
|
||||||
range<T> bounds (void) const;
|
range<T> bounds (void) const;
|
||||||
constexpr T operator() (util::point<2,T>) const;
|
constexpr T operator() (util::point<2,T>) const;
|
||||||
|
|
||||||
seed_t seed;
|
constexpr seed_t seed (void) const;
|
||||||
|
seed_t seed (seed_t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
constexpr point<2,T> generate (point<2,intmax_t>) const;
|
constexpr point<2,T> generate (point<2,intmax_t>) const;
|
||||||
|
seed_t m_seed;
|
||||||
};
|
};
|
||||||
} } }
|
} } }
|
||||||
|
|
||||||
|
@ -28,14 +28,7 @@ namespace util { namespace noise { namespace basis {
|
|||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
template <typename T, size_t F>
|
template <typename T, size_t F>
|
||||||
worley<T,F>::worley (seed_t _seed):
|
worley<T,F>::worley (seed_t _seed):
|
||||||
seed (_seed)
|
m_seed (_seed)
|
||||||
{ ; }
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
template <typename T, size_t F>
|
|
||||||
worley<T,F>::worley ():
|
|
||||||
worley (time (nullptr))
|
|
||||||
{ ; }
|
{ ; }
|
||||||
|
|
||||||
|
|
||||||
@ -48,6 +41,24 @@ namespace util { namespace noise { namespace basis {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
template <typename T, size_t F>
|
||||||
|
constexpr seed_t
|
||||||
|
worley<T,F>::seed (void) const
|
||||||
|
{
|
||||||
|
return m_seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
template <typename T, size_t F>
|
||||||
|
seed_t
|
||||||
|
worley<T,F>::seed (seed_t _seed)
|
||||||
|
{
|
||||||
|
return m_seed = _seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
template <typename T, size_t F>
|
template <typename T, size_t F>
|
||||||
constexpr T
|
constexpr T
|
||||||
@ -95,8 +106,8 @@ namespace util { namespace noise { namespace basis {
|
|||||||
{
|
{
|
||||||
using util::hash::murmur2::mix;
|
using util::hash::murmur2::mix;
|
||||||
|
|
||||||
auto u = mix (seed, mix (uint64_t (p.x), uint64_t (p.y)));
|
auto u = mix (m_seed, mix (uint64_t (p.x), uint64_t (p.y)));
|
||||||
auto v = mix (u, seed);
|
auto v = mix (u, m_seed);
|
||||||
|
|
||||||
auto r = util::point<2,T> {
|
auto r = util::point<2,T> {
|
||||||
(u & 0xffff) / T{0xffff},
|
(u & 0xffff) / T{0xffff},
|
||||||
|
@ -90,10 +90,10 @@ namespace util { namespace noise { namespace fractal {
|
|||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
//template <typename T, typename B>
|
template <typename T, typename B>
|
||||||
//typename base<T,B>::seed_t
|
typename base<T,B>::seed_t
|
||||||
//base<T,B>::seed (seed_t _seed)
|
base<T,B>::seed (seed_t _seed)
|
||||||
//{
|
{
|
||||||
// return basis.seed (_seed);
|
return m_basis.seed (_seed);
|
||||||
//}
|
}
|
||||||
} } }
|
} } }
|
||||||
|
@ -28,18 +28,18 @@ main (void)
|
|||||||
uint64_t seed = time (nullptr);
|
uint64_t seed = time (nullptr);
|
||||||
|
|
||||||
// setup the noise generator
|
// setup the noise generator
|
||||||
util::noise::fractal::fbm<float, util::noise::basis::worley<float>> b (seed);
|
//util::noise::fractal::fbm<float, util::noise::basis::worley<float>> b (seed);
|
||||||
//util::noise::fractal::rmf<float, util::noise::basis::worley<float>> b (seed);
|
//util::noise::fractal::rmf<float, util::noise::basis::worley<float>> b (seed);
|
||||||
//util::noise::fractal::fbm<float, util::noise::basis::perlin<float,util::lerp::cubic>> b (seed);
|
//util::noise::fractal::fbm<float, util::noise::basis::perlin<float,util::lerp::cubic>> b (seed);
|
||||||
//util::noise::fractal::rmf<float, util::noise::basis::perlin<float,util::lerp::cubic>> b (seed);
|
//util::noise::fractal::rmf<float, util::noise::basis::perlin<float,util::lerp::cubic>> b (seed);
|
||||||
//util::noise::fractal::hmf<float, util::noise::basis::perlin<float,util::lerp::cubic>> b (seed);
|
//util::noise::fractal::hmf<float, util::noise::basis::perlin<float,util::lerp::cubic>> b (seed);
|
||||||
//util::noise::fractal::hetero<float, util::noise::basis::value<float,util::lerp::quintic>> b (seed);
|
util::noise::fractal::hetero<float, util::noise::basis::value<float,util::lerp::quintic>> b (seed);
|
||||||
|
|
||||||
b.octaves (8);
|
b.octaves (8);
|
||||||
b.frequency (10.f / size.w);
|
b.frequency (10.f / size.w);
|
||||||
//b.lacunarity = 2.f;
|
//b.lacunarity = 2.f;
|
||||||
//b.H = 1.0f;
|
//b.H = 1.0f;
|
||||||
//b.basis.seed = time (NULL);
|
b.seed (seed);
|
||||||
|
|
||||||
// generate the values. offset positions slightly to avoid simple axis issues with perlin basis
|
// generate the values. offset positions slightly to avoid simple axis issues with perlin basis
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user