Skip to content

Commit

Permalink
Perm based octave offset
Browse files Browse the repository at this point in the history
  • Loading branch information
Auburn committed Jul 23, 2016
1 parent 5ef4f1a commit a225ead
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 55 deletions.
91 changes: 36 additions & 55 deletions FastNoise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,7 @@ float FastNoise::GetValueFractal(float x, float y, float z)

float FastNoise::SingleValueFractalFBM(float x, float y, float z)
{
unsigned char offset = 0;
float sum = SingleValue(m_perm[offset], x, y, z);
float sum = SingleValue(m_perm[0], x, y, z);
float max = 1.0f;
float amp = 1.0f;
unsigned int i = 0;
Expand All @@ -513,16 +512,15 @@ float FastNoise::SingleValueFractalFBM(float x, float y, float z)

amp *= m_gain;
max += amp;
sum += SingleValue(m_perm[++offset], x, y, z) * amp;
sum += SingleValue(m_perm[i], x, y, z) * amp;
}

return sum / max;
}

float FastNoise::SingleValueFractalBillow(float x, float y, float z)
{
unsigned char offset = 0;
float sum = FastAbs(SingleValue(m_perm[offset], x, y, z)) * 2.0f - 1.0f;
float sum = FastAbs(SingleValue(m_perm[0], x, y, z)) * 2.0f - 1.0f;
float max = 1.0f;
float amp = 1.0f;
unsigned int i = 0;
Expand All @@ -535,16 +533,15 @@ float FastNoise::SingleValueFractalBillow(float x, float y, float z)

amp *= m_gain;
max += amp;
sum += (FastAbs(SingleValue(m_perm[++offset], x, y, z)) * 2.0f - 1.0f) * amp;
sum += (FastAbs(SingleValue(m_perm[i], x, y, z)) * 2.0f - 1.0f) * amp;
}

return sum / max;
}

float FastNoise::SingleValueFractalRigidMulti(float x, float y, float z)
{
unsigned char offset = 0;
float sum = 1.0f - FastAbs(SingleValue(m_perm[offset], x, y, z));
float sum = 1.0f - FastAbs(SingleValue(m_perm[0], x, y, z));
float amp = 1.0f;
unsigned int i = 0;

Expand All @@ -555,7 +552,7 @@ float FastNoise::SingleValueFractalRigidMulti(float x, float y, float z)
z *= m_lacunarity;

amp *= m_gain;
sum -= (1.0f - FastAbs(SingleValue(m_perm[++offset], x, y, z))) * amp;
sum -= (1.0f - FastAbs(SingleValue(m_perm[i], x, y, z))) * amp;
}

return sum;
Expand Down Expand Up @@ -626,8 +623,7 @@ float FastNoise::GetValueFractal(float x, float y)

float FastNoise::SingleValueFractalFBM(float x, float y)
{
unsigned char offset = 0;
float sum = SingleValue(m_perm[offset], x, y);
float sum = SingleValue(m_perm[0], x, y);
float max = 1.0f;
float amp = 1.0f;
unsigned int i = 0;
Expand All @@ -639,19 +635,17 @@ float FastNoise::SingleValueFractalFBM(float x, float y)

amp *= m_gain;
max += amp;
sum += SingleValue(m_perm[++offset], x, y) * amp;
sum += SingleValue(m_perm[i], x, y) * amp;
}

return sum / max;
}

float FastNoise::SingleValueFractalBillow(float x, float y)
{
unsigned char offset = 0;
float sum = FastAbs(SingleValue(m_perm[offset], x, y)) * 2.0f - 1.0f;
float sum = FastAbs(SingleValue(m_perm[0], x, y)) * 2.0f - 1.0f;
float max = 1.0f;
float amp = 1.0f;

unsigned int i = 0;

while (++i < m_octaves)
Expand All @@ -660,16 +654,15 @@ float FastNoise::SingleValueFractalBillow(float x, float y)
y *= m_lacunarity;
amp *= m_gain;
max += amp;
sum += (FastAbs(SingleValue(m_perm[++offset], x, y)) * 2.0f - 1.0f) * amp;
sum += (FastAbs(SingleValue(m_perm[i], x, y)) * 2.0f - 1.0f) * amp;
}

return sum / max;
}

float FastNoise::SingleValueFractalRigidMulti(float x, float y)
{
unsigned char offset = 0;
float sum = 1.0f - FastAbs(SingleValue(m_perm[offset], x, y));
float sum = 1.0f - FastAbs(SingleValue(m_perm[0], x, y));
float amp = 1.0f;
unsigned int i = 0;

Expand All @@ -679,7 +672,7 @@ float FastNoise::SingleValueFractalRigidMulti(float x, float y)
y *= m_lacunarity;

amp *= m_gain;
sum -= (1.0f - FastAbs(SingleValue(m_perm[++offset], x, y))) * amp;
sum -= (1.0f - FastAbs(SingleValue(m_perm[i], x, y))) * amp;
}

return sum;
Expand Down Expand Up @@ -742,8 +735,7 @@ float FastNoise::GetGradientFractal(float x, float y, float z)

