Noise: Refresh module using ZNoise
https://github.com/Overdrivr/ZNoise Former-commit-id: 3f7be1c8fd14e074826ca667676412ea4989621c [formerly 882d0bdad12c264766dc00869ac07bbecbee7306] Former-commit-id: b12a4654bb5b9ff3fdd474704d66aa10fd2d756d
This commit is contained in:
parent
752fd3d4d2
commit
81245a9c43
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ABSTRACT2DNOISE_HPP
|
||||
#define NAZARA_ABSTRACT2DNOISE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/MappedNoiseBase.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API Abstract2DNoise : public MappedNoiseBase
|
||||
{
|
||||
public:
|
||||
virtual ~Abstract2DNoise();
|
||||
|
||||
float GetBasicValue(float x, float y);
|
||||
float GetMappedValue(float x, float y);
|
||||
virtual float GetValue(float x, float y, float resolution) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_ABSTRACT2DNOISE_HPP
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ABSTRACT3DNOISE_HPP
|
||||
#define NAZARA_ABSTRACT3DNOISE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/MappedNoiseBase.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API Abstract3DNoise : public MappedNoiseBase
|
||||
{
|
||||
public:
|
||||
virtual ~Abstract3DNoise();
|
||||
|
||||
float GetBasicValue(float x, float y, float z);
|
||||
float GetMappedValue(float x, float y, float z);
|
||||
virtual float GetValue(float x, float y, float z, float resolution) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_ABSTRACT3DNOISE_HPP
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ABSTRACT4DNOISE_HPP
|
||||
#define NAZARA_ABSTRACT4DNOISE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/MappedNoiseBase.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API Abstract4DNoise : public MappedNoiseBase
|
||||
{
|
||||
public:
|
||||
virtual ~Abstract4DNoise();
|
||||
|
||||
float GetBasicValue(float x, float y, float z, float w);
|
||||
float GetMappedValue(float x, float y, float z, float w);
|
||||
virtual float GetValue(float x, float y, float z, float w, float resolution) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_ABSTRACT4DNOISE_HPP
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef COMPLEXNOISEBASE_HPP
|
||||
#define COMPLEXNOISEBASE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <array>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API ComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
ComplexNoiseBase();
|
||||
~ComplexNoiseBase() = default;
|
||||
|
||||
float GetHurstParameter() const;
|
||||
float GetLacunarity() const;
|
||||
float GetOctaveNumber() const;
|
||||
void SetHurstParameter(float h);
|
||||
void SetLacunarity(float lacunarity);
|
||||
void SetOctavesNumber(float octaves);
|
||||
void RecomputeExponentArray();
|
||||
|
||||
protected:
|
||||
float m_lacunarity;
|
||||
float m_hurst;
|
||||
float m_octaves;
|
||||
std::array<float, 30> m_exponent_array;
|
||||
float m_sum;
|
||||
|
||||
private:
|
||||
bool m_parametersModified;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // COMPLEXNOISEBASE_HPP
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Nazara Engine - Noise module
|
||||
|
||||
Copyright (C) 2015 Rémi "Overdrivr" Bèges (remi.beges@laposte.net)
|
||||
Copyright (C) 2016 Rémi "Overdrivr" Bèges (remi.beges@laposte.net)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#ifndef NAZARA_ENUMS_NOISE_HPP
|
||||
#define NAZARA_ENUMS_NOISE_HPP
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
enum WorleyFunction
|
||||
{
|
||||
WorleyFunction_F1 = 0,
|
||||
WorleyFunction_F2 = 1,
|
||||
WorleyFunction_F3 = 2,
|
||||
WorleyFunction_F4 = 3
|
||||
};
|
||||
}
|
||||
#endif // NAZARA_ENUMS_NOISE_HPP
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#ifndef NAZARA_FBM_HPP
|
||||
#define NAZARA_FBM_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/Enums.hpp>
|
||||
#include <Nazara/Noise/MixerBase.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API FBM : public MixerBase
|
||||
{
|
||||
public:
|
||||
FBM(const NoiseBase& source);
|
||||
FBM(const FBM&) = delete;
|
||||
~FBM() = default;
|
||||
|
||||
float Get(std::initializer_list<float> coordinates, float scale) const;
|
||||
|
||||
FBM& operator=(const FBM&) = delete;
|
||||
|
||||
private:
|
||||
const NoiseBase& m_source;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_FBM_HPP
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef FBM2D_HPP
|
||||
#define FBM2D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/ComplexNoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract2DNoise.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API FBM2D : public Abstract2DNoise, public ComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
FBM2D(NoiseType source, unsigned int seed);
|
||||
float GetValue(float x, float y, float resolution);
|
||||
~FBM2D();
|
||||
|
||||
private:
|
||||
Abstract2DNoise* m_source;
|
||||
float m_value;
|
||||
float m_remainder;
|
||||
NoiseType m_noiseType;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // FBM2D_HPP
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef FBM3D_HPP
|
||||
#define FBM3D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/ComplexNoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract3DNoise.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API FBM3D : public Abstract3DNoise, public ComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
FBM3D(NoiseType source, unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float resolution);
|
||||
~FBM3D();
|
||||
|
||||
private:
|
||||
Abstract3DNoise* m_source;
|
||||
float m_value;
|
||||
float m_remainder;
|
||||
NoiseType m_noiseType;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // FBM3D_HPP
|
||||
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef FBM4D_HPP
|
||||
#define FBM4D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/ComplexNoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract4DNoise.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API FBM4D : public Abstract4DNoise, public ComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
FBM4D(NoiseType source, unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float w, float resolution);
|
||||
~FBM4D();
|
||||
|
||||
private:
|
||||
Abstract4DNoise* m_source;
|
||||
float m_value;
|
||||
float m_remainder;
|
||||
NoiseType m_noiseType;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // FBM4D_HPP
|
||||
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#ifndef NAZARA_HYBRIDMULTIFRACTAL_HPP
|
||||
#define NAZARA_HYBRIDMULTIFRACTAL_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/MixerBase.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API HybridMultiFractal : public MixerBase
|
||||
{
|
||||
public:
|
||||
HybridMultiFractal(const NoiseBase & source);
|
||||
HybridMultiFractal(const HybridMultiFractal&) = delete;
|
||||
~HybridMultiFractal() = default;
|
||||
|
||||
float Get(std::initializer_list<float> coordinates, float scale) const;
|
||||
|
||||
HybridMultiFractal& operator=(const HybridMultiFractal&) = delete;
|
||||
|
||||
private:
|
||||
const NoiseBase& m_source;
|
||||
float m_value;
|
||||
float m_remainder;
|
||||
float m_offset;
|
||||
float m_weight;
|
||||
float m_signal;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_HYBRIDMULTIFRACTAL_HPP
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef HYBRIDMULTIFRACTAL2D_HPP
|
||||
#define HYBRIDMULTIFRACTAL2D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/ComplexNoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract2DNoise.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API HybridMultiFractal2D : public Abstract2DNoise, public ComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
HybridMultiFractal2D(NoiseType source, unsigned int seed);
|
||||
~HybridMultiFractal2D();
|
||||
|
||||
float GetValue(float x, float y, float resolution);
|
||||
|
||||
private:
|
||||
Abstract2DNoise* m_source;
|
||||
float m_value;
|
||||
float m_remainder;
|
||||
float m_offset;
|
||||
float m_weight;
|
||||
float m_signal;
|
||||
NoiseType m_noiseType;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // HYBRIDMULTIFRACTAL2D_HPP
|
||||
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef HYBRIDMULTIFRACTAL3D_HPP
|
||||
#define HYBRIDMULTIFRACTAL3D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/ComplexNoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract3DNoise.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API HybridMultiFractal3D : public Abstract3DNoise, public ComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
HybridMultiFractal3D(NoiseType source, unsigned int seed);
|
||||
~HybridMultiFractal3D();
|
||||
|
||||
float GetValue(float x, float y, float z, float resolution);
|
||||
|
||||
private:
|
||||
Abstract3DNoise* m_source;
|
||||
float m_value;
|
||||
float m_remainder;
|
||||
float m_offset;
|
||||
float m_weight;
|
||||
float m_signal;
|
||||
NoiseType m_noiseType;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // HYBRIDMULTIFRACTAL3D_HPP
|
||||
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef HYBRIDMULTIFRACTAL4D_HPP
|
||||
#define HYBRIDMULTIFRACTAL4D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/ComplexNoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract4DNoise.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API HybridMultiFractal4D : public Abstract4DNoise, public ComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
HybridMultiFractal4D(NoiseType source, unsigned int seed);
|
||||
~HybridMultiFractal4D();
|
||||
|
||||
float GetValue(float x, float y, float z, float w, float resolution);
|
||||
|
||||
private:
|
||||
Abstract4DNoise* m_source;
|
||||
float m_value;
|
||||
float m_remainder;
|
||||
float m_offset;
|
||||
float m_weight;
|
||||
float m_signal;
|
||||
NoiseType m_noiseType;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // HYBRIDMULTIFRACTAL4D_HPP
|
||||
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_MAPPEDNOISEBASE_HPP
|
||||
#define NAZARA_MAPPEDNOISEBASE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API MappedNoiseBase : public NoiseBase
|
||||
{
|
||||
public:
|
||||
MappedNoiseBase();
|
||||
~MappedNoiseBase() = default;
|
||||
|
||||
float GetGain() const;
|
||||
float GetOffset() const;
|
||||
float GetResolution() const;
|
||||
void SetGain(float gain);
|
||||
void SetOffset(float offset);
|
||||
void SetResolution(float resolution);
|
||||
|
||||
protected:
|
||||
float m_gain;
|
||||
float m_offset;
|
||||
float m_resolution;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_MAPPEDNOISEBASE_HPP
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#ifndef NAZARA_MIXERBASE_HPP
|
||||
#define NAZARA_MIXERBASE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <array>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API MixerBase
|
||||
{
|
||||
public:
|
||||
MixerBase();
|
||||
~MixerBase() = default;
|
||||
|
||||
float GetHurstParameter() const;
|
||||
float GetLacunarity() const;
|
||||
float GetOctaveNumber() const;
|
||||
|
||||
void SetParameters(float hurst, float lacunarity, float octaves);
|
||||
|
||||
protected:
|
||||
float m_hurst;
|
||||
float m_lacunarity;
|
||||
float m_octaves;
|
||||
std::vector<float> m_exponent_array;
|
||||
float m_sum;
|
||||
|
||||
private:
|
||||
void Recompute();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_MIXERBASE_HPP
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
|
|
|
|||
|
|
@ -1,48 +1,38 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NOISEBASE_HPP
|
||||
#define NOISEBASE_HPP
|
||||
#ifndef NAZARA_NOISEBASE_HPP
|
||||
#define NAZARA_NOISEBASE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <random>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
enum NoiseType
|
||||
{
|
||||
PERLIN,
|
||||
SIMPLEX,
|
||||
CELL
|
||||
};
|
||||
|
||||
class NAZARA_NOISE_API NoiseBase
|
||||
{
|
||||
public:
|
||||
NoiseBase(unsigned int seed = 0);
|
||||
~NoiseBase() = default;
|
||||
|
||||
void SetNewSeed(unsigned int seed);
|
||||
virtual float Get(std::initializer_list<float> coordinates, float scale) const = 0;
|
||||
float GetScale();
|
||||
|
||||
void ShufflePermutationTable();
|
||||
void SetScale(float scale);
|
||||
void SetSeed(unsigned int seed);
|
||||
|
||||
unsigned int GetUniformRandomValue();
|
||||
|
||||
int fastfloor(float n);
|
||||
int JenkinsHash(int a, int b, int c);
|
||||
void Shuffle();
|
||||
void Shuffle(unsigned int amount);
|
||||
|
||||
protected:
|
||||
unsigned int perm[512];
|
||||
float m_scale;
|
||||
|
||||
private:
|
||||
unsigned int Ua, Uc, Um;
|
||||
unsigned int UcurrentSeed;
|
||||
unsigned int Uprevious, Ulast;
|
||||
|
||||
std::default_random_engine generator;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NOISEBASE_HPP
|
||||
#endif // NAZARA_NOISEBASE_HPP
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#ifndef NAZARA_NOISETOOLS_HPP
|
||||
#define NAZARA_NOISETOOLS_HPP
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
int fastfloor(float n);
|
||||
int JenkinsHash(int a, int b, int c);
|
||||
}
|
||||
|
||||
#endif // NAZARA_NOISETOOLS_HPP
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#ifndef NAZARA_PERLIN_HPP
|
||||
#define NAZARA_PERLIN_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <initializer_list>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API Perlin : public NoiseBase
|
||||
{
|
||||
public:
|
||||
Perlin();
|
||||
Perlin(unsigned int seed);
|
||||
~Perlin() = default;
|
||||
|
||||
float Get(std::initializer_list<float> coordinates, float scale) const;
|
||||
|
||||
protected:
|
||||
float _2D(std::initializer_list<float> coordinates, float scale) const;
|
||||
float _3D(std::initializer_list<float> coordinates, float scale) const;
|
||||
float _4D(std::initializer_list<float> coordinates, float scale) const;
|
||||
|
||||
private:
|
||||
const float gradient2[8][2];
|
||||
const float gradient3[16][3];
|
||||
const float gradient4[32][4];
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PERLIN_HPP
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef PERLIN2D_HPP
|
||||
#define PERLIN2D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract2DNoise.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API Perlin2D : public Abstract2DNoise
|
||||
{
|
||||
public:
|
||||
Perlin2D();
|
||||
Perlin2D(unsigned int seed);
|
||||
~Perlin2D() = default;
|
||||
|
||||
float GetValue(float x, float y, float resolution);
|
||||
|
||||
private:
|
||||
int x0, y0;
|
||||
int gi0,gi1,gi2,gi3;
|
||||
int ii, jj;
|
||||
float gradient2[8][2];
|
||||
float s,t,u,v;
|
||||
float Cx,Cy;
|
||||
float Li1, Li2;
|
||||
Vector2<float> temp;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // PERLIN2D_HPP
|
||||
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef PERLIN3D_HPP
|
||||
#define PERLIN3D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract3DNoise.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API Perlin3D : public Abstract3DNoise
|
||||
{
|
||||
public:
|
||||
Perlin3D();
|
||||
Perlin3D(unsigned int seed);
|
||||
~Perlin3D() = default;
|
||||
|
||||
float GetValue(float x, float y, float z, float resolution);
|
||||
|
||||
private:
|
||||
int x0,y0,z0;
|
||||
int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7;
|
||||
int ii,jj,kk;
|
||||
float gradient3[16][3];
|
||||
float Li1,Li2,Li3,Li4,Li5,Li6;
|
||||
float s[2],t[2],u[2],v[2];
|
||||
float Cx,Cy,Cz;
|
||||
float nx,ny,nz;
|
||||
float tmp;
|
||||
Vector3<float> temp;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // PERLIN3D_HPP
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef PERLIN4D_HPP
|
||||
#define PERLIN4D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract4DNoise.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API Perlin4D : public Abstract4DNoise
|
||||
{
|
||||
public:
|
||||
Perlin4D();
|
||||
Perlin4D(unsigned int seed);
|
||||
~Perlin4D() = default;
|
||||
|
||||
float GetValue(float x, float y, float z, float w, float resolution);
|
||||
|
||||
private:
|
||||
int x0,y0,z0,w0;
|
||||
int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7,gi8,gi9,gi10,gi11,gi12,gi13,gi14,gi15;
|
||||
int ii,jj,kk,ll;
|
||||
float gradient4[32][4];
|
||||
float Li1,Li2,Li3,Li4,Li5,Li6,Li7,Li8,Li9,Li10,Li11,Li12,Li13,Li14;
|
||||
float s[4],t[4],u[4],v[4];
|
||||
float Cx,Cy,Cz,Cw;
|
||||
float tmp;
|
||||
Vector4<float> temp;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // PERLIN4D_HPP
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#ifndef SIMPLEX_HPP
|
||||
#define SIMPLE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <initializer_list>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API Simplex : public NoiseBase
|
||||
{
|
||||
public:
|
||||
Simplex();
|
||||
Simplex(unsigned int seed);
|
||||
~Simplex() = default;
|
||||
|
||||
float Get(std::initializer_list<float> coordinates, float scale) const;
|
||||
|
||||
protected:
|
||||
float _2D(std::initializer_list<float> coordinates, float scale) const;
|
||||
float _3D(std::initializer_list<float> coordinates, float scale) const;
|
||||
float _4D(std::initializer_list<float> coordinates, float scale) const;
|
||||
|
||||
private:
|
||||
const float gradient2[8][2];
|
||||
const float gradient3[16][3];
|
||||
const float gradient4[32][4];
|
||||
const float UnskewCoeff2D;
|
||||
const float SkewCoeff2D;
|
||||
const float UnskewCoeff3D;
|
||||
const float SkewCoeff3D;
|
||||
const float UnskewCoeff4D;
|
||||
const float SkewCoeff4D;
|
||||
const int lookupTable4D[64][4];
|
||||
};
|
||||
}
|
||||
|
||||
#endif // SIMPLEX_HPP
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef SIMPLEX2D_HPP
|
||||
#define SIMPLEX2D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract2DNoise.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API Simplex2D : public Abstract2DNoise
|
||||
{
|
||||
public:
|
||||
Simplex2D();
|
||||
Simplex2D(unsigned int seed);
|
||||
virtual ~Simplex2D() = default;
|
||||
|
||||
float GetValue(float x, float y, float resolution);
|
||||
|
||||
private:
|
||||
int ii,jj;
|
||||
int gi0,gi1,gi2;
|
||||
Vector2i skewedCubeOrigin,off1;
|
||||
float n1,n2,n3;
|
||||
float c1,c2,c3;
|
||||
float gradient2[8][2];
|
||||
float UnskewCoeff2D;
|
||||
float SkewCoeff2D;
|
||||
float sum;
|
||||
Vector2<float> unskewedCubeOrigin, unskewedDistToOrigin;
|
||||
Vector2<float> d1,d2,d3;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // SIMPLEX2D_HPP
|
||||
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef SIMPLEX3D_HPP
|
||||
#define SIMPLEX3D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract3DNoise.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API Simplex3D : public Abstract3DNoise
|
||||
{
|
||||
public:
|
||||
Simplex3D();
|
||||
Simplex3D(unsigned int seed);
|
||||
~Simplex3D() = default;
|
||||
|
||||
float GetValue(float x, float y, float z, float resolution);
|
||||
|
||||
private:
|
||||
int ii,jj,kk;
|
||||
int gi0,gi1,gi2,gi3;
|
||||
Vector3i skewedCubeOrigin,off1,off2;
|
||||
float n1,n2,n3,n4;
|
||||
float c1,c2,c3,c4;
|
||||
float gradient3[12][3];
|
||||
float UnskewCoeff3D;
|
||||
float SkewCoeff3D;
|
||||
float sum;
|
||||
Vector3<float> unskewedCubeOrigin, unskewedDistToOrigin;
|
||||
Vector3<float> d1,d2,d3,d4;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // SIMPLEX3D_HPP
|
||||
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef SIMPLEX4D_HPP
|
||||
#define SIMPLEX4D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract4DNoise.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API Simplex4D : public Abstract4DNoise
|
||||
{
|
||||
public:
|
||||
Simplex4D();
|
||||
Simplex4D(unsigned int seed);
|
||||
~Simplex4D() = default;
|
||||
|
||||
float GetValue(float x, float y, float z, float w, float resolution);
|
||||
|
||||
private:
|
||||
int ii,jj,kk,ll;
|
||||
int gi0,gi1,gi2,gi3,gi4;
|
||||
Vector4i skewedCubeOrigin,off1,off2,off3;
|
||||
int lookupTable4D[64][4];
|
||||
int c;
|
||||
float n1,n2,n3,n4,n5;
|
||||
float c1,c2,c3,c4,c5,c6;
|
||||
float gradient4[32][4];
|
||||
float UnskewCoeff4D;
|
||||
float SkewCoeff4D;
|
||||
float sum;
|
||||
Vector4<float> unskewedCubeOrigin, unskewedDistToOrigin;
|
||||
Vector4<float> d1,d2,d3,d4,d5;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // SIMPLEX4D_H
|
||||
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#ifndef NAZARA_WORLEY_HPP
|
||||
#define NAZARA_WORLEY_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Enums.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <initializer_list>
|
||||
#include <map>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NOISE_API Worley : public NoiseBase
|
||||
{
|
||||
public:
|
||||
Worley();
|
||||
Worley(unsigned int seed);
|
||||
~Worley() = default;
|
||||
|
||||
void Set(WorleyFunction func);
|
||||
|
||||
float Get(std::initializer_list<float> coordinates, float scale) const;
|
||||
|
||||
protected:
|
||||
float _2D(std::initializer_list<float> coordinates, float scale) const;
|
||||
float _3D(std::initializer_list<float> coordinates, float scale) const;
|
||||
float _4D(std::initializer_list<float> coordinates, float scale) const;
|
||||
void _SquareTest(int xi, int yi, float x, float y, std::map<float, Vector2f> & featurePoints) const;
|
||||
|
||||
private:
|
||||
const float scales[4];
|
||||
WorleyFunction function;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_WORLEY_HPP
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Abstract2DNoise.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Abstract2DNoise::~Abstract2DNoise() = default;
|
||||
|
||||
float Abstract2DNoise::GetBasicValue(float x, float y)
|
||||
{
|
||||
return this->GetValue(x,y,m_resolution);
|
||||
}
|
||||
|
||||
float Abstract2DNoise::GetMappedValue(float x, float y)
|
||||
{
|
||||
return (this->GetValue(x,y,m_resolution) + m_offset) * m_gain;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Abstract3DNoise.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Abstract3DNoise::~Abstract3DNoise() = default;
|
||||
|
||||
float Abstract3DNoise::GetBasicValue(float x, float y, float z)
|
||||
{
|
||||
return this->GetValue(x,y,z,m_resolution);
|
||||
}
|
||||
|
||||
float Abstract3DNoise::GetMappedValue(float x, float y, float z)
|
||||
{
|
||||
return (this->GetValue(x,y,z,m_resolution) + m_offset) * m_gain ;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Abstract4DNoise.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Abstract4DNoise::~Abstract4DNoise() = default;
|
||||
|
||||
float Abstract4DNoise::GetBasicValue(float x, float y, float z, float w)
|
||||
{
|
||||
return this->GetValue(x,y,z,w,m_resolution);
|
||||
}
|
||||
|
||||
float Abstract4DNoise::GetMappedValue(float x, float y, float z, float w)
|
||||
{
|
||||
return (this->GetValue(x,y,z,w,m_resolution) + m_offset) * m_gain ;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <cmath>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/ComplexNoiseBase.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
ComplexNoiseBase::ComplexNoiseBase()
|
||||
{
|
||||
m_parametersModified = true;
|
||||
m_lacunarity = 5.0f;
|
||||
m_hurst = 1.2f;
|
||||
m_octaves = 3.0f;
|
||||
|
||||
for (int i(0) ; i < m_octaves; ++i)
|
||||
{
|
||||
m_exponent_array[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
float ComplexNoiseBase::GetLacunarity() const
|
||||
{
|
||||
|
||||
return m_lacunarity;
|
||||
}
|
||||
|
||||
float ComplexNoiseBase::GetHurstParameter() const
|
||||
{
|
||||
return m_hurst;
|
||||
}
|
||||
|
||||
float ComplexNoiseBase::GetOctaveNumber() const
|
||||
{
|
||||
return m_octaves;
|
||||
}
|
||||
|
||||
void ComplexNoiseBase::SetLacunarity(float lacunarity)
|
||||
{
|
||||
m_lacunarity = lacunarity;
|
||||
m_parametersModified = true;
|
||||
|
||||
}
|
||||
|
||||
void ComplexNoiseBase::SetHurstParameter(float h)
|
||||
{
|
||||
m_hurst = h;
|
||||
m_parametersModified = true;
|
||||
}
|
||||
|
||||
void ComplexNoiseBase::SetOctavesNumber(float octaves)
|
||||
{
|
||||
if(octaves <= 30.0f)
|
||||
m_octaves = octaves;
|
||||
else
|
||||
m_octaves = 30.0f;
|
||||
|
||||
m_parametersModified = true;
|
||||
}
|
||||
|
||||
void ComplexNoiseBase::RecomputeExponentArray()
|
||||
{
|
||||
if(m_parametersModified)
|
||||
{
|
||||
float frequency = 1.0;
|
||||
m_sum = 0.f;
|
||||
for (int i(0) ; i < static_cast<int>(m_octaves) ; ++i)
|
||||
{
|
||||
|
||||
m_exponent_array[i] = std::pow( frequency, -m_hurst );
|
||||
frequency *= m_lacunarity;
|
||||
|
||||
m_sum += m_exponent_array[i];
|
||||
|
||||
}
|
||||
m_parametersModified = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Noise/FBM.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
FBM::FBM(const NoiseBase & source): m_source(source)
|
||||
{
|
||||
}
|
||||
|
||||
float FBM::Get(std::initializer_list<float> coordinates, float scale) const
|
||||
{
|
||||
float value = 0.0;
|
||||
|
||||
for(int i(0); i < m_octaves; ++i)
|
||||
{
|
||||
value += m_source.Get(coordinates,scale) * m_exponent_array.at(i);
|
||||
scale *= m_lacunarity;
|
||||
}
|
||||
|
||||
float remainder = m_octaves - static_cast<int>(m_octaves);
|
||||
|
||||
if(std::fabs(remainder) > 0.01f)
|
||||
value += remainder * m_source.Get(coordinates,scale) * m_exponent_array.at(static_cast<int>(m_octaves-1));
|
||||
|
||||
return value / m_sum;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/FBM2D.hpp>
|
||||
#include <Nazara/Noise/Perlin2D.hpp>
|
||||
#include <Nazara/Noise/Simplex2D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
FBM2D::FBM2D(NoiseType source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
case PERLIN:
|
||||
m_source = new Perlin2D();
|
||||
break;
|
||||
|
||||
default:
|
||||
m_source = new Simplex2D();
|
||||
break;
|
||||
}
|
||||
m_source->SetNewSeed(seed);
|
||||
m_source->ShufflePermutationTable();
|
||||
m_noiseType = source;
|
||||
}
|
||||
|
||||
float FBM2D::GetValue(float x, float y, float resolution)
|
||||
{
|
||||
this->RecomputeExponentArray();
|
||||
|
||||
m_value = 0.0;
|
||||
|
||||
for (int i(0); i < m_octaves; ++i)
|
||||
{
|
||||
m_value += m_source->GetValue(x,y,resolution) * m_exponent_array[i];
|
||||
resolution *= m_lacunarity;
|
||||
}
|
||||
m_remainder = m_octaves - static_cast<int>(m_octaves);
|
||||
|
||||
if(!NumberEquals(m_remainder, static_cast<float>(0.0)))
|
||||
m_value += m_remainder * m_source->GetValue(x,y,resolution) * m_exponent_array[static_cast<int>(m_octaves-1)];
|
||||
|
||||
return m_value/this->m_sum;
|
||||
}
|
||||
|
||||
FBM2D::~FBM2D()
|
||||
{
|
||||
delete m_source;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/FBM3D.hpp>
|
||||
#include <Nazara/Noise/Perlin3D.hpp>
|
||||
#include <Nazara/Noise/Simplex3D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
FBM3D::FBM3D(NoiseType source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
case PERLIN:
|
||||
m_source = new Perlin3D();
|
||||
break;
|
||||
|
||||
default:
|
||||
m_source = new Simplex3D();
|
||||
break;
|
||||
}
|
||||
m_source->SetNewSeed(seed);
|
||||
m_source->ShufflePermutationTable();
|
||||
m_noiseType = source;
|
||||
}
|
||||
|
||||
float FBM3D::GetValue(float x, float y, float z, float resolution)
|
||||
{
|
||||
this->RecomputeExponentArray();
|
||||
|
||||
m_value = 0.0;
|
||||
|
||||
for (int i(0); i < m_octaves; ++i)
|
||||
{
|
||||
m_value += m_source->GetValue(x,y,z,resolution) * m_exponent_array[i];
|
||||
resolution *= m_lacunarity;
|
||||
}
|
||||
m_remainder = m_octaves - static_cast<int>(m_octaves);
|
||||
|
||||
if(!NumberEquals(m_remainder, static_cast<float>(0.0)))
|
||||
m_value += m_remainder * m_source->GetValue(x,y,z,resolution) * m_exponent_array[static_cast<int>(m_octaves-1)];
|
||||
|
||||
return m_value/this->m_sum;
|
||||
}
|
||||
|
||||
FBM3D::~FBM3D()
|
||||
{
|
||||
delete m_source;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/FBM4D.hpp>
|
||||
#include <Nazara/Noise/Perlin4D.hpp>
|
||||
#include <Nazara/Noise/Simplex4D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
FBM4D::FBM4D(NoiseType source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
case PERLIN:
|
||||
m_source = new Perlin4D();
|
||||
break;
|
||||
|
||||
default:
|
||||
m_source = new Simplex4D();
|
||||
break;
|
||||
}
|
||||
m_source->SetNewSeed(seed);
|
||||
m_source->ShufflePermutationTable();
|
||||
m_noiseType = source;
|
||||
}
|
||||
|
||||
float FBM4D::GetValue(float x, float y, float z, float w, float resolution)
|
||||
{
|
||||
this->RecomputeExponentArray();
|
||||
|
||||
m_value = 0.0;
|
||||
|
||||
for (int i(0); i < m_octaves; ++i)
|
||||
{
|
||||
m_value += m_source->GetValue(x,y,z,w,resolution) * m_exponent_array[i];
|
||||
resolution *= m_lacunarity;
|
||||
}
|
||||
m_remainder = m_octaves - static_cast<int>(m_octaves);
|
||||
|
||||
if(!NumberEquals(m_remainder, static_cast<float>(0.0)))
|
||||
m_value += m_remainder * m_source->GetValue(x,y,z,w,resolution) * m_exponent_array[static_cast<int>(m_octaves-1)];
|
||||
|
||||
return m_value/this->m_sum;
|
||||
}
|
||||
|
||||
FBM4D::~FBM4D()
|
||||
{
|
||||
delete m_source;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Noise/HybridMultiFractal.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
HybridMultiFractal::HybridMultiFractal(const NoiseBase & source) :
|
||||
m_source(source)
|
||||
{
|
||||
}
|
||||
|
||||
float HybridMultiFractal::Get(std::initializer_list<float> coordinates, float scale) const
|
||||
{
|
||||
float offset = 1.0f;
|
||||
float value = (m_source.Get(coordinates,scale) + offset) * m_exponent_array.at(0);
|
||||
float weight = value;
|
||||
float signal = 0.f;
|
||||
|
||||
scale *= m_lacunarity;
|
||||
|
||||
for(int i(1) ; i < m_octaves; ++i)
|
||||
{
|
||||
if (weight > 1.f)
|
||||
weight = 1.f;
|
||||
|
||||
signal = (m_source.Get(coordinates,scale) + offset) * m_exponent_array.at(i);
|
||||
value += weight * signal;
|
||||
weight *= signal;
|
||||
scale *= m_lacunarity;
|
||||
}
|
||||
|
||||
float remainder = m_octaves - static_cast<int>(m_octaves);
|
||||
|
||||
if (remainder > 0.f)
|
||||
value += remainder * m_source.Get(coordinates,scale) * m_exponent_array.at(static_cast<int>(m_octaves-1));
|
||||
|
||||
return value / m_sum - offset;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/HybridMultiFractal3D.hpp>
|
||||
#include <Nazara/Noise/Perlin3D.hpp>
|
||||
#include <Nazara/Noise/Simplex3D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
HybridMultiFractal3D::HybridMultiFractal3D(NoiseType source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
case PERLIN:
|
||||
m_source = new Perlin3D();
|
||||
break;
|
||||
|
||||
default:
|
||||
m_source = new Simplex3D();
|
||||
break;
|
||||
}
|
||||
m_source->SetNewSeed(seed);
|
||||
m_source->ShufflePermutationTable();
|
||||
m_noiseType = source;
|
||||
}
|
||||
|
||||
float HybridMultiFractal3D::GetValue(float x, float y, float z, float resolution)
|
||||
{
|
||||
this->RecomputeExponentArray();
|
||||
|
||||
m_offset = 1.0f;
|
||||
|
||||
m_value = (m_source->GetValue(x,y,z,resolution) + m_offset) * m_exponent_array[0];
|
||||
m_weight = m_value;
|
||||
m_signal = 0.f;
|
||||
|
||||
resolution *= m_lacunarity;
|
||||
|
||||
for(int i(1) ; i < m_octaves; ++i)
|
||||
{
|
||||
if (m_weight > 1.f)
|
||||
m_weight = 1.f;
|
||||
|
||||
m_signal = (m_source->GetValue(x,y,z,resolution) + m_offset) * m_exponent_array[i];
|
||||
m_value += m_weight * m_signal;
|
||||
|
||||
m_weight *= m_signal;
|
||||
|
||||
resolution *= m_lacunarity;
|
||||
}
|
||||
|
||||
m_remainder = m_octaves - static_cast<int>(m_octaves);
|
||||
if (m_remainder > 0.f)
|
||||
m_value += m_remainder * m_source->GetValue(x,y,z,resolution) * m_exponent_array[static_cast<int>(m_octaves-1)];
|
||||
|
||||
return m_value/this->m_sum - m_offset;
|
||||
}
|
||||
|
||||
HybridMultiFractal3D::~HybridMultiFractal3D()
|
||||
{
|
||||
delete m_source;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/HybridMultiFractal4D.hpp>
|
||||
#include <Nazara/Noise/Perlin4D.hpp>
|
||||
#include <Nazara/Noise/Simplex4D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
HybridMultiFractal4D::HybridMultiFractal4D(NoiseType source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
case PERLIN:
|
||||
m_source = new Perlin4D();
|
||||
break;
|
||||
|
||||
default:
|
||||
m_source = new Simplex4D();
|
||||
break;
|
||||
}
|
||||
m_source->SetNewSeed(seed);
|
||||
m_source->ShufflePermutationTable();
|
||||
m_noiseType = source;
|
||||
}
|
||||
|
||||
float HybridMultiFractal4D::GetValue(float x, float y, float z, float w, float resolution)
|
||||
{
|
||||
this->RecomputeExponentArray();
|
||||
|
||||
m_offset = 1.0f;
|
||||
|
||||
m_value = (m_source->GetValue(x,y,z,w,resolution) + m_offset) * m_exponent_array[0];
|
||||
m_weight = m_value;
|
||||
m_signal = 0.f;
|
||||
|
||||
resolution *= m_lacunarity;
|
||||
|
||||
for(int i(1) ; i < m_octaves; ++i)
|
||||
{
|
||||
if (m_weight > 1.f)
|
||||
m_weight = 1.f;
|
||||
|
||||
m_signal = (m_source->GetValue(x,y,z,w,resolution) + m_offset) * m_exponent_array[i];
|
||||
m_value += m_weight * m_signal;
|
||||
|
||||
m_weight *= m_signal;
|
||||
|
||||
resolution *= m_lacunarity;
|
||||
}
|
||||
|
||||
m_remainder = m_octaves - static_cast<int>(m_octaves);
|
||||
if (m_remainder > 0.f)
|
||||
m_value += m_remainder * m_source->GetValue(x,y,z,w,resolution) * m_exponent_array[static_cast<int>(m_octaves-1)];
|
||||
|
||||
return m_value/this->m_sum - m_offset;
|
||||
}
|
||||
|
||||
HybridMultiFractal4D::~HybridMultiFractal4D()
|
||||
{
|
||||
delete m_source;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/HybridMultiFractal2D.hpp>
|
||||
#include <Nazara/Noise/Perlin2D.hpp>
|
||||
#include <Nazara/Noise/Simplex2D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
HybridMultiFractal2D::HybridMultiFractal2D(NoiseType source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
case PERLIN:
|
||||
m_source = new Perlin2D();
|
||||
break;
|
||||
|
||||
default:
|
||||
m_source = new Simplex2D();
|
||||
break;
|
||||
}
|
||||
m_source->SetNewSeed(seed);
|
||||
m_source->ShufflePermutationTable();
|
||||
m_noiseType = source;
|
||||
}
|
||||
|
||||
float HybridMultiFractal2D::GetValue(float x, float y, float resolution)
|
||||
{
|
||||
this->RecomputeExponentArray();
|
||||
|
||||
m_offset = 1.0f;
|
||||
|
||||
m_value = (m_source->GetValue(x,y,resolution) + m_offset) * m_exponent_array[0];
|
||||
m_weight = m_value;
|
||||
m_signal = 0.f;
|
||||
|
||||
resolution *= m_lacunarity;
|
||||
|
||||
for(int i(1) ; i < m_octaves; ++i)
|
||||
{
|
||||
if (m_weight > 1.f)
|
||||
m_weight = 1.f;
|
||||
|
||||
m_signal = (m_source->GetValue(x,y,resolution) + m_offset) * m_exponent_array[i];
|
||||
m_value += m_weight * m_signal;
|
||||
|
||||
m_weight *= m_signal;
|
||||
|
||||
resolution *= m_lacunarity;
|
||||
}
|
||||
|
||||
m_remainder = m_octaves - static_cast<int>(m_octaves);
|
||||
if (m_remainder > 0.f)
|
||||
m_value += m_remainder * m_source->GetValue(x,y,resolution) * m_exponent_array[static_cast<int>(m_octaves-1)];
|
||||
|
||||
return m_value/this->m_sum - m_offset;
|
||||
}
|
||||
|
||||
HybridMultiFractal2D::~HybridMultiFractal2D()
|
||||
{
|
||||
delete m_source;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Noise/MappedNoiseBase.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
MappedNoiseBase::MappedNoiseBase() : m_gain(1.f), m_offset(0.f), m_resolution(30.f)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float MappedNoiseBase::GetGain() const
|
||||
{
|
||||
return m_gain;
|
||||
}
|
||||
|
||||
float MappedNoiseBase::GetOffset() const
|
||||
{
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
float MappedNoiseBase::GetResolution() const
|
||||
{
|
||||
return m_resolution;
|
||||
}
|
||||
|
||||
void MappedNoiseBase::SetGain(float gain)
|
||||
{
|
||||
m_gain = gain;
|
||||
}
|
||||
|
||||
void MappedNoiseBase::SetOffset(float offset)
|
||||
{
|
||||
m_offset = offset;
|
||||
}
|
||||
|
||||
void MappedNoiseBase::SetResolution(float resolution)
|
||||
{
|
||||
if (NumberEquals(resolution, 0.f))
|
||||
{
|
||||
StringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << " : resolution cannot be 0.0f";
|
||||
|
||||
throw std::domain_error(ss.ToString());
|
||||
}
|
||||
m_resolution = resolution;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Noise/MixerBase.hpp>
|
||||
#include <cmath>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
MixerBase::MixerBase() :
|
||||
m_hurst(1.2f),
|
||||
m_lacunarity(5.f),
|
||||
m_octaves(3.f)
|
||||
{
|
||||
Recompute();
|
||||
}
|
||||
|
||||
float MixerBase::GetHurstParameter() const
|
||||
{
|
||||
return m_hurst;
|
||||
}
|
||||
|
||||
float MixerBase::GetLacunarity() const
|
||||
{
|
||||
return m_lacunarity;
|
||||
}
|
||||
|
||||
float MixerBase::GetOctaveNumber() const
|
||||
{
|
||||
return m_octaves;
|
||||
}
|
||||
|
||||
void MixerBase::SetParameters(float hurst, float lacunarity, float octaves)
|
||||
{
|
||||
m_hurst = hurst;
|
||||
m_lacunarity = lacunarity;
|
||||
m_octaves = octaves;
|
||||
|
||||
Recompute();
|
||||
}
|
||||
|
||||
void MixerBase::Recompute()
|
||||
{
|
||||
float frequency = 1.0;
|
||||
m_sum = 0.f;
|
||||
m_exponent_array.clear();
|
||||
|
||||
for (int i(0) ; i < static_cast<int>(m_octaves) ; ++i)
|
||||
{
|
||||
m_exponent_array.push_back(std::pow( frequency, -m_hurst ));
|
||||
frequency *= m_lacunarity;
|
||||
m_sum += m_exponent_array.at(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +1,37 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
NoiseBase::NoiseBase(unsigned int seed)
|
||||
{
|
||||
Ua = 16807;
|
||||
Uc = 0;
|
||||
Um = 2147483647;
|
||||
UcurrentSeed = 0;
|
||||
Uprevious = 0;
|
||||
SetSeed(seed);
|
||||
m_scale = 0.05f;
|
||||
|
||||
SetNewSeed(seed);
|
||||
|
||||
for(int i(0) ; i < 512 ; i++)
|
||||
for(unsigned int i(0) ; i < 512; ++i)
|
||||
perm[i] = i & 255;
|
||||
|
||||
}
|
||||
|
||||
void NoiseBase::SetNewSeed(unsigned int seed)
|
||||
float NoiseBase::GetScale()
|
||||
{
|
||||
Uprevious = seed;
|
||||
UcurrentSeed = seed;
|
||||
return m_scale;
|
||||
}
|
||||
|
||||
unsigned int NoiseBase::GetUniformRandomValue()
|
||||
void NoiseBase::SetScale(float scale)
|
||||
{
|
||||
Ulast = Ua*Uprevious + Uc%Um;
|
||||
Uprevious = Ulast;
|
||||
return Ulast;
|
||||
m_scale = scale;
|
||||
}
|
||||
|
||||
void NoiseBase::ShufflePermutationTable()
|
||||
void NoiseBase::SetSeed(unsigned int seed)
|
||||
{
|
||||
generator.seed(seed);
|
||||
}
|
||||
|
||||
void NoiseBase::Shuffle()
|
||||
{
|
||||
int xchanger;
|
||||
unsigned int ncase;
|
||||
|
|
@ -45,35 +39,21 @@ namespace Nz
|
|||
for(unsigned int i(0) ; i < 256 ; i++)
|
||||
perm[i] = i;
|
||||
|
||||
for(unsigned int j(0) ; j < 20 ; ++j)
|
||||
for (unsigned int i(0); i < 256 ; ++i)
|
||||
{
|
||||
ncase = this->GetUniformRandomValue() & 255;
|
||||
xchanger = perm[i];
|
||||
perm[i] = perm[ncase];
|
||||
perm[ncase] = xchanger;
|
||||
}
|
||||
for (unsigned int i(0); i < 256 ; ++i)
|
||||
{
|
||||
ncase = generator() & 255;
|
||||
xchanger = perm[i];
|
||||
perm[i] = perm[ncase];
|
||||
perm[ncase] = xchanger;
|
||||
}
|
||||
|
||||
for(unsigned int i(256) ; i < 512; ++i)
|
||||
perm[i] = perm[i & 255];
|
||||
}
|
||||
|
||||
int NoiseBase::fastfloor(float n)
|
||||
void NoiseBase::Shuffle(unsigned int amount)
|
||||
{
|
||||
return (n >= 0) ? static_cast<int>(n) : static_cast<int>(n-1);
|
||||
}
|
||||
|
||||
int NoiseBase::JenkinsHash(int a, int b, int c)
|
||||
{
|
||||
a = a-b; a = a - c; a = a^(static_cast<unsigned int>(c) >> 13);
|
||||
b = b-c; b = b - a; b = b^(a << 8);
|
||||
c = c-a; c = c - b; c = c^(static_cast<unsigned int>(b) >> 13);
|
||||
a = a-b; a = a - c; a = a^(static_cast<unsigned int>(c) >> 12);
|
||||
b = b-c; b = b - a; b = b^(a << 16);
|
||||
c = c-a; c = c - b; c = c^(static_cast<unsigned int>(b) >> 5);
|
||||
a = a-b; a = a - c; a = a^(static_cast<unsigned int>(c) >> 3);
|
||||
b = b-c; b = b - a; b = b^(a << 10);
|
||||
c = c-a; c = c - b; c = c^(static_cast<unsigned int>(b) >> 15);
|
||||
return c;
|
||||
for(unsigned int j(0) ; j < amount ; ++j)
|
||||
Shuffle();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Noise/NoiseTools.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
int fastfloor(float n)
|
||||
{
|
||||
return (n >= 0) ? static_cast<int>(n) : static_cast<int>(n-1);
|
||||
}
|
||||
|
||||
int JenkinsHash(int a, int b, int c)
|
||||
{
|
||||
a = a-b; a = a - c; a = a^(static_cast<unsigned int>(c) >> 13);
|
||||
b = b-c; b = b - a; b = b^(a << 8);
|
||||
c = c-a; c = c - b; c = c^(static_cast<unsigned int>(b) >> 13);
|
||||
a = a-b; a = a - c; a = a^(static_cast<unsigned int>(c) >> 12);
|
||||
b = b-c; b = b - a; b = b^(a << 16);
|
||||
c = c-a; c = c - b; c = c^(static_cast<unsigned int>(b) >> 5);
|
||||
a = a-b; a = a - c; a = a^(static_cast<unsigned int>(c) >> 3);
|
||||
b = b-c; b = b - a; b = b^(a << 10);
|
||||
c = c-a; c = c - b; c = c^(static_cast<unsigned int>(b) >> 15);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,325 @@
|
|||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Noise/Perlin.hpp>
|
||||
#include <Nazara/Noise/NoiseTools.hpp>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Perlin::Perlin() :
|
||||
gradient2{
|
||||
{1.f,1.f},{-1.f,1.f},{1.f,-1.f},{-1.f,-1.f},
|
||||
{1.f,0.f},{-1.f,0.f},{0.f,1.f},{0.f,-1.f}
|
||||
},
|
||||
gradient3{
|
||||
{1,1,0},{-1,1,0},{1,-1,0},{-1,-1,0},
|
||||
{1,0,1},{-1,0,1},{1,0,-1},{-1,0,-1},
|
||||
{0,1,1},{0,-1,1},{0,1,-1},{0,-1,-1},
|
||||
{1,1,0},{-1,1,0},{0,-1,1},{0,-1,-1}
|
||||
},
|
||||
gradient4{
|
||||
{0,1,1,1}, {0,1,1,-1}, {0,1,-1,1}, {0,1,-1,-1},
|
||||
{0,-1,1,1},{0,-1,1,-1},{0,-1,-1,1},{0,-1,-1,-1},
|
||||
{1,0,1,1}, {1,0,1,-1}, {1,0,-1,1}, {1,0,-1,-1},
|
||||
{-1,0,1,1},{-1,0,1,-1},{-1,0,-1,1},{-1,0,-1,-1},
|
||||
{1,1,0,1}, {1,1,0,-1}, {1,-1,0,1}, {1,-1,0,-1},
|
||||
{-1,1,0,1},{-1,1,0,-1},{-1,-1,0,1},{-1,-1,0,-1},
|
||||
{1,1,1,0}, {1,1,-1,0}, {1,-1,1,0}, {1,-1,-1,0},
|
||||
{-1,1,1,0},{-1,1,-1,0},{-1,-1,1,0},{-1,-1,-1,0}
|
||||
}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Perlin::Perlin(unsigned int seed) : Perlin()
|
||||
{
|
||||
SetSeed(seed);
|
||||
Shuffle();
|
||||
}
|
||||
|
||||
float Perlin::Get(std::initializer_list<float> coordinates, float scale) const
|
||||
{
|
||||
switch(coordinates.size())
|
||||
{
|
||||
case 2:
|
||||
return this->_2D(coordinates,scale);
|
||||
case 3:
|
||||
return this->_3D(coordinates,scale);
|
||||
case 4:
|
||||
return this->_4D(coordinates,scale);
|
||||
default:
|
||||
throw std::invalid_argument("Number of coordinates elements not comprised between 2 and 4");
|
||||
}
|
||||
}
|
||||
|
||||
float Perlin::_2D(std::initializer_list<float> coordinates, float scale) const
|
||||
{
|
||||
thread_local float xc, yc;
|
||||
thread_local int x0, y0;
|
||||
thread_local int gi0,gi1,gi2,gi3;
|
||||
thread_local int ii, jj;
|
||||
|
||||
thread_local float s,t,u,v;
|
||||
thread_local float Cx,Cy;
|
||||
thread_local float Li1, Li2;
|
||||
thread_local float tempx,tempy;
|
||||
|
||||
std::initializer_list<float>::const_iterator it = coordinates.begin();
|
||||
|
||||
xc = *(it ) * scale;
|
||||
yc = *(++it) * scale;
|
||||
|
||||
x0 = fastfloor(xc);
|
||||
y0 = fastfloor(yc);
|
||||
|
||||
ii = x0 & 255;
|
||||
jj = y0 & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj]] & 7;
|
||||
gi1 = perm[ii + 1 + perm[jj]] & 7;
|
||||
gi2 = perm[ii + perm[jj + 1]] & 7;
|
||||
gi3 = perm[ii + 1 + perm[jj + 1]] & 7;
|
||||
|
||||
tempx = xc - x0;
|
||||
tempy = yc - y0;
|
||||
|
||||
Cx = tempx * tempx * tempx * (tempx * (tempx * 6 - 15) + 10);
|
||||
Cy = tempy * tempy * tempy * (tempy * (tempy * 6 - 15) + 10);
|
||||
|
||||
s = gradient2[gi0][0]*tempx + gradient2[gi0][1]*tempy;
|
||||
|
||||
tempx = xc - (x0 + 1);
|
||||
t = gradient2[gi1][0]*tempx + gradient2[gi1][1]*tempy;
|
||||
|
||||
tempy = yc - (y0 + 1);
|
||||
v = gradient2[gi3][0]*tempx + gradient2[gi3][1]*tempy;
|
||||
|
||||
tempx = xc - x0;
|
||||
u = gradient2[gi2][0]*tempx + gradient2[gi2][1]*tempy;
|
||||
|
||||
Li1 = s + Cx*(t-s);
|
||||
Li2 = u + Cx*(v-u);
|
||||
|
||||
return Li1 + Cy*(Li2-Li1);
|
||||
}
|
||||
|
||||
float Perlin::_3D(std::initializer_list<float> coordinates, float scale) const
|
||||
{
|
||||
thread_local float xc, yc, zc;
|
||||
thread_local int x0, y0, z0;
|
||||
thread_local int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7;
|
||||
thread_local int ii, jj, kk;
|
||||
|
||||
thread_local float Li1,Li2,Li3,Li4,Li5,Li6;
|
||||
thread_local float s[2],t[2],u[2],v[2];
|
||||
thread_local float Cx,Cy,Cz;
|
||||
thread_local float nx,ny,nz;
|
||||
|
||||
thread_local float tmp;
|
||||
thread_local float tempx,tempy,tempz;
|
||||
|
||||
std::initializer_list<float>::const_iterator it = coordinates.begin();
|
||||
|
||||
xc = *(it ) * scale;
|
||||
yc = *(++it) * scale;
|
||||
zc = *(++it) * scale;
|
||||
|
||||
x0 = fastfloor(xc);
|
||||
y0 = fastfloor(yc);
|
||||
z0 = fastfloor(zc);
|
||||
|
||||
ii = x0 & 255;
|
||||
jj = y0 & 255;
|
||||
kk = z0 & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj + perm[kk]]] & 15;
|
||||
gi1 = perm[ii + 1 + perm[jj + perm[kk]]] & 15;
|
||||
gi2 = perm[ii + perm[jj + 1 + perm[kk]]] & 15;
|
||||
gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk]]] & 15;
|
||||
|
||||
gi4 = perm[ii + perm[jj + perm[kk + 1]]] & 15;
|
||||
gi5 = perm[ii + 1 + perm[jj + perm[kk + 1]]] & 15;
|
||||
gi6 = perm[ii + perm[jj + 1 + perm[kk + 1]]] & 15;
|
||||
gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] & 15;
|
||||
|
||||
tempx = xc - x0;
|
||||
tempy = yc - y0;
|
||||
tempz = zc - z0;
|
||||
|
||||
Cx = tempx * tempx * tempx * (tempx * (tempx * 6 - 15) + 10);
|
||||
Cy = tempy * tempy * tempy * (tempy * (tempy * 6 - 15) + 10);
|
||||
Cz = tempz * tempz * tempz * (tempz * (tempz * 6 - 15) + 10);
|
||||
|
||||
s[0] = gradient3[gi0][0]*tempx + gradient3[gi0][1]*tempy + gradient3[gi0][2]*tempz;
|
||||
|
||||
tempx = xc - (x0 + 1);
|
||||
t[0] = gradient3[gi1][0]*tempx + gradient3[gi1][1]*tempy + gradient3[gi1][2]*tempz;
|
||||
|
||||
tempy = yc - (y0 + 1);
|
||||
v[0] = gradient3[gi3][0]*tempx + gradient3[gi3][1]*tempy + gradient3[gi3][2]*tempz;
|
||||
|
||||
tempx = xc - x0;
|
||||
u[0] = gradient3[gi2][0]*tempx + gradient3[gi2][1]*tempy + gradient3[gi2][2]*tempz;
|
||||
|
||||
tempy = yc - y0;
|
||||
tempz = zc - (z0 + 1);
|
||||
s[1] = gradient3[gi4][0]*tempx + gradient3[gi4][1]*tempy + gradient3[gi4][2]*tempz;
|
||||
|
||||
tempx = xc - (x0 + 1);
|
||||
t[1] = gradient3[gi5][0]*tempx + gradient3[gi5][1]*tempy + gradient3[gi5][2]*tempz;
|
||||
|
||||
tempy = yc - (y0 + 1);
|
||||
v[1] = gradient3[gi7][0]*tempx + gradient3[gi7][1]*tempy + gradient3[gi7][2]*tempz;
|
||||
|
||||
tempx = xc - x0;
|
||||
u[1] = gradient3[gi6][0]*tempx + gradient3[gi6][1]*tempy + gradient3[gi6][2]*tempz;
|
||||
|
||||
Li1 = s[0] + Cx*(t[0]-s[0]);
|
||||
Li2 = u[0] + Cx*(v[0]-u[0]);
|
||||
Li3 = s[1] + Cx*(t[1]-s[1]);
|
||||
Li4 = u[1] + Cx*(v[1]-u[1]);
|
||||
|
||||
Li5 = Li1 + Cy * (Li2-Li1);
|
||||
Li6 = Li3 + Cy * (Li4-Li3);
|
||||
|
||||
return Li5 + Cz * (Li6-Li5);
|
||||
}
|
||||
|
||||
float Perlin::_4D(std::initializer_list<float> coordinates, float scale) const
|
||||
{
|
||||
thread_local float xc,yc,zc,wc;
|
||||
thread_local int x0,y0,z0,w0;
|
||||
thread_local int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7,gi8,gi9,gi10,gi11,gi12,gi13,gi14,gi15;
|
||||
thread_local int ii,jj,kk,ll;
|
||||
|
||||
thread_local float Li1,Li2,Li3,Li4,Li5,Li6,Li7,Li8,Li9,Li10,Li11,Li12,Li13,Li14;
|
||||
thread_local float s[4],t[4],u[4],v[4];
|
||||
thread_local float Cx,Cy,Cz,Cw;
|
||||
|
||||
thread_local float tmp;
|
||||
thread_local float tempx,tempy,tempz,tempw;
|
||||
|
||||
std::initializer_list<float>::const_iterator it = coordinates.begin();
|
||||
|
||||
xc = *(it ) * scale;
|
||||
yc = *(++it) * scale;
|
||||
zc = *(++it) * scale;
|
||||
wc = *(++it) * scale;
|
||||
|
||||
x0 = fastfloor(xc);
|
||||
y0 = fastfloor(yc);
|
||||
z0 = fastfloor(zc);
|
||||
w0 = fastfloor(wc);
|
||||
|
||||
ii = x0 & 255;
|
||||
jj = y0 & 255;
|
||||
kk = z0 & 255;
|
||||
ll = w0 & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj + perm[kk + perm[ll]]]] & 31;
|
||||
gi1 = perm[ii + 1 + perm[jj + perm[kk + perm[ll]]]] & 31;
|
||||
gi2 = perm[ii + perm[jj + 1 + perm[kk + perm[ll]]]] & 31;
|
||||
gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll]]]] & 31;
|
||||
|
||||
gi4 = perm[ii + perm[jj + + perm[kk + 1 + perm[ll]]]] & 31;
|
||||
gi5 = perm[ii + 1 + perm[jj + + perm[kk + 1 + perm[ll]]]] & 31;
|
||||
gi6 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll]]]] & 31;
|
||||
gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll]]]] & 31;
|
||||
|
||||
gi8 = perm[ii + perm[jj + perm[kk + perm[ll + 1]]]] & 31;
|
||||
gi9 = perm[ii + 1 + perm[jj + perm[kk + perm[ll + 1]]]] & 31;
|
||||
gi10 = perm[ii + perm[jj + 1 + perm[kk + perm[ll + 1]]]] & 31;
|
||||
gi11 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll + 1]]]] & 31;
|
||||
|
||||
gi12 = perm[ii + perm[jj + perm[kk + 1 + perm[ll + 1]]]] & 31;
|
||||
gi13 = perm[ii + 1 + perm[jj + perm[kk + 1 + perm[ll + 1]]]] & 31;
|
||||
gi14 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] & 31;
|
||||
gi15 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] & 31;
|
||||
|
||||
tempx = xc - x0;
|
||||
tempy = yc - y0;
|
||||
tempz = zc - z0;
|
||||
tempw = wc - w0;
|
||||
|
||||
Cx = tempx * tempx * tempx * (tempx * (tempx * 6 - 15) + 10);
|
||||
Cy = tempy * tempy * tempy * (tempy * (tempy * 6 - 15) + 10);
|
||||
Cz = tempz * tempz * tempz * (tempz * (tempz * 6 - 15) + 10);
|
||||
Cw = tempw * tempw * tempw * (tempw * (tempw * 6 - 15) + 10);
|
||||
|
||||
s[0] = gradient4[gi0][0]*tempx + gradient4[gi0][1]*tempy + gradient4[gi0][2]*tempz + gradient4[gi0][3]*tempw;
|
||||
|
||||
tempx = xc - (x0+1);
|
||||
t[0] = gradient4[gi1][0]*tempx + gradient4[gi1][1]*tempy + gradient4[gi1][2]*tempz + gradient4[gi1][3]*tempw;
|
||||
|
||||
tempy = yc - (y0+1);
|
||||
v[0] = gradient4[gi3][0]*tempx + gradient4[gi3][1]*tempy + gradient4[gi3][2]*tempz + gradient4[gi3][3]*tempw;
|
||||
|
||||
tempx = xc - x0;
|
||||
u[0] = gradient4[gi2][0]*tempx + gradient4[gi2][1]*tempy + gradient4[gi2][2]*tempz + gradient4[gi2][3]*tempw;
|
||||
|
||||
tempy = yc - y0;
|
||||
tempz = zc - (z0+1);
|
||||
s[1] = gradient4[gi4][0]*tempx + gradient4[gi4][1]*tempy + gradient4[gi4][2]*tempz + gradient4[gi4][3]*tempw;
|
||||
|
||||
tempx = xc - (x0+1);
|
||||
t[1] = gradient4[gi5][0]*tempx + gradient4[gi5][1]*tempy + gradient4[gi5][2]*tempz + gradient4[gi5][3]*tempw;
|
||||
|
||||
tempy = yc - (y0+1);
|
||||
v[1] = gradient4[gi7][0]*tempx + gradient4[gi7][1]*tempy + gradient4[gi7][2]*tempz + gradient4[gi7][3]*tempw;
|
||||
|
||||
tempx = xc - x0;
|
||||
u[1] = gradient4[gi6][0]*tempx + gradient4[gi6][1]*tempy + gradient4[gi6][2]*tempz + gradient4[gi6][3]*tempw;
|
||||
|
||||
|
||||
tempy = yc - y0;
|
||||
tempz = zc - z0;
|
||||
tempw = wc - (w0+1);
|
||||
s[2] = gradient4[gi8][0]*tempx + gradient4[gi8][1]*tempy + gradient4[gi8][2]*tempz + gradient4[gi8][3]*tempw;
|
||||
|
||||
tempx = xc - (x0+1);
|
||||
t[2] = gradient4[gi9][0]*tempx + gradient4[gi9][1]*tempy + gradient4[gi9][2]*tempz + gradient4[gi9][3]*tempw;
|
||||
|
||||
tempy = yc - (y0+1);
|
||||
v[2] = gradient4[gi11][0]*tempx + gradient4[gi11][1]*tempy + gradient4[gi11][2]*tempz + gradient4[gi11][3]*tempw;
|
||||
|
||||
tempx = xc - x0;
|
||||
u[2] = gradient4[gi10][0]*tempx + gradient4[gi10][1]*tempy + gradient4[gi10][2]*tempz + gradient4[gi10][3]*tempw;
|
||||
|
||||
|
||||
tempy = yc - y0;
|
||||
tempz = zc - (z0+1);
|
||||
s[3] = gradient4[gi12][0]*tempx + gradient4[gi12][1]*tempy + gradient4[gi12][2]*tempz + gradient4[gi12][3]*tempw;
|
||||
|
||||
tempx = xc - (x0+1);
|
||||
t[3] = gradient4[gi13][0]*tempx + gradient4[gi13][1]*tempy + gradient4[gi13][2]*tempz + gradient4[gi13][3]*tempw;
|
||||
|
||||
tempy = yc - (y0+1);
|
||||
v[3] = gradient4[gi15][0]*tempx + gradient4[gi15][1]*tempy + gradient4[gi15][2]*tempz + gradient4[gi15][3]*tempw;
|
||||
|
||||
tempx = xc - x0;
|
||||
u[3] = gradient4[gi14][0]*tempx + gradient4[gi14][1]*tempy + gradient4[gi14][2]*tempz + gradient4[gi14][3]*tempw;
|
||||
|
||||
Li1 = s[0] + Cx*(t[0]-s[0]);
|
||||
Li2 = u[0] + Cx*(v[0]-u[0]);
|
||||
Li3 = s[1] + Cx*(t[1]-s[1]);
|
||||
Li4 = u[1] + Cx*(v[1]-u[1]);
|
||||
Li5 = s[2] + Cx*(t[2]-s[2]);
|
||||
Li6 = u[2] + Cx*(v[2]-u[2]);
|
||||
Li7 = s[3] + Cx*(t[3]-s[3]);
|
||||
Li8 = u[3] + Cx*(v[3]-u[3]);
|
||||
|
||||
Li9 = Li1 + Cy*(Li2-Li1);
|
||||
Li10 = Li3 + Cy*(Li4-Li3);
|
||||
Li11 = Li5 + Cy*(Li6-Li5);
|
||||
Li12 = Li7 + Cy*(Li8-Li7);
|
||||
|
||||
Li13 = Li9 + Cz*(Li10-Li9);
|
||||
Li14 = Li11 + Cz*(Li12-Li11);
|
||||
|
||||
return Li13 + Cw*(Li14-Li13);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Perlin2D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Perlin2D::Perlin2D()
|
||||
{
|
||||
float grad2Temp[][2] = {
|
||||
{1.f,1.f},
|
||||
{-1.f,1.f},
|
||||
{1.f,-1.f},
|
||||
{-1.f,-1.f},
|
||||
|
||||
{1.f,0.f},
|
||||
{-1.f,0.f},
|
||||
{0.f,1.f},
|
||||
{0.f,-1.f}
|
||||
};
|
||||
|
||||
for(int i(0) ; i < 8 ; ++i)
|
||||
for(int j(0) ; j < 2 ; ++j)
|
||||
gradient2[i][j] = grad2Temp[i][j];
|
||||
}
|
||||
|
||||
Perlin2D::Perlin2D(unsigned int seed) : Perlin2D()
|
||||
{
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
}
|
||||
|
||||
float Perlin2D::GetValue(float x, float y, float resolution)
|
||||
{
|
||||
x *= resolution;
|
||||
y *= resolution;
|
||||
|
||||
x0 = fastfloor(x);
|
||||
y0 = fastfloor(y);
|
||||
|
||||
ii = x0 & 255;
|
||||
jj = y0 & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj]] & 7;
|
||||
gi1 = perm[ii + 1 + perm[jj]] & 7;
|
||||
gi2 = perm[ii + perm[jj + 1]] & 7;
|
||||
gi3 = perm[ii + 1 + perm[jj + 1]] & 7;
|
||||
|
||||
temp.x = x-x0;
|
||||
temp.y = y-y0;
|
||||
|
||||
Cx = temp.x * temp.x * temp.x * (temp.x * (temp.x * 6 - 15) + 10);
|
||||
Cy = temp.y * temp.y * temp.y * (temp.y * (temp.y * 6 - 15) + 10);
|
||||
|
||||
s = gradient2[gi0][0]*temp.x + gradient2[gi0][1]*temp.y;
|
||||
|
||||
temp.x = x-(x0+1);
|
||||
t = gradient2[gi1][0]*temp.x + gradient2[gi1][1]*temp.y;
|
||||
|
||||
temp.y = y-(y0+1);
|
||||
v = gradient2[gi3][0]*temp.x + gradient2[gi3][1]*temp.y;
|
||||
|
||||
temp.x = x-x0;
|
||||
u = gradient2[gi2][0]*temp.x + gradient2[gi2][1]*temp.y;
|
||||
|
||||
Li1 = s + Cx*(t-s);
|
||||
Li2 = u + Cx*(v-u);
|
||||
|
||||
return Li1 + Cy*(Li2-Li1);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Perlin3D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Perlin3D::Perlin3D()
|
||||
{
|
||||
float grad3Temp[][3] = {
|
||||
{1,1,0},{-1,1,0},{1,-1,0},{-1,-1,0},
|
||||
{1,0,1},{-1,0,1},{1,0,-1},{-1,0,-1},
|
||||
{0,1,1},{0,-1,1},{0,1,-1},{0,-1,-1},
|
||||
{1,1,0},{-1,1,0},{0,-1,1},{0,-1,-1}
|
||||
};
|
||||
|
||||
for(int i(0) ; i < 16 ; ++i)
|
||||
for(int j(0) ; j < 3 ; ++j)
|
||||
gradient3[i][j] = grad3Temp[i][j];
|
||||
}
|
||||
|
||||
Perlin3D::Perlin3D(unsigned int seed) : Perlin3D()
|
||||
{
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
}
|
||||
|
||||
float Perlin3D::GetValue(float x, float y, float z, float resolution)
|
||||
{
|
||||
x /= resolution;
|
||||
y /= resolution;
|
||||
z /= resolution;
|
||||
|
||||
x0 = fastfloor(x);
|
||||
y0 = fastfloor(y);
|
||||
z0 = fastfloor(z);
|
||||
|
||||
ii = x0 & 255;
|
||||
jj = y0 & 255;
|
||||
kk = z0 & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj + perm[kk]]] & 15;
|
||||
gi1 = perm[ii + 1 + perm[jj + perm[kk]]] & 15;
|
||||
gi2 = perm[ii + perm[jj + 1 + perm[kk]]] & 15;
|
||||
gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk]]] & 15;
|
||||
|
||||
gi4 = perm[ii + perm[jj + perm[kk + 1]]] & 15;
|
||||
gi5 = perm[ii + 1 + perm[jj + perm[kk + 1]]] & 15;
|
||||
gi6 = perm[ii + perm[jj + 1 + perm[kk + 1]]] & 15;
|
||||
gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] & 15;
|
||||
|
||||
temp.x = x-x0;
|
||||
temp.y = y-y0;
|
||||
temp.z = z-z0;
|
||||
|
||||
Cx = temp.x * temp.x * temp.x * (temp.x * (temp.x * 6 - 15) + 10);
|
||||
Cy = temp.y * temp.y * temp.y * (temp.y * (temp.y * 6 - 15) + 10);
|
||||
Cz = temp.z * temp.z * temp.z * (temp.z * (temp.z * 6 - 15) + 10);
|
||||
|
||||
s[0] = gradient3[gi0][0]*temp.x + gradient3[gi0][1]*temp.y + gradient3[gi0][2]*temp.z;
|
||||
|
||||
temp.x = x-(x0+1);
|
||||
t[0] = gradient3[gi1][0]*temp.x + gradient3[gi1][1]*temp.y + gradient3[gi1][2]*temp.z;
|
||||
|
||||
temp.y = y-(y0+1);
|
||||
v[0] = gradient3[gi3][0]*temp.x + gradient3[gi3][1]*temp.y + gradient3[gi3][2]*temp.z;
|
||||
|
||||
temp.x = x-x0;
|
||||
u[0] = gradient3[gi2][0]*temp.x + gradient3[gi2][1]*temp.y + gradient3[gi2][2]*temp.z;
|
||||
|
||||
temp.y = y-y0;
|
||||
temp.z = z-(z0+1);
|
||||
s[1] = gradient3[gi4][0]*temp.x + gradient3[gi4][1]*temp.y + gradient3[gi4][2]*temp.z;
|
||||
|
||||
temp.x = x-(x0+1);
|
||||
t[1] = gradient3[gi5][0]*temp.x + gradient3[gi5][1]*temp.y + gradient3[gi5][2]*temp.z;
|
||||
|
||||
temp.y = y-(y0+1);
|
||||
v[1] = gradient3[gi7][0]*temp.x + gradient3[gi7][1]*temp.y + gradient3[gi7][2]*temp.z;
|
||||
|
||||
temp.x = x-x0;
|
||||
u[1] = gradient3[gi6][0]*temp.x + gradient3[gi6][1]*temp.y + gradient3[gi6][2]*temp.z;
|
||||
|
||||
Li1 = s[0] + Cx*(t[0]-s[0]);
|
||||
Li2 = u[0] + Cx*(v[0]-u[0]);
|
||||
Li3 = s[1] + Cx*(t[1]-s[1]);
|
||||
Li4 = u[1] + Cx*(v[1]-u[1]);
|
||||
|
||||
Li5 = Li1 + Cy*(Li2-Li1);
|
||||
Li6 = Li3 + Cy*(Li4-Li3);
|
||||
|
||||
return Li5 + Cz*(Li6-Li5);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,156 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Perlin4D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Perlin4D::Perlin4D()
|
||||
{
|
||||
float grad4Temp[][4] =
|
||||
{
|
||||
{0,1,1,1}, {0,1,1,-1}, {0,1,-1,1}, {0,1,-1,-1},
|
||||
{0,-1,1,1},{0,-1,1,-1},{0,-1,-1,1},{0,-1,-1,-1},
|
||||
{1,0,1,1}, {1,0,1,-1}, {1,0,-1,1}, {1,0,-1,-1},
|
||||
{-1,0,1,1},{-1,0,1,-1},{-1,0,-1,1},{-1,0,-1,-1},
|
||||
{1,1,0,1}, {1,1,0,-1}, {1,-1,0,1}, {1,-1,0,-1},
|
||||
{-1,1,0,1},{-1,1,0,-1},{-1,-1,0,1},{-1,-1,0,-1},
|
||||
{1,1,1,0}, {1,1,-1,0}, {1,-1,1,0}, {1,-1,-1,0},
|
||||
{-1,1,1,0},{-1,1,-1,0},{-1,-1,1,0},{-1,-1,-1,0}
|
||||
};
|
||||
|
||||
for(int i(0) ; i < 32 ; ++i)
|
||||
for(int j(0) ; j < 4 ; ++j)
|
||||
gradient4[i][j] = grad4Temp[i][j];
|
||||
}
|
||||
|
||||
Perlin4D::Perlin4D(unsigned int seed) : Perlin4D()
|
||||
{
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
}
|
||||
|
||||
float Perlin4D::GetValue(float x, float y, float z, float w, float resolution)
|
||||
{
|
||||
x *= resolution;
|
||||
y *= resolution;
|
||||
z *= resolution;
|
||||
w *= resolution;
|
||||
|
||||
x0 = fastfloor(x);
|
||||
y0 = fastfloor(y);
|
||||
z0 = fastfloor(z);
|
||||
w0 = fastfloor(w);
|
||||
|
||||
ii = x0 & 255;
|
||||
jj = y0 & 255;
|
||||
kk = z0 & 255;
|
||||
ll = w0 & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj + perm[kk + perm[ll]]]] & 31;
|
||||
gi1 = perm[ii + 1 + perm[jj + perm[kk + perm[ll]]]] & 31;
|
||||
gi2 = perm[ii + perm[jj + 1 + perm[kk + perm[ll]]]] & 31;
|
||||
gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll]]]] & 31;
|
||||
|
||||
gi4 = perm[ii + perm[jj + + perm[kk + 1 + perm[ll]]]] & 31;
|
||||
gi5 = perm[ii + 1 + perm[jj + + perm[kk + 1 + perm[ll]]]] & 31;
|
||||
gi6 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll]]]] & 31;
|
||||
gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll]]]] & 31;
|
||||
|
||||
gi8 = perm[ii + perm[jj + perm[kk + perm[ll + 1]]]] & 31;
|
||||
gi9 = perm[ii + 1 + perm[jj + perm[kk + perm[ll + 1]]]] & 31;
|
||||
gi10 = perm[ii + perm[jj + 1 + perm[kk + perm[ll + 1]]]] & 31;
|
||||
gi11 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll + 1]]]] & 31;
|
||||
|
||||
gi12 = perm[ii + perm[jj + perm[kk + 1 + perm[ll + 1]]]] & 31;
|
||||
gi13 = perm[ii + 1 + perm[jj + perm[kk + 1 + perm[ll + 1]]]] & 31;
|
||||
gi14 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] & 31;
|
||||
gi15 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] & 31;
|
||||
|
||||
temp.x = x-x0;
|
||||
temp.y = y-y0;
|
||||
temp.z = z-z0;
|
||||
temp.w = w-w0;
|
||||
|
||||
Cx = temp.x * temp.x * temp.x * (temp.x * (temp.x * 6 - 15) + 10);
|
||||
Cy = temp.y * temp.y * temp.y * (temp.y * (temp.y * 6 - 15) + 10);
|
||||
Cz = temp.z * temp.z * temp.z * (temp.z * (temp.z * 6 - 15) + 10);
|
||||
Cw = temp.w * temp.w * temp.w * (temp.w * (temp.w * 6 - 15) + 10);
|
||||
|
||||
s[0] = gradient4[gi0][0]*temp.x + gradient4[gi0][1]*temp.y + gradient4[gi0][2]*temp.z + gradient4[gi0][3]*temp.w;
|
||||
|
||||
temp.x = x-(x0+1);
|
||||
t[0] = gradient4[gi1][0]*temp.x + gradient4[gi1][1]*temp.y + gradient4[gi1][2]*temp.z + gradient4[gi1][3]*temp.w;
|
||||
|
||||
temp.y = y-(y0+1);
|
||||
v[0] = gradient4[gi3][0]*temp.x + gradient4[gi3][1]*temp.y + gradient4[gi3][2]*temp.z + gradient4[gi3][3]*temp.w;
|
||||
|
||||
temp.x = x-x0;
|
||||
u[0] = gradient4[gi2][0]*temp.x + gradient4[gi2][1]*temp.y + gradient4[gi2][2]*temp.z + gradient4[gi2][3]*temp.w;
|
||||
|
||||
temp.y = y-y0;
|
||||
temp.z = z-(z0+1);
|
||||
s[1] = gradient4[gi4][0]*temp.x + gradient4[gi4][1]*temp.y + gradient4[gi4][2]*temp.z + gradient4[gi4][3]*temp.w;
|
||||
|
||||
temp.x = x-(x0+1);
|
||||
t[1] = gradient4[gi5][0]*temp.x + gradient4[gi5][1]*temp.y + gradient4[gi5][2]*temp.z + gradient4[gi5][3]*temp.w;
|
||||
|
||||
temp.y = y-(y0+1);
|
||||
v[1] = gradient4[gi7][0]*temp.x + gradient4[gi7][1]*temp.y + gradient4[gi7][2]*temp.z + gradient4[gi7][3]*temp.w;
|
||||
|
||||
temp.x = x-x0;
|
||||
u[1] = gradient4[gi6][0]*temp.x + gradient4[gi6][1]*temp.y + gradient4[gi6][2]*temp.z + gradient4[gi6][3]*temp.w;
|
||||
|
||||
|
||||
temp.y = y-y0;
|
||||
temp.z = z-z0;
|
||||
temp.w = w-(w0+1);
|
||||
s[2] = gradient4[gi8][0]*temp.x + gradient4[gi8][1]*temp.y + gradient4[gi8][2]*temp.z + gradient4[gi8][3]*temp.w;
|
||||
|
||||
temp.x = x-(x0+1);
|
||||
t[2] = gradient4[gi9][0]*temp.x + gradient4[gi9][1]*temp.y + gradient4[gi9][2]*temp.z + gradient4[gi9][3]*temp.w;
|
||||
|
||||
temp.y = y-(y0+1);
|
||||
v[2] = gradient4[gi11][0]*temp.x + gradient4[gi11][1]*temp.y + gradient4[gi11][2]*temp.z + gradient4[gi11][3]*temp.w;
|
||||
|
||||
temp.x = x-x0;
|
||||
u[2] = gradient4[gi10][0]*temp.x + gradient4[gi10][1]*temp.y + gradient4[gi10][2]*temp.z + gradient4[gi10][3]*temp.w;
|
||||
|
||||
|
||||
temp.y = y-y0;
|
||||
temp.z = z-(z0+1);
|
||||
s[3] = gradient4[gi12][0]*temp.x + gradient4[gi12][1]*temp.y + gradient4[gi12][2]*temp.z + gradient4[gi12][3]*temp.w;
|
||||
|
||||
temp.x = x-(x0+1);
|
||||
t[3] = gradient4[gi13][0]*temp.x + gradient4[gi13][1]*temp.y + gradient4[gi13][2]*temp.z + gradient4[gi13][3]*temp.w;
|
||||
|
||||
temp.y = y-(y0+1);
|
||||
v[3] = gradient4[gi15][0]*temp.x + gradient4[gi15][1]*temp.y + gradient4[gi15][2]*temp.z + gradient4[gi15][3]*temp.w;
|
||||
|
||||
temp.x = x-x0;
|
||||
u[3] = gradient4[gi14][0]*temp.x + gradient4[gi14][1]*temp.y + gradient4[gi14][2]*temp.z + gradient4[gi14][3]*temp.w;
|
||||
|
||||
Li1 = s[0] + Cx*(t[0]-s[0]);
|
||||
Li2 = u[0] + Cx*(v[0]-u[0]);
|
||||
Li3 = s[1] + Cx*(t[1]-s[1]);
|
||||
Li4 = u[1] + Cx*(v[1]-u[1]);
|
||||
Li5 = s[2] + Cx*(t[2]-s[2]);
|
||||
Li6 = u[2] + Cx*(v[2]-u[2]);
|
||||
Li7 = s[3] + Cx*(t[3]-s[3]);
|
||||
Li8 = u[3] + Cx*(v[3]-u[3]);
|
||||
|
||||
Li9 = Li1 + Cy*(Li2-Li1);
|
||||
Li10 = Li3 + Cy*(Li4-Li3);
|
||||
Li11 = Li5 + Cy*(Li6-Li5);
|
||||
Li12 = Li7 + Cy*(Li8-Li7);
|
||||
|
||||
Li13 = Li9 + Cz*(Li10-Li9);
|
||||
Li14 = Li11 + Cz*(Li12-Li11);
|
||||
|
||||
return Li13 + Cw*(Li14-Li13);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,459 @@
|
|||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Noise/Simplex.hpp>
|
||||
#include <Nazara/Noise/NoiseTools.hpp>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Simplex::Simplex() :
|
||||
gradient2{
|
||||
{1,1},{-1,1},{1,-1},{-1,-1},
|
||||
{1,0},{-1,0},{0,1},{0,-1}
|
||||
},
|
||||
gradient3{
|
||||
{1.f,1.f,0.f},{-1.f,1.f,0.f},{1.f,-1.f,0.f},{-1.f,-1.f,0.f},
|
||||
{1.f,0.f,1.f},{-1.f,0.f,1.f},{1.f,0.f,-1.f},{-1.f,0.f,-1.f},
|
||||
{0.f,1.f,1.f},{0.f,-1.f,1.f},{0.f,1.f,-1.f},{0.f,-1.f,-1.f}
|
||||
},
|
||||
gradient4{
|
||||
{0.f,1.f,1.f,1.f}, {0.f,1.f,1.f,-1.f}, {0.f,1.f,-1.f,1.f}, {0.f,1.f,-1.f,-1.f},
|
||||
{0.f,-1.f,1.f,1.f},{0.f,-1.f,1.f,-1.f},{0.f,-1.f,-1.f,1.f},{0.f,-1.f,-1.f,-1.f},
|
||||
{1.f,0.f,1.f,1.f}, {1.f,0.f,1.f,-1.f}, {1.f,0.f,-1.f,1.f}, {1.f,0.f,-1.f,-1.f},
|
||||
{-1.f,0.f,1.f,1.f},{-1.f,0.f,1.f,-1.f},{-1.f,0.f,-1.f,1.f},{-1.f,0.f,-1.f,-1.f},
|
||||
{1.f,1.f,0.f,1.f}, {1.f,1.f,0.f,-1.f}, {1.f,-1.f,0.f,1.f}, {1.f,-1.f,0.f,-1.f},
|
||||
{-1.f,1.f,0.f,1.f},{-1.f,1.f,0.f,-1.f},{-1.f,-1.f,0.f,1.f},{-1.f,-1.f,0.f,-1.f},
|
||||
{1.f,1.f,1.f,0.f}, {1.f,1.f,-1.f,0.f}, {1.f,-1.f,1.f,0.f}, {1.f,-1.f,-1.f,0.f},
|
||||
{-1.f,1.f,1.f,0.f},{-1.f,1.f,-1.f,0.f},{-1.f,-1.f,1.f,0.f},{-1.f,-1.f,-1.f,0.f}
|
||||
},
|
||||
lookupTable4D{
|
||||
{0,1,2,3},{0,1,3,2},{0,0,0,0},{0,2,3,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,2,3,0},
|
||||
{0,2,1,3},{0,0,0,0},{0,3,1,2},{0,3,2,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,3,2,0},
|
||||
{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
|
||||
{1,2,0,3},{0,0,0,0},{1,3,0,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,3,0,1},{2,3,1,0},
|
||||
{1,0,2,3},{1,0,3,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,0,3,1},{0,0,0,0},{2,1,3,0},
|
||||
{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
|
||||
{2,0,1,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,0,1,2},{3,0,2,1},{0,0,0,0},{3,1,2,0},
|
||||
{2,1,0,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,1,0,2},{0,0,0,0},{3,2,0,1},{3,2,1,0}
|
||||
},
|
||||
SkewCoeff2D (0.5f*(std::sqrt(3.f) - 1.f)),
|
||||
UnskewCoeff2D((3.f-std::sqrt(3.f))/6.f),
|
||||
SkewCoeff3D (1/3.f),
|
||||
UnskewCoeff3D (1/6.f),
|
||||
SkewCoeff4D ((std::sqrt(5.f) - 1.f)/4.f),
|
||||
UnskewCoeff4D ((5.f - std::sqrt(5.f))/20.f)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Simplex::Simplex(unsigned int seed) : Simplex()
|
||||
{
|
||||
SetSeed(seed);
|
||||
Shuffle();
|
||||
}
|
||||
|
||||
float Simplex::Get(std::initializer_list<float> coordinates, float scale) const
|
||||
{
|
||||
switch(coordinates.size())
|
||||
{
|
||||
case 2:
|
||||
return this->_2D(coordinates,scale);
|
||||
case 3:
|
||||
return this->_3D(coordinates,scale);
|
||||
case 4:
|
||||
return this->_4D(coordinates,scale);
|
||||
default:
|
||||
throw std::invalid_argument("Number of coordinates elements not comprised between 2 and 4");
|
||||
}
|
||||
}
|
||||
|
||||
float Simplex::_2D(std::initializer_list<float> coordinates, float scale) const
|
||||
{
|
||||
thread_local float xc,yc;
|
||||
thread_local int ii,jj;
|
||||
thread_local int gi0,gi1,gi2;
|
||||
thread_local int skewedCubeOriginx,skewedCubeOriginy;
|
||||
thread_local int off1x,off1y;
|
||||
thread_local float n1,n2,n3;
|
||||
thread_local float c1,c2,c3;
|
||||
thread_local float sum;
|
||||
thread_local float unskewedCubeOriginx,unskewedCubeOriginy;
|
||||
thread_local float unskewedDistToOriginx,unskewedDistToOriginy;
|
||||
thread_local float d1x,d1y;
|
||||
thread_local float d2x,d2y;
|
||||
thread_local float d3x,d3y;
|
||||
|
||||
std::initializer_list<float>::const_iterator it = coordinates.begin();
|
||||
|
||||
xc = *(it ) * scale;
|
||||
yc = *(++it) * scale;
|
||||
|
||||
sum = (xc + yc) * SkewCoeff2D;
|
||||
skewedCubeOriginx = fastfloor(xc + sum);
|
||||
skewedCubeOriginy = fastfloor(yc + sum);
|
||||
|
||||
sum = (skewedCubeOriginx + skewedCubeOriginy) * UnskewCoeff2D;
|
||||
unskewedCubeOriginx = skewedCubeOriginx - sum;
|
||||
unskewedCubeOriginy = skewedCubeOriginy - sum;
|
||||
|
||||
unskewedDistToOriginx = xc - unskewedCubeOriginx;// Difference with 3d and 4d
|
||||
unskewedDistToOriginy = yc - unskewedCubeOriginy;
|
||||
|
||||
if(unskewedDistToOriginx > unskewedDistToOriginy)
|
||||
{
|
||||
off1x = 1;
|
||||
off1y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
off1x = 0;
|
||||
off1y = 1;
|
||||
}
|
||||
|
||||
d1x = - unskewedDistToOriginx;
|
||||
d1y = - unskewedDistToOriginy;
|
||||
|
||||
d2x = d1x + off1x - UnskewCoeff2D;
|
||||
d2y = d1y + off1y - UnskewCoeff2D;
|
||||
|
||||
d3x = d1x + 1.f - 2.f * UnskewCoeff2D;
|
||||
d3y = d1y + 1.f - 2.f * UnskewCoeff2D;
|
||||
|
||||
ii = skewedCubeOriginx & 255;
|
||||
jj = skewedCubeOriginy & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj ]] & 7;
|
||||
gi1 = perm[ii + off1x + perm[jj + off1y ]] & 7;
|
||||
gi2 = perm[ii + 1 + perm[jj + 1 ]] & 7;
|
||||
|
||||
c1 = 0.5f - d1x * d1x - d1y * d1y;
|
||||
c2 = 0.5f - d2x * d2x - d2y * d2y;
|
||||
c3 = 0.5f - d3x * d3x - d3y * d3y;
|
||||
|
||||
if(c1 < 0)
|
||||
n1 = 0;
|
||||
else
|
||||
n1 = c1*c1*c1*c1*(gradient2[gi0][0] * d1x + gradient2[gi0][1] * d1y);
|
||||
|
||||
if(c2 < 0)
|
||||
n2 = 0;
|
||||
else
|
||||
n2 = c2*c2*c2*c2*(gradient2[gi1][0] * d2x + gradient2[gi1][1] * d2y);
|
||||
|
||||
if(c3 < 0)
|
||||
n3 = 0;
|
||||
else
|
||||
n3 = c3*c3*c3*c3*(gradient2[gi2][0] * d3x + gradient2[gi2][1] * d3y);
|
||||
|
||||
return (n1+n2+n3)*70.f;
|
||||
}
|
||||
|
||||
float Simplex::_3D(std::initializer_list<float> coordinates, float scale) const
|
||||
{
|
||||
thread_local float xc, yc, zc;
|
||||
thread_local float x,y,z;
|
||||
thread_local int ii,jj,kk;
|
||||
thread_local int gi0,gi1,gi2,gi3;
|
||||
thread_local int skewedCubeOriginx,skewedCubeOriginy,skewedCubeOriginz;
|
||||
|
||||
thread_local int off1x,off1y,off1z;
|
||||
thread_local int off2x,off2y,off2z;
|
||||
thread_local float n1,n2,n3,n4;
|
||||
thread_local float c1,c2,c3,c4;
|
||||
|
||||
thread_local float sum;
|
||||
thread_local float unskewedCubeOriginx,unskewedCubeOriginy,unskewedCubeOriginz;
|
||||
thread_local float unskewedDistToOriginx,unskewedDistToOriginy,unskewedDistToOriginz;
|
||||
thread_local float d1x,d1y,d1z;
|
||||
thread_local float d2x,d2y,d2z;
|
||||
thread_local float d3x,d3y,d3z;
|
||||
thread_local float d4x,d4y,d4z;
|
||||
|
||||
std::initializer_list<float>::const_iterator it = coordinates.begin();
|
||||
|
||||
x = *(it );
|
||||
y = *(++it);
|
||||
z = *(++it);
|
||||
|
||||
xc = x * scale;
|
||||
yc = y * scale;
|
||||
zc = z * scale;
|
||||
|
||||
sum = (xc + yc + zc) * SkewCoeff3D;
|
||||
skewedCubeOriginx = fastfloor(xc + sum);
|
||||
skewedCubeOriginy = fastfloor(yc + sum);
|
||||
skewedCubeOriginz = fastfloor(zc + sum);
|
||||
|
||||
sum = (skewedCubeOriginx + skewedCubeOriginy + skewedCubeOriginz) * UnskewCoeff3D;
|
||||
unskewedCubeOriginx = skewedCubeOriginx - sum;
|
||||
unskewedCubeOriginy = skewedCubeOriginy - sum;
|
||||
unskewedCubeOriginz = skewedCubeOriginz - sum;
|
||||
|
||||
unskewedDistToOriginx = xc - unskewedCubeOriginx;
|
||||
unskewedDistToOriginy = yc - unskewedCubeOriginy;
|
||||
unskewedDistToOriginz = zc - unskewedCubeOriginz;
|
||||
|
||||
if(unskewedDistToOriginx >= unskewedDistToOriginy)
|
||||
{
|
||||
if(unskewedDistToOriginy >= unskewedDistToOriginz)
|
||||
{
|
||||
off1x = 1;
|
||||
off1y = 0;
|
||||
off1z = 0;
|
||||
off2x = 1;
|
||||
off2y = 1;
|
||||
off2z = 0;
|
||||
}
|
||||
else if(unskewedDistToOriginx >= unskewedDistToOriginz)
|
||||
{
|
||||
off1x = 1;
|
||||
off1y = 0;
|
||||
off1z = 0;
|
||||
off2x = 1;
|
||||
off2y = 0;
|
||||
off2z = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
off1x = 0;
|
||||
off1y = 0;
|
||||
off1z = 1;
|
||||
off2x = 1;
|
||||
off2y = 0;
|
||||
off2z = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(unskewedDistToOriginy < unskewedDistToOriginz)
|
||||
{
|
||||
off1x = 0;
|
||||
off1y = 0;
|
||||
off1z = 1;
|
||||
off2x = 0;
|
||||
off2y = 1;
|
||||
off2z = 1;
|
||||
}
|
||||
else if(unskewedDistToOriginx < unskewedDistToOriginz)
|
||||
{
|
||||
off1x = 0;
|
||||
off1y = 1;
|
||||
off1z = 0;
|
||||
off2x = 0;
|
||||
off2y = 1;
|
||||
off2z = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
off1x = 0;
|
||||
off1y = 1;
|
||||
off1z = 0;
|
||||
off2x = 1;
|
||||
off2y = 1;
|
||||
off2z = 0;
|
||||
}
|
||||
}
|
||||
|
||||
d1x = unskewedDistToOriginx;
|
||||
d1y = unskewedDistToOriginy;
|
||||
d1z = unskewedDistToOriginz;
|
||||
|
||||
d2x = d1x - off1x + UnskewCoeff3D;
|
||||
d2y = d1y - off1y + UnskewCoeff3D;
|
||||
d2z = d1z - off1z + UnskewCoeff3D;
|
||||
|
||||
d3x = d1x - off2x + 2.f*UnskewCoeff3D;
|
||||
d3y = d1y - off2y + 2.f*UnskewCoeff3D;
|
||||
d3z = d1z - off2z + 2.f*UnskewCoeff3D;
|
||||
|
||||
d4x = d1x - 1.f + 3.f*UnskewCoeff3D;
|
||||
d4y = d1y - 1.f + 3.f*UnskewCoeff3D;
|
||||
d4z = d1z - 1.f + 3.f*UnskewCoeff3D;
|
||||
|
||||
ii = skewedCubeOriginx & 255;
|
||||
jj = skewedCubeOriginy & 255;
|
||||
kk = skewedCubeOriginz & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj + perm[kk ]]] % 12;
|
||||
gi1 = perm[ii + off1x + perm[jj + off1y + perm[kk + off1z ]]] % 12;
|
||||
gi2 = perm[ii + off2x + perm[jj + off2y + perm[kk + off2z ]]] % 12;
|
||||
gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 ]]] % 12;
|
||||
|
||||
c1 = 0.6f - d1x * d1x - d1y * d1y - d1z * d1z;
|
||||
c2 = 0.6f - d2x * d2x - d2y * d2y - d2z * d2z;
|
||||
c3 = 0.6f - d3x * d3x - d3y * d3y - d3z * d3z;
|
||||
c4 = 0.6f - d4x * d4x - d4y * d4y - d4z * d4z;
|
||||
|
||||
if(c1 < 0)
|
||||
n1 = 0;
|
||||
else
|
||||
n1 = c1*c1*c1*c1*(gradient3[gi0][0] * d1x + gradient3[gi0][1] * d1y + gradient3[gi0][2] * d1z);
|
||||
|
||||
if(c2 < 0)
|
||||
n2 = 0;
|
||||
else
|
||||
n2 = c2*c2*c2*c2*(gradient3[gi1][0] * d2x + gradient3[gi1][1] * d2y + gradient3[gi1][2] * d2z);
|
||||
|
||||
if(c3 < 0)
|
||||
n3 = 0;
|
||||
else
|
||||
n3 = c3*c3*c3*c3*(gradient3[gi2][0] * d3x + gradient3[gi2][1] * d3y + gradient3[gi2][2] * d3z);
|
||||
|
||||
if(c4 < 0)
|
||||
n4 = 0;
|
||||
else
|
||||
n4 = c4*c4*c4*c4*(gradient3[gi3][0] * d4x + gradient3[gi3][1] * d4y + gradient3[gi3][2] * d4z);
|
||||
|
||||
return (n1+n2+n3+n4)*32;
|
||||
}
|
||||
|
||||
float Simplex::_4D(std::initializer_list<float> coordinates, float scale) const
|
||||
{
|
||||
thread_local float xc,yc,zc,wc;
|
||||
thread_local float x,y,z,w;
|
||||
thread_local int ii,jj,kk,ll;
|
||||
thread_local int gi0,gi1,gi2,gi3,gi4;
|
||||
thread_local int skewedCubeOriginx,skewedCubeOriginy,skewedCubeOriginz,skewedCubeOriginw;
|
||||
|
||||
thread_local int off1x,off1y,off1z,off1w;
|
||||
thread_local int off2x,off2y,off2z,off2w;
|
||||
thread_local int off3x,off3y,off3z,off3w;
|
||||
|
||||
thread_local int c;
|
||||
thread_local float n1,n2,n3,n4,n5;
|
||||
thread_local float c1,c2,c3,c4,c5,c6;
|
||||
|
||||
thread_local float sum;
|
||||
thread_local float unskewedCubeOriginx,unskewedCubeOriginy,unskewedCubeOriginz,unskewedCubeOriginw;
|
||||
thread_local float unskewedDistToOriginx,unskewedDistToOriginy,unskewedDistToOriginz,unskewedDistToOriginw;
|
||||
thread_local float d1x,d2x,d3x,d4x,d5x;
|
||||
thread_local float d1y,d2y,d3y,d4y,d5y;
|
||||
thread_local float d1z,d2z,d3z,d4z,d5z;
|
||||
thread_local float d1w,d2w,d3w,d4w,d5w;
|
||||
|
||||
std::initializer_list<float>::const_iterator it = coordinates.begin();
|
||||
|
||||
x = *(it );
|
||||
y = *(++it);
|
||||
z = *(++it);
|
||||
w = *(++it);
|
||||
|
||||
xc = x * scale;
|
||||
yc = y * scale;
|
||||
zc = z * scale;
|
||||
wc = w * scale;
|
||||
|
||||
sum = (xc + yc + zc + wc) * SkewCoeff4D;
|
||||
skewedCubeOriginx = fastfloor(xc + sum);
|
||||
skewedCubeOriginy = fastfloor(yc + sum);
|
||||
skewedCubeOriginz = fastfloor(zc + sum);
|
||||
skewedCubeOriginw = fastfloor(wc + sum);
|
||||
|
||||
sum = (skewedCubeOriginx + skewedCubeOriginy + skewedCubeOriginz + skewedCubeOriginw) * UnskewCoeff4D;
|
||||
unskewedCubeOriginx = skewedCubeOriginx - sum;
|
||||
unskewedCubeOriginy = skewedCubeOriginy - sum;
|
||||
unskewedCubeOriginz = skewedCubeOriginz - sum;
|
||||
unskewedCubeOriginw = skewedCubeOriginw - sum;
|
||||
|
||||
unskewedDistToOriginx = xc - unskewedCubeOriginx;
|
||||
unskewedDistToOriginy = yc - unskewedCubeOriginy;
|
||||
unskewedDistToOriginz = zc - unskewedCubeOriginz;
|
||||
unskewedDistToOriginw = wc - unskewedCubeOriginw;
|
||||
|
||||
c1 = (unskewedDistToOriginx > unskewedDistToOriginy) ? 32 : 0;
|
||||
c2 = (unskewedDistToOriginx > unskewedDistToOriginz) ? 16 : 0;
|
||||
c3 = (unskewedDistToOriginy > unskewedDistToOriginz) ? 8 : 0;
|
||||
c4 = (unskewedDistToOriginx > unskewedDistToOriginw) ? 4 : 0;
|
||||
c5 = (unskewedDistToOriginy > unskewedDistToOriginw) ? 2 : 0;
|
||||
c6 = (unskewedDistToOriginz > unskewedDistToOriginw) ? 1 : 0;
|
||||
c = c1 + c2 + c3 + c4 + c5 + c6;
|
||||
|
||||
off1x = lookupTable4D[c][0] >= 3 ? 1 : 0;
|
||||
off1y = lookupTable4D[c][1] >= 3 ? 1 : 0;
|
||||
off1z = lookupTable4D[c][2] >= 3 ? 1 : 0;
|
||||
off1w = lookupTable4D[c][3] >= 3 ? 1 : 0;
|
||||
|
||||
off2x = lookupTable4D[c][0] >= 2 ? 1 : 0;
|
||||
off2y = lookupTable4D[c][1] >= 2 ? 1 : 0;
|
||||
off2z = lookupTable4D[c][2] >= 2 ? 1 : 0;
|
||||
off2w = lookupTable4D[c][3] >= 2 ? 1 : 0;
|
||||
|
||||
off3x = lookupTable4D[c][0] >= 1 ? 1 : 0;
|
||||
off3y = lookupTable4D[c][1] >= 1 ? 1 : 0;
|
||||
off3z = lookupTable4D[c][2] >= 1 ? 1 : 0;
|
||||
off3w = lookupTable4D[c][3] >= 1 ? 1 : 0;
|
||||
|
||||
d1x = unskewedDistToOriginx;
|
||||
d1y = unskewedDistToOriginy;
|
||||
d1z = unskewedDistToOriginz;
|
||||
d1w = unskewedDistToOriginw;
|
||||
|
||||
d2x = d1x - off1x + UnskewCoeff4D;
|
||||
d2y = d1y - off1y + UnskewCoeff4D;
|
||||
d2z = d1z - off1z + UnskewCoeff4D;
|
||||
d2w = d1w - off1w + UnskewCoeff4D;
|
||||
|
||||
d3x = d1x - off2x + 2.f*UnskewCoeff4D;
|
||||
d3y = d1y - off2y + 2.f*UnskewCoeff4D;
|
||||
d3z = d1z - off2z + 2.f*UnskewCoeff4D;
|
||||
d3w = d1w - off2w + 2.f*UnskewCoeff4D;
|
||||
|
||||
d4x = d1x - off3x + 3.f*UnskewCoeff4D;
|
||||
d4y = d1y - off3y + 3.f*UnskewCoeff4D;
|
||||
d4z = d1z - off3z + 3.f*UnskewCoeff4D;
|
||||
d4w = d1w - off3w + 3.f*UnskewCoeff4D;
|
||||
|
||||
d5x = d1x - 1.f + 4*UnskewCoeff4D;
|
||||
d5y = d1y - 1.f + 4*UnskewCoeff4D;
|
||||
d5z = d1z - 1.f + 4*UnskewCoeff4D;
|
||||
d5w = d1w - 1.f + 4*UnskewCoeff4D;
|
||||
|
||||
ii = skewedCubeOriginx & 255;
|
||||
jj = skewedCubeOriginy & 255;
|
||||
kk = skewedCubeOriginz & 255;
|
||||
ll = skewedCubeOriginw & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj + perm[kk + perm[ll ]]]] & 31;
|
||||
gi1 = perm[ii + off1x + perm[jj + off1y + perm[kk + off1z + perm[ll + off1w]]]] & 31;
|
||||
gi2 = perm[ii + off2x + perm[jj + off2y + perm[kk + off2z + perm[ll + off2w]]]] & 31;
|
||||
gi3 = perm[ii + off3x + perm[jj + off3y + perm[kk + off3z + perm[ll + off3w]]]] & 31;
|
||||
gi4 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1 ]]]] % 32;
|
||||
|
||||
c1 = 0.6f - d1x*d1x - d1y*d1y - d1z*d1z - d1w*d1w;
|
||||
c2 = 0.6f - d2x*d2x - d2y*d2y - d2z*d2z - d2w*d2w;
|
||||
c3 = 0.6f - d3x*d3x - d3y*d3y - d3z*d3z - d3w*d3w;
|
||||
c4 = 0.6f - d4x*d4x - d4y*d4y - d4z*d4z - d4w*d4w;
|
||||
c5 = 0.6f - d5x*d5x - d5y*d5y - d5z*d5z - d5w*d5w;
|
||||
|
||||
if(c1 < 0)
|
||||
n1 = 0;
|
||||
else
|
||||
n1 = c1*c1*c1*c1*(gradient4[gi0][0]*d1x + gradient4[gi0][1]*d1y + gradient4[gi0][2]*d1z + gradient4[gi0][3]*d1w);
|
||||
|
||||
if(c2 < 0)
|
||||
n2 = 0;
|
||||
else
|
||||
n2 = c2*c2*c2*c2*(gradient4[gi1][0]*d2x + gradient4[gi1][1]*d2y + gradient4[gi1][2]*d2z + gradient4[gi1][3]*d2w);
|
||||
|
||||
if(c3 < 0)
|
||||
n3 = 0;
|
||||
else
|
||||
n3 = c3*c3*c3*c3*(gradient4[gi2][0]*d3x + gradient4[gi2][1]*d3y + gradient4[gi2][2]*d3z + gradient4[gi2][3]*d3w);
|
||||
|
||||
if(c4 < 0)
|
||||
n4 = 0;
|
||||
else
|
||||
n4 = c4*c4*c4*c4*(gradient4[gi3][0]*d4x + gradient4[gi3][1]*d4y + gradient4[gi3][2]*d4z + gradient4[gi3][3]*d4w);
|
||||
|
||||
if(c5 < 0)
|
||||
n5 = 0;
|
||||
else
|
||||
n5 = c5*c5*c5*c5*(gradient4[gi4][0]*d5x + gradient4[gi4][1]*d5y + gradient4[gi4][2]*d5z + gradient4[gi4][3]*d5w);
|
||||
|
||||
return (n1+n2+n3+n4+n5)*27.f;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Simplex2D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Simplex2D::Simplex2D()
|
||||
{
|
||||
float grad2Temp[][2] = {{1,1},{-1,1},{1,-1},{-1,-1},
|
||||
{1,0},{-1,0},{0,1},{0,-1}};
|
||||
|
||||
for(int i(0) ; i < 8 ; ++i)
|
||||
for(int j(0) ; j < 2 ; ++j)
|
||||
gradient2[i][j] = grad2Temp[i][j];
|
||||
|
||||
SkewCoeff2D = 0.5f*(std::sqrt(3.f) - 1.f);
|
||||
UnskewCoeff2D = (3.f-std::sqrt(3.f))/6.f;
|
||||
}
|
||||
|
||||
Simplex2D::Simplex2D(unsigned int seed) : Simplex2D()
|
||||
{
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
}
|
||||
|
||||
float Simplex2D::GetValue(float x, float y, float resolution)
|
||||
{
|
||||
x *= resolution;
|
||||
y *= resolution;
|
||||
|
||||
sum = (x + y) * SkewCoeff2D;
|
||||
skewedCubeOrigin.x = fastfloor(x + sum);
|
||||
skewedCubeOrigin.y = fastfloor(y + sum);
|
||||
|
||||
sum = (skewedCubeOrigin.x + skewedCubeOrigin.y) * UnskewCoeff2D;
|
||||
unskewedCubeOrigin.x = skewedCubeOrigin.x - sum;
|
||||
unskewedCubeOrigin.y = skewedCubeOrigin.y - sum;
|
||||
|
||||
unskewedDistToOrigin.x = x - unskewedCubeOrigin.x;
|
||||
unskewedDistToOrigin.y = y - unskewedCubeOrigin.y;
|
||||
|
||||
if(unskewedDistToOrigin.x > unskewedDistToOrigin.y)
|
||||
{
|
||||
off1.x = 1;
|
||||
off1.y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
off1.x = 0;
|
||||
off1.y = 1;
|
||||
}
|
||||
|
||||
d1 = - unskewedDistToOrigin;
|
||||
|
||||
d2.x = d1.x + off1.x - UnskewCoeff2D;
|
||||
d2.y = d1.y + off1.y - UnskewCoeff2D;
|
||||
|
||||
d3.x = d1.x + 1.f - 2.f * UnskewCoeff2D;
|
||||
d3.y = d1.y + 1.f - 2.f * UnskewCoeff2D;
|
||||
|
||||
ii = skewedCubeOrigin.x & 255;
|
||||
jj = skewedCubeOrigin.y & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj ]] & 7;
|
||||
gi1 = perm[ii + off1.x + perm[jj + off1.y]] & 7;
|
||||
gi2 = perm[ii + 1 + perm[jj + 1 ]] & 7;
|
||||
|
||||
c1 = 0.5f - d1.x * d1.x - d1.y * d1.y;
|
||||
c2 = 0.5f - d2.x * d2.x - d2.y * d2.y;
|
||||
c3 = 0.5f - d3.x * d3.x - d3.y * d3.y;
|
||||
|
||||
if(c1 < 0)
|
||||
n1 = 0;
|
||||
else
|
||||
n1 = c1*c1*c1*c1*(gradient2[gi0][0] * d1.x + gradient2[gi0][1] * d1.y);
|
||||
|
||||
if(c2 < 0)
|
||||
n2 = 0;
|
||||
else
|
||||
n2 = c2*c2*c2*c2*(gradient2[gi1][0] * d2.x + gradient2[gi1][1] * d2.y);
|
||||
|
||||
if(c3 < 0)
|
||||
n3 = 0;
|
||||
else
|
||||
n3 = c3*c3*c3*c3*(gradient2[gi2][0] * d3.x + gradient2[gi2][1] * d3.y);
|
||||
|
||||
return (n1+n2+n3)*70.f;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,176 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Simplex3D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Simplex3D::Simplex3D()
|
||||
{
|
||||
SkewCoeff3D = 1/3.f;
|
||||
UnskewCoeff3D = 1/6.f;
|
||||
|
||||
float grad3Temp[][3] = {
|
||||
{1.f,1.f,0.f},
|
||||
{-1.f,1.f,0.f},
|
||||
{1.f,-1.f,0.f},
|
||||
{-1.f,-1.f,0.f},
|
||||
|
||||
{1.f,0.f,1.f},
|
||||
{-1.f,0.f,1.f},
|
||||
{1.f,0.f,-1.f},
|
||||
{-1.f,0.f,-1.f},
|
||||
|
||||
{0.f,1.f,1.f},
|
||||
{0.f,-1.f,1.f},
|
||||
{0.f,1.f,-1.f},
|
||||
{0.f,-1.f,-1.f}
|
||||
};
|
||||
|
||||
for(int i(0) ; i < 12 ; ++i)
|
||||
for(int j(0) ; j < 3 ; ++j)
|
||||
gradient3[i][j] = grad3Temp[i][j];
|
||||
}
|
||||
|
||||
Simplex3D::Simplex3D(unsigned int seed) : Simplex3D()
|
||||
{
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
}
|
||||
|
||||
float Simplex3D::GetValue(float x, float y, float z, float resolution)
|
||||
{
|
||||
x *= resolution;
|
||||
y *= resolution;
|
||||
z *= resolution;
|
||||
|
||||
sum = (x + y + z) * SkewCoeff3D;
|
||||
skewedCubeOrigin.x = fastfloor(x + sum);
|
||||
skewedCubeOrigin.y = fastfloor(y + sum);
|
||||
skewedCubeOrigin.z = fastfloor(z + sum);
|
||||
|
||||
sum = (skewedCubeOrigin.x + skewedCubeOrigin.y + skewedCubeOrigin.z) * UnskewCoeff3D;
|
||||
unskewedCubeOrigin.x = skewedCubeOrigin.x - sum;
|
||||
unskewedCubeOrigin.y = skewedCubeOrigin.y - sum;
|
||||
unskewedCubeOrigin.z = skewedCubeOrigin.z - sum;
|
||||
|
||||
unskewedDistToOrigin.x = x - unskewedCubeOrigin.x;
|
||||
unskewedDistToOrigin.y = y - unskewedCubeOrigin.y;
|
||||
unskewedDistToOrigin.z = z - unskewedCubeOrigin.z;
|
||||
|
||||
if(unskewedDistToOrigin.x >= unskewedDistToOrigin.y)
|
||||
{
|
||||
if(unskewedDistToOrigin.y >= unskewedDistToOrigin.z)
|
||||
{
|
||||
off1.x = 1;
|
||||
off1.y = 0;
|
||||
off1.z = 0;
|
||||
off2.x = 1;
|
||||
off2.y = 1;
|
||||
off2.z = 0;
|
||||
}
|
||||
else if(unskewedDistToOrigin.x >= unskewedDistToOrigin.z)
|
||||
{
|
||||
off1.x = 1;
|
||||
off1.y = 0;
|
||||
off1.z = 0;
|
||||
off2.x = 1;
|
||||
off2.y = 0;
|
||||
off2.z = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
off1.x = 0;
|
||||
off1.y = 0;
|
||||
off1.z = 1;
|
||||
off2.x = 1;
|
||||
off2.y = 0;
|
||||
off2.z = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(unskewedDistToOrigin.y < unskewedDistToOrigin.z)
|
||||
{
|
||||
off1.x = 0;
|
||||
off1.y = 0;
|
||||
off1.z = 1;
|
||||
off2.x = 0;
|
||||
off2.y = 1;
|
||||
off2.z = 1;
|
||||
}
|
||||
else if(unskewedDistToOrigin.x < unskewedDistToOrigin.z)
|
||||
{
|
||||
off1.x = 0;
|
||||
off1.y = 1;
|
||||
off1.z = 0;
|
||||
off2.x = 0;
|
||||
off2.y = 1;
|
||||
off2.z = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
off1.x = 0;
|
||||
off1.y = 1;
|
||||
off1.z = 0;
|
||||
off2.x = 1;
|
||||
off2.y = 1;
|
||||
off2.z = 0;
|
||||
}
|
||||
}
|
||||
|
||||
d1 = unskewedDistToOrigin;
|
||||
|
||||
d2.x = d1.x - off1.x + UnskewCoeff3D;
|
||||
d2.y = d1.y - off1.y + UnskewCoeff3D;
|
||||
d2.z = d1.z - off1.z + UnskewCoeff3D;
|
||||
|
||||
d3.x = d1.x - off2.x + 2.f*UnskewCoeff3D;
|
||||
d3.y = d1.y - off2.y + 2.f*UnskewCoeff3D;
|
||||
d3.z = d1.z - off2.z + 2.f*UnskewCoeff3D;
|
||||
|
||||
d4.x = d1.x - 1.f + 3.f*UnskewCoeff3D;
|
||||
d4.y = d1.y - 1.f + 3.f*UnskewCoeff3D;
|
||||
d4.z = d1.z - 1.f + 3.f*UnskewCoeff3D;
|
||||
|
||||
ii = skewedCubeOrigin.x & 255;
|
||||
jj = skewedCubeOrigin.y & 255;
|
||||
kk = skewedCubeOrigin.z & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj + perm[kk ]]] % 12;
|
||||
gi1 = perm[ii + off1.x + perm[jj + off1.y + perm[kk + off1.z]]] % 12;
|
||||
gi2 = perm[ii + off2.x + perm[jj + off2.y + perm[kk + off2.z]]] % 12;
|
||||
gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 ]]] % 12;
|
||||
|
||||
c1 = 0.6f - d1.x * d1.x - d1.y * d1.y - d1.z * d1.z;
|
||||
c2 = 0.6f - d2.x * d2.x - d2.y * d2.y - d2.z * d2.z;
|
||||
c3 = 0.6f - d3.x * d3.x - d3.y * d3.y - d3.z * d3.z;
|
||||
c4 = 0.6f - d4.x * d4.x - d4.y * d4.y - d4.z * d4.z;
|
||||
|
||||
if(c1 < 0)
|
||||
n1 = 0;
|
||||
else
|
||||
n1 = c1*c1*c1*c1*(gradient3[gi0][0] * d1.x + gradient3[gi0][1] * d1.y + gradient3[gi0][2] * d1.z);
|
||||
|
||||
if(c2 < 0)
|
||||
n2 = 0;
|
||||
else
|
||||
n2 = c2*c2*c2*c2*(gradient3[gi1][0] * d2.x + gradient3[gi1][1] * d2.y + gradient3[gi1][2] * d2.z);
|
||||
|
||||
if(c3 < 0)
|
||||
n3 = 0;
|
||||
else
|
||||
n3 = c3*c3*c3*c3*(gradient3[gi2][0] * d3.x + gradient3[gi2][1] * d3.y + gradient3[gi2][2] * d3.z);
|
||||
|
||||
if(c4 < 0)
|
||||
n4 = 0;
|
||||
else
|
||||
n4 = c4*c4*c4*c4*(gradient3[gi3][0] * d4.x + gradient3[gi3][1] * d4.y + gradient3[gi3][2] * d4.z);
|
||||
|
||||
return (n1+n2+n3+n4)*32;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,169 +0,0 @@
|
|||
// Copyright (C) 2015 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Simplex4D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Simplex4D::Simplex4D()
|
||||
{
|
||||
SkewCoeff4D = (std::sqrt(5.f) - 1.f)/4.f;
|
||||
UnskewCoeff4D = (5.f - std::sqrt(5.f))/20.f;
|
||||
|
||||
int lookupTemp4D[][4] =
|
||||
{
|
||||
{0,1,2,3},{0,1,3,2},{0,0,0,0},{0,2,3,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,2,3,0},
|
||||
{0,2,1,3},{0,0,0,0},{0,3,1,2},{0,3,2,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,3,2,0},
|
||||
{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
|
||||
{1,2,0,3},{0,0,0,0},{1,3,0,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,3,0,1},{2,3,1,0},
|
||||
{1,0,2,3},{1,0,3,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,0,3,1},{0,0,0,0},{2,1,3,0},
|
||||
{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
|
||||
{2,0,1,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,0,1,2},{3,0,2,1},{0,0,0,0},{3,1,2,0},
|
||||
{2,1,0,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,1,0,2},{0,0,0,0},{3,2,0,1},{3,2,1,0}
|
||||
};
|
||||
|
||||
for(int i(0) ; i < 64 ; ++i)
|
||||
for(int j(0) ; j < 4 ; ++j)
|
||||
lookupTable4D[i][j] = lookupTemp4D[i][j];
|
||||
|
||||
float grad4Temp[][4] =
|
||||
{
|
||||
{0.f,1.f,1.f,1.f}, {0.f,1.f,1.f,-1.f}, {0.f,1.f,-1.f,1.f}, {0.f,1.f,-1.f,-1.f},
|
||||
{0.f,-1.f,1.f,1.f},{0.f,-1.f,1.f,-1.f},{0.f,-1.f,-1.f,1.f},{0.f,-1.f,-1.f,-1.f},
|
||||
{1.f,0.f,1.f,1.f}, {1.f,0.f,1.f,-1.f}, {1.f,0.f,-1.f,1.f}, {1.f,0.f,-1.f,-1.f},
|
||||
{-1.f,0.f,1.f,1.f},{-1.f,0.f,1.f,-1.f},{-1.f,0.f,-1.f,1.f},{-1.f,0.f,-1.f,-1.f},
|
||||
{1.f,1.f,0.f,1.f}, {1.f,1.f,0.f,-1.f}, {1.f,-1.f,0.f,1.f}, {1.f,-1.f,0.f,-1.f},
|
||||
{-1.f,1.f,0.f,1.f},{-1.f,1.f,0.f,-1.f},{-1.f,-1.f,0.f,1.f},{-1.f,-1.f,0.f,-1.f},
|
||||
{1.f,1.f,1.f,0.f}, {1.f,1.f,-1.f,0.f}, {1.f,-1.f,1.f,0.f}, {1.f,-1.f,-1.f,0.f},
|
||||
{-1.f,1.f,1.f,0.f},{-1.f,1.f,-1.f,0.f},{-1.f,-1.f,1.f,0.f},{-1.f,-1.f,-1.f,0.f}
|
||||
};
|
||||
|
||||
for(int i(0) ; i < 32 ; ++i)
|
||||
for(int j(0) ; j < 4 ; ++j)
|
||||
gradient4[i][j] = grad4Temp[i][j];
|
||||
}
|
||||
|
||||
Simplex4D::Simplex4D(unsigned int seed) : Simplex4D()
|
||||
{
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
}
|
||||
|
||||
float Simplex4D::GetValue(float x, float y, float z, float w, float resolution)
|
||||
{
|
||||
x *= resolution;
|
||||
y *= resolution;
|
||||
z *= resolution;
|
||||
w *= resolution;
|
||||
|
||||
sum = (x + y + z + w) * SkewCoeff4D;
|
||||
skewedCubeOrigin.x = fastfloor(x + sum);
|
||||
skewedCubeOrigin.y = fastfloor(y + sum);
|
||||
skewedCubeOrigin.z = fastfloor(z + sum);
|
||||
skewedCubeOrigin.w = fastfloor(w + sum);
|
||||
|
||||
sum = (skewedCubeOrigin.x + skewedCubeOrigin.y + skewedCubeOrigin.z + skewedCubeOrigin.w) * UnskewCoeff4D;
|
||||
unskewedCubeOrigin.x = skewedCubeOrigin.x - sum;
|
||||
unskewedCubeOrigin.y = skewedCubeOrigin.y - sum;
|
||||
unskewedCubeOrigin.z = skewedCubeOrigin.z - sum;
|
||||
unskewedCubeOrigin.w = skewedCubeOrigin.w - sum;
|
||||
|
||||
unskewedDistToOrigin.x = x - unskewedCubeOrigin.x;
|
||||
unskewedDistToOrigin.y = y - unskewedCubeOrigin.y;
|
||||
unskewedDistToOrigin.z = z - unskewedCubeOrigin.z;
|
||||
unskewedDistToOrigin.w = w - unskewedCubeOrigin.w;
|
||||
|
||||
c1 = (unskewedDistToOrigin.x > unskewedDistToOrigin.y) ? 32 : 0;
|
||||
c2 = (unskewedDistToOrigin.x > unskewedDistToOrigin.z) ? 16 : 0;
|
||||
c3 = (unskewedDistToOrigin.y > unskewedDistToOrigin.z) ? 8 : 0;
|
||||
c4 = (unskewedDistToOrigin.x > unskewedDistToOrigin.w) ? 4 : 0;
|
||||
c5 = (unskewedDistToOrigin.y > unskewedDistToOrigin.w) ? 2 : 0;
|
||||
c6 = (unskewedDistToOrigin.z > unskewedDistToOrigin.w) ? 1 : 0;
|
||||
c = c1 + c2 + c3 + c4 + c5 + c6;
|
||||
|
||||
off1.x = lookupTable4D[c][0] >= 3 ? 1 : 0;
|
||||
off1.y = lookupTable4D[c][1] >= 3 ? 1 : 0;
|
||||
off1.z = lookupTable4D[c][2] >= 3 ? 1 : 0;
|
||||
off1.w = lookupTable4D[c][3] >= 3 ? 1 : 0;
|
||||
|
||||
off2.x = lookupTable4D[c][0] >= 2 ? 1 : 0;
|
||||
off2.y = lookupTable4D[c][1] >= 2 ? 1 : 0;
|
||||
off2.z = lookupTable4D[c][2] >= 2 ? 1 : 0;
|
||||
off2.w = lookupTable4D[c][3] >= 2 ? 1 : 0;
|
||||
|
||||
off3.x = lookupTable4D[c][0] >= 1 ? 1 : 0;
|
||||
off3.y = lookupTable4D[c][1] >= 1 ? 1 : 0;
|
||||
off3.z = lookupTable4D[c][2] >= 1 ? 1 : 0;
|
||||
off3.w = lookupTable4D[c][3] >= 1 ? 1 : 0;
|
||||
|
||||
d1 = unskewedDistToOrigin;
|
||||
|
||||
d2.x = d1.x - off1.x + UnskewCoeff4D;
|
||||
d2.y = d1.y - off1.y + UnskewCoeff4D;
|
||||
d2.z = d1.z - off1.z + UnskewCoeff4D;
|
||||
d2.w = d1.w - off1.w + UnskewCoeff4D;
|
||||
|
||||
d3.x = d1.x - off2.x + 2.f*UnskewCoeff4D;
|
||||
d3.y = d1.y - off2.y + 2.f*UnskewCoeff4D;
|
||||
d3.z = d1.z - off2.z + 2.f*UnskewCoeff4D;
|
||||
d3.w = d1.w - off2.w + 2.f*UnskewCoeff4D;
|
||||
|
||||
d4.x = d1.x - off3.x + 3.f*UnskewCoeff4D;
|
||||
d4.y = d1.y - off3.y + 3.f*UnskewCoeff4D;
|
||||
d4.z = d1.z - off3.z + 3.f*UnskewCoeff4D;
|
||||
d4.w = d1.w - off3.w + 3.f*UnskewCoeff4D;
|
||||
|
||||
d5.x = d1.x - 1.f + 4*UnskewCoeff4D;
|
||||
d5.y = d1.y - 1.f + 4*UnskewCoeff4D;
|
||||
d5.z = d1.z - 1.f + 4*UnskewCoeff4D;
|
||||
d5.w = d1.w - 1.f + 4*UnskewCoeff4D;
|
||||
|
||||
ii = skewedCubeOrigin.x & 255;
|
||||
jj = skewedCubeOrigin.y & 255;
|
||||
kk = skewedCubeOrigin.z & 255;
|
||||
ll = skewedCubeOrigin.w & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj + perm[kk + perm[ll]]]] & 31;
|
||||
gi1 = perm[ii + off1.x + perm[jj + off1.y + perm[kk + off1.z + perm[ll + off1.w]]]] & 31;
|
||||
gi2 = perm[ii + off2.x + perm[jj + off2.y + perm[kk + off2.z + perm[ll + off2.w]]]] & 31;
|
||||
gi3 = perm[ii + off3.x + perm[jj + off3.y + perm[kk + off3.z + perm[ll + off3.w]]]] & 31;
|
||||
gi4 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32;
|
||||
|
||||
c1 = 0.6f - d1.x*d1.x - d1.y*d1.y - d1.z*d1.z - d1.w*d1.w;
|
||||
c2 = 0.6f - d2.x*d2.x - d2.y*d2.y - d2.z*d2.z - d2.w*d2.w;
|
||||
c3 = 0.6f - d3.x*d3.x - d3.y*d3.y - d3.z*d3.z - d3.w*d3.w;
|
||||
c4 = 0.6f - d4.x*d4.x - d4.y*d4.y - d4.z*d4.z - d4.w*d4.w;
|
||||
c5 = 0.6f - d5.x*d5.x - d5.y*d5.y - d5.z*d5.z - d5.w*d5.w;
|
||||
|
||||
if(c1 < 0)
|
||||
n1 = 0;
|
||||
else
|
||||
n1 = c1*c1*c1*c1*(gradient4[gi0][0]*d1.x + gradient4[gi0][1]*d1.y + gradient4[gi0][2]*d1.z + gradient4[gi0][3]*d1.w);
|
||||
|
||||
if(c2 < 0)
|
||||
n2 = 0;
|
||||
else
|
||||
n2 = c2*c2*c2*c2*(gradient4[gi1][0]*d2.x + gradient4[gi1][1]*d2.y + gradient4[gi1][2]*d2.z + gradient4[gi1][3]*d2.w);
|
||||
|
||||
if(c3 < 0)
|
||||
n3 = 0;
|
||||
else
|
||||
n3 = c3*c3*c3*c3*(gradient4[gi2][0]*d3.x + gradient4[gi2][1]*d3.y + gradient4[gi2][2]*d3.z + gradient4[gi2][3]*d3.w);
|
||||
|
||||
if(c4 < 0)
|
||||
n4 = 0;
|
||||
else
|
||||
n4 = c4*c4*c4*c4*(gradient4[gi3][0]*d4.x + gradient4[gi3][1]*d4.y + gradient4[gi3][2]*d4.z + gradient4[gi3][3]*d4.w);
|
||||
|
||||
if(c5 < 0)
|
||||
n5 = 0;
|
||||
else
|
||||
n5 = c5*c5*c5*c5*(gradient4[gi4][0]*d5.x + gradient4[gi4][1]*d5.y + gradient4[gi4][2]*d5.z + gradient4[gi4][3]*d5.w);
|
||||
|
||||
return (n1+n2+n3+n4+n5)*27.f;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,171 @@
|
|||
// Copyright (C) 2016 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Noise/Worley.hpp>
|
||||
#include <Nazara/Noise/NoiseTools.hpp>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Worley::Worley() :
|
||||
scales{
|
||||
1.f / std::sqrt(2),
|
||||
0.5f / std::sqrt(2),
|
||||
0.5f / std::sqrt(2),
|
||||
0.5f / std::sqrt(2)
|
||||
}
|
||||
{
|
||||
function = WorleyFunction_F1;
|
||||
}
|
||||
|
||||
Worley::Worley(unsigned int seed) : Worley()
|
||||
{
|
||||
SetSeed(seed);
|
||||
Shuffle();
|
||||
}
|
||||
|
||||
void Worley::Set(WorleyFunction func)
|
||||
{
|
||||
function = func;
|
||||
}
|
||||
|
||||
float Worley::Get(std::initializer_list<float> coordinates, float scale) const
|
||||
{
|
||||
switch(coordinates.size())
|
||||
{
|
||||
case 2:
|
||||
return this->_2D(coordinates,scale);
|
||||
case 3:
|
||||
return this->_3D(coordinates,scale);
|
||||
case 4:
|
||||
return this->_4D(coordinates,scale);
|
||||
default:
|
||||
throw std::invalid_argument("Number of coordinates elements not comprised between 2 and 4");
|
||||
}
|
||||
}
|
||||
|
||||
float Worley::_2D(std::initializer_list<float> coordinates, float scale) const
|
||||
{
|
||||
std::map<float, Vector2f> featurePoints;
|
||||
std::map<float, Vector2f>::iterator it;
|
||||
|
||||
float xc, yc;
|
||||
int x0, y0;
|
||||
float fractx, fracty;
|
||||
|
||||
std::initializer_list<float>::const_iterator c = coordinates.begin();
|
||||
|
||||
xc = *(c ) * scale;
|
||||
yc = *(++c) * scale;
|
||||
|
||||
x0 = fastfloor(xc);
|
||||
y0 = fastfloor(yc);
|
||||
|
||||
fractx = xc - static_cast<float>(x0);
|
||||
fracty = yc - static_cast<float>(y0);
|
||||
|
||||
featurePoints.clear();
|
||||
|
||||
_SquareTest(x0,y0,xc,yc,featurePoints);
|
||||
|
||||
it = featurePoints.begin();
|
||||
std::advance(it,function);
|
||||
|
||||
if(fractx < it->first)
|
||||
_SquareTest(x0 - 1,y0,xc,yc,featurePoints);
|
||||
|
||||
it = featurePoints.begin();
|
||||
std::advance(it,function);
|
||||
|
||||
if(1.f - fractx < it->first)
|
||||
_SquareTest(x0 + 1,y0,xc,yc,featurePoints);
|
||||
|
||||
it = featurePoints.begin();
|
||||
std::advance(it,function);
|
||||
|
||||
if(fracty < it->first)
|
||||
_SquareTest(x0,y0 - 1,xc,yc,featurePoints);
|
||||
|
||||
it = featurePoints.begin();
|
||||
std::advance(it,function);
|
||||
|
||||
if(1.f - fracty < it->first)
|
||||
_SquareTest(x0,y0 + 1,xc,yc,featurePoints);
|
||||
|
||||
it = featurePoints.begin();
|
||||
std::advance(it,function);
|
||||
|
||||
if(fractx < it->first &&
|
||||
fracty < it->first)
|
||||
_SquareTest(x0 - 1, y0 - 1,xc,yc,featurePoints);
|
||||
|
||||
it = featurePoints.begin();
|
||||
std::advance(it,function);
|
||||
|
||||
if(1.f - fractx < it->first &&
|
||||
fracty < it->first)
|
||||
_SquareTest(x0 + 1, y0 - 1,xc,yc,featurePoints);
|
||||
|
||||
it = featurePoints.begin();
|
||||
std::advance(it,function);
|
||||
|
||||
if(fractx < it->first &&
|
||||
1.f - fracty < it->first)
|
||||
_SquareTest(x0 - 1, y0 + 1,xc,yc,featurePoints);
|
||||
|
||||
it = featurePoints.begin();
|
||||
std::advance(it,function);
|
||||
|
||||
if(1.f - fractx < it->first &&
|
||||
1.f - fracty < it->first)
|
||||
_SquareTest(x0 + 1, y0 + 1,xc,yc,featurePoints);
|
||||
|
||||
it = featurePoints.begin();
|
||||
std::advance(it,function);
|
||||
|
||||
return it->first * scales[function];
|
||||
}
|
||||
|
||||
float Worley::_3D(std::initializer_list<float> coordinates, float scale) const
|
||||
{
|
||||
throw std::runtime_error("Worley 3D not available yet.");
|
||||
}
|
||||
|
||||
float Worley::_4D(std::initializer_list<float> coordinates, float scale) const
|
||||
{
|
||||
throw std::runtime_error("Worley 4D not available yet.");
|
||||
}
|
||||
|
||||
|
||||
void Worley::_SquareTest(int xi, int yi, float x, float y, std::map<float, Vector2f> & featurePoints) const
|
||||
{
|
||||
int ii = xi & 255;
|
||||
int jj = yi & 255;
|
||||
|
||||
int seed = perm[ii + perm[jj]];
|
||||
|
||||
//On initialise notre rng avec seed
|
||||
std::minstd_rand0 randomNumberGenerator(seed);
|
||||
|
||||
//On prend un nombre de points à déterminer dans le cube, compris entre 1 et 8
|
||||
unsigned int m = (seed & 7) + 1;
|
||||
|
||||
//On calcule les emplacements des différents points
|
||||
for(unsigned int i(0) ; i < m ; ++i)
|
||||
{
|
||||
Nz::Vector2f featurePoint;
|
||||
featurePoint.x = (randomNumberGenerator() & 1023) / 1023.f + static_cast<float>(xi);
|
||||
featurePoint.y = (randomNumberGenerator() & 1023) / 1023.f + static_cast<float>(yi);
|
||||
|
||||
// TODO : Check order is correct
|
||||
float distance = std::sqrt((featurePoint.x - x) * (featurePoint.x - x) +
|
||||
(featurePoint.y - y) * (featurePoint.y - y));
|
||||
|
||||
//Insertion dans la liste triée
|
||||
featurePoints[distance] = featurePoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue