Skip to content

Instantly share code, notes, and snippets.

@deltaluca
Created October 26, 2013 23:14
Show Gist options
  • Save deltaluca/7175732 to your computer and use it in GitHub Desktop.
Save deltaluca/7175732 to your computer and use it in GitHub Desktop.
#ifndef WORLEYNOISE_H
#define WORLEYNOISE_H
#include <dynarray>
#include <vector>
#include <noise/noise.h>
#include <util/spatialcache.h>
#include <util/fastmath.h>
/**
* Worley noise implementation on an unbounded grid in any dimension.
*
* Functions return scalars in [0,1] but require help in determining
* a suitable mapping of values to this range.
*/
namespace noise
{
static inline float32_t intNoise(int32_t n)
{
n = (n >> 13) ^ n;
n = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
return static_cast<float32_t>(static_cast<float64_t>(n) / 2147483648.0);
}
template <size_t Dim>
class Worley : public ScalarNoise<Dim>
{
public:
const size_t cellCount;
struct Component
{
size_t k;
float32_t power;
float32_t multiplier;
};
...
#ifndef JS_WORLEYNOISE_H
#define JS_WORLEYNOISE_H
#include <v8interop/noise/noise.h>
#include <noise/worley.h>
namespace v8interop { namespace noise
{
namespace worley
{
void init(v8::Handle<v8::Object> exports);
}
// node/v8 wrapper of Worley noise
template <size_t Dim>
class Worley : public ScalarNoise<Dim>
{
Worley(const std::vector<::noise::Worley<Dim>::Component>& cs,
const std::array<float32_t, 2>& bounds):
ScalarNoise<Dim>(::noise::Worley<Dim>(cs, bounds))
{
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment