This repository has been archived by the owner on Apr 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 88
Add OpenSimplex2, alternative to Simplex. #43
Open
KdotJPG
wants to merge
2
commits into
Auburn:master
Choose a base branch
from
KdotJPG:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -461,6 +461,7 @@ static float FUNC(INV_SQRT)(float x) | |||||
#define SIMDf_XOR(a,b) SIMDf_CAST_TO_FLOAT(SIMDi_CAST_TO_INT(a) ^ SIMDi_CAST_TO_INT(b)) | ||||||
|
||||||
#define SIMDf_FLOOR(a) floorf(a) | ||||||
#define SIMDf_ROUND(a) roundf(a) | ||||||
#define SIMDf_ABS(a) fabsf(a) | ||||||
#define SIMDf_BLENDV(a,b,mask) (mask ? (b) : (a)) | ||||||
#define SIMDf_GATHER(p,a) (*(reinterpret_cast<const float*>(p)+(a))) | ||||||
|
@@ -566,15 +567,18 @@ static SIMDf SIMDf_NUM(10); | |||||
static SIMDf SIMDf_NUM(15); | ||||||
static SIMDf SIMDf_NUM(32); | ||||||
static SIMDf SIMDf_NUM(999999); | ||||||
static SIMDf SIMDf_NUM(_1); | ||||||
|
||||||
static SIMDf SIMDf_NUM(0_5); | ||||||
static SIMDf SIMDf_NUM(0_6); | ||||||
static SIMDf SIMDf_NUM(15_5); | ||||||
static SIMDf SIMDf_NUM(511_5); | ||||||
static SIMDf SIMDf_NUM(32768_5); | ||||||
|
||||||
//static SIMDf SIMDf_NUM(cellJitter); | ||||||
static SIMDf SIMDf_NUM(F3); | ||||||
static SIMDf SIMDf_NUM(G3); | ||||||
static SIMDf SIMDf_NUM(R3); | ||||||
static SIMDf SIMDf_NUM(G33); | ||||||
static SIMDf SIMDf_NUM(hash2Float); | ||||||
static SIMDf SIMDf_NUM(vectorSize); | ||||||
|
@@ -632,15 +636,18 @@ void FUNC(InitSIMDValues)() | |||||
SIMDf_NUM(15) = SIMDf_SET(15.0f); | ||||||
SIMDf_NUM(32) = SIMDf_SET(32.0f); | ||||||
SIMDf_NUM(999999) = SIMDf_SET(999999.0f); | ||||||
SIMDf_NUM(_1) = SIMDf_SET(-1.0f); | ||||||
|
||||||
SIMDf_NUM(0_5) = SIMDf_SET(0.5f); | ||||||
SIMDf_NUM(0_6) = SIMDf_SET(0.6f); | ||||||
SIMDf_NUM(15_5) = SIMDf_SET(15.5f); | ||||||
SIMDf_NUM(511_5) = SIMDf_SET(511.5f); | ||||||
SIMDf_NUM(32768_5) = SIMDf_SET(32768.5f); | ||||||
|
||||||
//SIMDf_NUM(cellJitter) = SIMDf_SET(0.39614f); | ||||||
SIMDf_NUM(F3) = SIMDf_SET(1.f / 3.f); | ||||||
SIMDf_NUM(G3) = SIMDf_SET(1.f / 6.f); | ||||||
SIMDf_NUM(R3) = SIMDf_SET(2.f / 3.f); | ||||||
SIMDf_NUM(G33) = SIMDf_SET((3.f / 6.f) - 1.f); | ||||||
SIMDf_NUM(hash2Float) = SIMDf_SET(1.f / 2147483648.f); | ||||||
SIMDf_NUM(vectorSize) = SIMDf_SET(VECTOR_SIZE); | ||||||
|
@@ -922,6 +929,65 @@ static SIMDf VECTORCALL FUNC(SimplexSingle)(SIMDi seed, SIMDf x, SIMDf y, SIMDf | |||||
return SIMDf_MUL(SIMDf_NUM(32), SIMDf_MASK_ADD(n0, SIMDf_MASK_ADD(n1, SIMDf_MASK_ADD(n2, v3, v2), v1), v0)); | ||||||
} | ||||||
|
||||||
static SIMDf VECTORCALL FUNC(OpenSimplex2Single)(SIMDi seed, SIMDf x, SIMDf y, SIMDf z) | ||||||
{ | ||||||
SIMDf f = SIMDf_MUL(SIMDf_NUM(R3), SIMDf_ADD(SIMDf_ADD(x, y), z)); | ||||||
SIMDf xr = SIMDf_SUB(f, x); | ||||||
SIMDf yr = SIMDf_SUB(f, y); | ||||||
SIMDf zr = SIMDf_SUB(f, z); | ||||||
|
||||||
SIMDf val = SIMDf_NUM(0); | ||||||
for (int i = 0; i < 2; i++) | ||||||
{ | ||||||
SIMDf v0xr = SIMDf_FLOOR(SIMDf_ADD(xr, SIMDf_NUM(0_5))); | ||||||
SIMDf v0yr = SIMDf_FLOOR(SIMDf_ADD(yr, SIMDf_NUM(0_5))); | ||||||
SIMDf v0zr = SIMDf_FLOOR(SIMDf_ADD(zr, SIMDf_NUM(0_5))); | ||||||
SIMDf d0xr = SIMDf_SUB(xr, v0xr); | ||||||
SIMDf d0yr = SIMDf_SUB(yr, v0yr); | ||||||
SIMDf d0zr = SIMDf_SUB(zr, v0zr); | ||||||
|
||||||
SIMDf score0xr = SIMDf_ABS(d0xr); | ||||||
SIMDf score0yr = SIMDf_ABS(d0yr); | ||||||
SIMDf score0zr = SIMDf_ABS(d0zr); | ||||||
MASK dir0xr = SIMDf_LESS_EQUAL(SIMDf_MAX(score0yr, score0zr), score0xr); | ||||||
MASK dir0yr = SIMDi_AND_NOT(dir0xr, SIMDf_LESS_EQUAL(SIMDf_MAX(score0zr, score0xr), score0yr)); | ||||||
MASK dir0zr = SIMDi_NOT(SIMDi_OR(dir0xr, dir0yr)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
SIMDf v1xr = SIMDf_ADD(v0xr, SIMDf_BLENDV(SIMDf_NUM(0), SIMDf_BLENDV(SIMDf_NUM(1), SIMDf_NUM(_1), SIMDf_LESS_THAN(d0xr, SIMDf_NUM(0))), dir0xr)); | ||||||
SIMDf v1yr = SIMDf_ADD(v0yr, SIMDf_BLENDV(SIMDf_NUM(0), SIMDf_BLENDV(SIMDf_NUM(1), SIMDf_NUM(_1), SIMDf_LESS_THAN(d0yr, SIMDf_NUM(0))), dir0yr)); | ||||||
SIMDf v1zr = SIMDf_ADD(v0zr, SIMDf_BLENDV(SIMDf_NUM(0), SIMDf_BLENDV(SIMDf_NUM(1), SIMDf_NUM(_1), SIMDf_LESS_THAN(d0zr, SIMDf_NUM(0))), dir0zr)); | ||||||
SIMDf d1xr = SIMDf_SUB(xr, v1xr); | ||||||
SIMDf d1yr = SIMDf_SUB(yr, v1yr); | ||||||
SIMDf d1zr = SIMDf_SUB(zr, v1zr); | ||||||
|
||||||
SIMDi hv0xr = SIMDi_MUL(SIMDi_CONVERT_TO_INT(v0xr), SIMDi_NUM(xPrime)); | ||||||
SIMDi hv0yr = SIMDi_MUL(SIMDi_CONVERT_TO_INT(v0yr), SIMDi_NUM(yPrime)); | ||||||
SIMDi hv0zr = SIMDi_MUL(SIMDi_CONVERT_TO_INT(v0zr), SIMDi_NUM(zPrime)); | ||||||
SIMDi hv1xr = SIMDi_MUL(SIMDi_CONVERT_TO_INT(v1xr), SIMDi_NUM(xPrime)); | ||||||
SIMDi hv1yr = SIMDi_MUL(SIMDi_CONVERT_TO_INT(v1yr), SIMDi_NUM(yPrime)); | ||||||
SIMDi hv1zr = SIMDi_MUL(SIMDi_CONVERT_TO_INT(v1zr), SIMDi_NUM(zPrime)); | ||||||
|
||||||
SIMDf t0 = SIMDf_NMUL_ADD(d0zr, d0zr, SIMDf_NMUL_ADD(d0yr, d0yr, SIMDf_NMUL_ADD(d0xr, d0xr, SIMDf_NUM(0_6)))); | ||||||
SIMDf t1 = SIMDf_NMUL_ADD(d1zr, d1zr, SIMDf_NMUL_ADD(d1yr, d1yr, SIMDf_NMUL_ADD(d1xr, d1xr, SIMDf_NUM(0_6)))); | ||||||
MASK n0 = SIMDf_GREATER_THAN(t0, SIMDf_NUM(0)); | ||||||
MASK n1 = SIMDf_GREATER_THAN(t1, SIMDf_NUM(0)); | ||||||
t0 = SIMDf_MUL(t0, t0); | ||||||
t1 = SIMDf_MUL(t1, t1); | ||||||
|
||||||
SIMDf v0 = SIMDf_MUL(SIMDf_MUL(t0, t0), FUNC(GradCoord)(seed, hv0xr, hv0yr, hv0zr, d0xr, d0yr, d0zr)); | ||||||
SIMDf v1 = SIMDf_MUL(SIMDf_MUL(t1, t1), FUNC(GradCoord)(seed, hv1xr, hv1yr, hv1zr, d1xr, d1yr, d1zr)); | ||||||
|
||||||
val = SIMDf_MASK_ADD(n0, SIMDf_MASK_ADD(n1, val, v1), v0); | ||||||
|
||||||
if (i == 0) { | ||||||
xr = SIMDf_ADD(xr, SIMDf_NUM(32768_5)); | ||||||
yr = SIMDf_ADD(yr, SIMDf_NUM(32768_5)); | ||||||
zr = SIMDf_ADD(zr, SIMDf_NUM(32768_5)); | ||||||
} | ||||||
} | ||||||
|
||||||
return SIMDf_MUL(SIMDf_NUM(32), val); | ||||||
} | ||||||
|
||||||
static SIMDf VECTORCALL FUNC(CubicSingle)(SIMDi seed, SIMDf x, SIMDf y, SIMDf z) | ||||||
{ | ||||||
SIMDf xf1 = SIMDf_FLOOR(x); | ||||||
|
@@ -1376,6 +1442,9 @@ FILL_FRACTAL_SET(Perlin) | |||||
FILL_SET(Simplex) | ||||||
FILL_FRACTAL_SET(Simplex) | ||||||
|
||||||
FILL_SET(OpenSimplex2) | ||||||
FILL_FRACTAL_SET(OpenSimplex2) | ||||||
|
||||||
//FILL_SET(WhiteNoise) | ||||||
|
||||||
FILL_SET(Cubic) | ||||||
|
@@ -1491,6 +1560,9 @@ void SIMD_LEVEL_CLASS::Fill##func##FractalSet(float* noiseSet, FastNoiseVectorSe | |||||
FILL_VECTOR_SET(Simplex) | ||||||
FILL_FRACTAL_VECTOR_SET(Simplex) | ||||||
|
||||||
FILL_VECTOR_SET(OpenSimplex2) | ||||||
FILL_FRACTAL_VECTOR_SET(OpenSimplex2) | ||||||
|
||||||
FILL_VECTOR_SET(WhiteNoise) | ||||||
|
||||||
FILL_VECTOR_SET(Cubic) | ||||||
|
@@ -1765,6 +1837,12 @@ static SIMDf VECTORCALL FUNC(CellularLookup##distanceFunc##Single)(SIMDi seedV, | |||||
case FastNoiseSIMD::SimplexFractal:\ | ||||||
CELLULAR_LOOKUP_FRACTAL_VALUE(Simplex);\ | ||||||
break; \ | ||||||
case FastNoiseSIMD::OpenSimplex2:\ | ||||||
result = FUNC(OpenSimplex2Single)(seedV, xF, yF, zF); \ | ||||||
break;\ | ||||||
case FastNoiseSIMD::OpenSimplex2Fractal:\ | ||||||
CELLULAR_LOOKUP_FRACTAL_VALUE(OpenSimplex2);\ | ||||||
break; \ | ||||||
case FastNoiseSIMD::Cubic:\ | ||||||
result = FUNC(CubicSingle)(seedV, xF, yF, zF); \ | ||||||
break;\ | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.