float FastNoise::SingleGradientFractalFBM(float x, float y, float z)
{
unsigned char offset = 0;
float sum = SingleGradient(m_perm[offset], x, y, z);
float sum = SingleGradient(m_perm[0], x, y, z);
float max = 1.0f;
float amp = 1.0f;
unsigned int i = 0;
Expand All @@ -756,16 +748,15 @@ float FastNoise::SingleGradientFractalFBM(float x, float y, float z)

amp *= m_gain;
max += amp;
sum += SingleGradient(m_perm[++offset], x, y, z) * amp;
sum += SingleGradient(m_perm[i], x, y, z) * amp;
}

return sum / max;
}

float FastNoise::SingleGradientFractalBillow(float x, float y, float z)
{
unsigned char offset = 0;
float sum = FastAbs(SingleGradient(m_perm[offset], x, y, z)) * 2.0f - 1.0f;
float sum = FastAbs(SingleGradient(m_perm[0], x, y, z)) * 2.0f - 1.0f;
float max = 1.0f;
float amp = 1.0f;
unsigned int i = 0;
Expand All @@ -778,16 +769,15 @@ float FastNoise::SingleGradientFractalBillow(float x, float y, float z)

amp *= m_gain;
max += amp;
sum += (FastAbs(SingleGradient(m_perm[++offset], x, y, z)) * 2.0f - 1.0f) * amp;
sum += (FastAbs(SingleGradient(m_perm[i], x, y, z)) * 2.0f - 1.0f) * amp;
}

return sum / max;
}

float FastNoise::SingleGradientFractalRigidMulti(float x, float y, float z)
{
unsigned char offset = 0;
float sum = 1.0f - FastAbs(SingleGradient(m_perm[offset], x, y, z));
float sum = 1.0f - FastAbs(SingleGradient(m_perm[0], x, y, z));
float amp = 1.0f;
unsigned int i = 0;

Expand All @@ -798,7 +788,7 @@ float FastNoise::SingleGradientFractalRigidMulti(float x, float y, float z)
z *= m_lacunarity;

amp *= m_gain;
sum -= (1.0f - FastAbs(SingleGradient(m_perm[++offset], x, y, z))) * amp;
sum -= (1.0f - FastAbs(SingleGradient(m_perm[i], x, y, z))) * amp;
}

return sum;
Expand Down Expand Up @@ -876,8 +866,7 @@ float FastNoise::GetGradientFractal(float x, float y)

float FastNoise::SingleGradientFractalFBM(float x, float y)
{
unsigned char offset = 0;
float sum = SingleGradient(m_perm[offset], x, y);
float sum = SingleGradient(m_perm[0], x, y);
float max = 1.0f;
float amp = 1.0f;
unsigned int i = 0;
Expand All @@ -889,16 +878,15 @@ float FastNoise::SingleGradientFractalFBM(float x, float y)

amp *= m_gain;
max += amp;
sum += SingleGradient(m_perm[++offset], x, y) * amp;
sum += SingleGradient(m_perm[i], x, y) * amp;
}

return sum / max;
}

float FastNoise::SingleGradientFractalBillow(float x, float y)
{
unsigned char offset = 0;
float sum = FastAbs(SingleGradient(m_perm[offset], x, y)) * 2.0f - 1.0f;
float sum = FastAbs(SingleGradient(m_perm[0], x, y)) * 2.0f - 1.0f;
float max = 1.0f;
float amp = 1.0f;
unsigned int i = 0;
Expand All @@ -910,16 +898,15 @@ float FastNoise::SingleGradientFractalBillow(float x, float y)

amp *= m_gain;
max += amp;
sum += (FastAbs(SingleGradient(m_perm[++offset], x, y)) * 2.0f - 1.0f) * amp;
sum += (FastAbs(SingleGradient(m_perm[i], x, y)) * 2.0f - 1.0f) * amp;
}

return sum / max;
}

float FastNoise::SingleGradientFractalRigidMulti(float x, float y)
{
unsigned char offset = 0;
float sum = 1.0f - FastAbs(SingleGradient(m_perm[offset], x, y));
float sum = 1.0f - FastAbs(SingleGradient(m_perm[0], x, y));
float amp = 1.0f;
unsigned int i = 0;

Expand All @@ -929,7 +916,7 @@ float FastNoise::SingleGradientFractalRigidMulti(float x, float y)
y *= m_lacunarity;

amp *= m_gain;
sum -= (1.0f - FastAbs(SingleGradient(m_perm[++offset], x, y))) * amp;
sum -= (1.0f - FastAbs(SingleGradient(m_perm[i], x, y))) * amp;
}

return sum;
Expand Down Expand Up @@ -998,8 +985,7 @@ float FastNoise::GetSimplexFractal(float x, float y, float z)

float FastNoise::SingleSimplexFractalFBM(float x, float y, float z)
{
unsigned char offset = 0;
float sum = SingleSimplex(m_perm[offset], x, y, z);
float sum = SingleSimplex(m_perm[0], x, y, z);
float max = 1.0f;
float amp = 1.0f;
unsigned int i = 0;
Expand All @@ -1012,16 +998,15 @@ float FastNoise::SingleSimplexFractalFBM(float x, float y, float z)

amp *= m_gain;
max += amp;
sum += SingleSimplex(m_perm[++offset], x, y, z) * amp;
sum += SingleSimplex(m_perm[i], x, y, z) * amp;
}

return sum / max;
}

float FastNoise::SingleSimplexFractalBillow(float x, float y, float z)
{
unsigned char offset = 0;
float sum = FastAbs(SingleSimplex(m_perm[offset], x, y, z)) * 2.0f - 1.0f;
float sum = FastAbs(SingleSimplex(m_perm[0], x, y, z)) * 2.0f - 1.0f;
float max = 1.0f;
float amp = 1.0f;
unsigned int i = 0;
Expand All @@ -1034,16 +1019,15 @@ float FastNoise::SingleSimplexFractalBillow(float x, float y, float z)

amp *= m_gain;
max += amp;
sum += (FastAbs(SingleSimplex(m_perm[++offset], x, y, z)) * 2.0f - 1.0f) * amp;
sum += (FastAbs(SingleSimplex(m_perm[i], x, y, z)) * 2.0f - 1.0f) * amp;
}

return sum / max;
}

float FastNoise::SingleSimplexFractalRigidMulti(float x, float y, float z)
{
unsigned char offset = 0;
float sum = 1.0f - FastAbs(SingleSimplex(m_perm[offset], x, y, z));
float sum = 1.0f - FastAbs(SingleSimplex(m_perm[0], x, y, z));
float amp = 1.0f;
unsigned int i = 0;

Expand All @@ -1054,7 +1038,7 @@ float FastNoise::SingleSimplexFractalRigidMulti(float x, float y, float z)
z *= m_lacunarity;

amp *= m_gain;
sum -= (1.0f - FastAbs(SingleSimplex(m_perm[++offset], x, y, z))) * amp;
sum -= (1.0f - FastAbs(SingleSimplex(m_perm[i], x, y, z))) * amp;
}

return sum;
Expand Down Expand Up @@ -1185,8 +1169,7 @@ float FastNoise::GetSimplexFractal(float x, float y)

float FastNoise::SingleSimplexFractalFBM(float x, float y)
{
unsigned char offset = 0;
float sum = SingleSimplex(m_perm[offset], x, y);
float sum = SingleSimplex(m_perm[0], x, y);
float max = 1.0f;
float amp = 1.0f;
unsigned int i = 0;
Expand All @@ -1198,16 +1181,15 @@ float FastNoise::SingleSimplexFractalFBM(float x, float y)

amp *= m_gain;
max += amp;
sum += SingleSimplex(m_perm[++offset], x, y) * amp;
sum += SingleSimplex(m_perm[i], x, y) * amp;
}

return sum / max;
}

float FastNoise::SingleSimplexFractalBillow(float x, float y)
{
unsigned char offset = 0;
float sum = FastAbs(SingleSimplex(m_perm[offset], x, y)) * 2.0f - 1.0f;
float sum = FastAbs(SingleSimplex(m_perm[0], x, y)) * 2.0f - 1.0f;
float max = 1.0f;
float amp = 1.0f;
unsigned int i = 0;
Expand All @@ -1219,16 +1201,15 @@ float FastNoise::SingleSimplexFractalBillow(float x, float y)

amp *= m_gain;
max += amp;
sum += (FastAbs(SingleSimplex(m_perm[++offset], x, y)) * 2.0f - 1.0f) * amp;
sum += (FastAbs(SingleSimplex(m_perm[i], x, y)) * 2.0f - 1.0f) * amp;
}

return sum / max;
}

float FastNoise::SingleSimplexFractalRigidMulti(float x, float y)
{
unsigned char offset = 0;
float sum = 1.0f - FastAbs(SingleSimplex(m_perm[offset], x, y));
float sum = 1.0f - FastAbs(SingleSimplex(m_perm[0], x, y));
float amp = 1.0f;
unsigned int i = 0;

Expand All @@ -1238,7 +1219,7 @@ float FastNoise::SingleSimplexFractalRigidMulti(float x, float y)
y *= m_lacunarity;

amp *= m_gain;
sum -= (1.0f - FastAbs(SingleSimplex(m_perm[++offset], x, y))) * amp;
sum -= (1.0f - FastAbs(SingleSimplex(m_perm[i], x, y))) * amp;
}

return sum;
Expand Down
1 change: 1 addition & 0 deletions FastNoise.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class FastNoise
inline unsigned char Index2D_256(unsigned char offset, int x, int y);
inline unsigned char Index3D_256(unsigned char offset, int x, int y, int z);
inline unsigned char Index4D_256(unsigned char offset, int x, int y, int z, int w);

inline float ValCoord2DFast(unsigned char offset, int x, int y);
inline float ValCoord3DFast(unsigned char offset, int x, int y, int z);
inline float GradCoord2D(unsigned char offset, int x, int y, float xd, float yd);
Expand Down

0 comments on commit a225ead

Please sign in to comment.