Skip to content

Commit 5cf601a

Browse files
committed
Merge remote-tracking branch 'origin/NewFastSIMD' into NewFastSIMD
2 parents ef2a604 + 16dd2ef commit 5cf601a

File tree

5 files changed

+67
-64
lines changed

5 files changed

+67
-64
lines changed

include/FastNoise/Generators/Simplex.h

+23-9
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ namespace FastNoise
66
class Simplex : public virtual VariableRange<ScalableGenerator>
77
{
88
public:
9-
void SetType( SimplexType value ) { mType = value; }
109
const Metadata& GetMetadata() const override;
11-
12-
protected:
13-
SimplexType mType = SimplexType::Standard;
1410
};
1511

1612
#ifdef FASTNOISE_METADATA
@@ -26,12 +22,30 @@ namespace FastNoise
2622
description =
2723
"Smooth gradient noise from an N dimensional simplex grid\n"
2824
"Developed by Ken Perlin in 2001";
25+
}
26+
};
27+
#endif
28+
29+
class SimplexSmooth : public virtual VariableRange<ScalableGenerator>
30+
{
31+
public:
32+
const Metadata& GetMetadata() const override;
33+
};
34+
35+
#ifdef FASTNOISE_METADATA
36+
template<>
37+
struct MetadataT<SimplexSmooth> : MetadataT<VariableRange<ScalableGenerator>>
38+
{
39+
SmartNode<> CreateNode( FastSIMD::FeatureSet ) const override;
40+
41+
MetadataT()
42+
{
43+
groups.push_back( "Coherent Noise" );
2944

30-
this->AddVariableEnum(
31-
{ "Type", "Noise character style" },
32-
SimplexType::Standard, &Simplex::SetType,
33-
kSimplexType_Strings
34-
);
45+
description =
46+
"Extra smooth gradient noise from an N dimensional simplex grid\n"
47+
"Slower to generate than Simplex noise\n"
48+
"Developed by K.jpg";
3549
}
3650
};
3751
#endif

include/FastNoise/Generators/Simplex.inl

+22-47
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,7 @@
44
template<FastSIMD::FeatureSet SIMD>
55
class FastSIMD::DispatchClass<FastNoise::Simplex, SIMD> final : public virtual FastNoise::Simplex, public FastSIMD::DispatchClass<FastNoise::VariableRange<ScalableGenerator>, SIMD>
66
{
7-
float32v FS_VECTORCALL Gen( int32v seed, float32v x, float32v y ) const final
8-
{
9-
switch( mType ) {
10-
case SimplexType::Standard:
11-
return Gen_Standard( seed, x, y );
12-
case SimplexType::Smooth:
13-
return Gen_Smooth( seed, x, y );
14-
}
15-
}
16-
17-
float32v FS_VECTORCALL Gen( int32v seed, float32v x, float32v y, float32v z ) const final
18-
{
19-
switch( mType ) {
20-
case SimplexType::Standard:
21-
return Gen_Standard( seed, x, y, z );
22-
case SimplexType::Smooth:
23-
return Gen_Smooth( seed, x, y, z );
24-
}
25-
}
26-
27-
float32v FS_VECTORCALL Gen( int32v seed, float32v x, float32v y, float32v z, float32v w ) const final
28-
{
29-
switch( mType ) {
30-
case SimplexType::Standard:
31-
return Gen_Standard( seed, x, y, z, w );
32-
case SimplexType::Smooth:
33-
return Gen_Smooth( seed, x, y, z, w );
34-
}
35-
}
36-
37-
float32v FS_VECTORCALL Gen_Standard( int32v seed, float32v x, float32v y ) const
7+
float32v FS_VECTORCALL Gen( int32v seed, float32v x, float32v y ) const
388
{
399
this->ScalePositions( x, y );
4010

@@ -90,7 +60,7 @@ class FastSIMD::DispatchClass<FastNoise::Simplex, SIMD> final : public virtual F
9060
-1 / kBounding, 1 / kBounding );
9161
}
9262

93-
float32v FS_VECTORCALL Gen_Standard( int32v seed, float32v x, float32v y, float32v z ) const
63+
float32v FS_VECTORCALL Gen( int32v seed, float32v x, float32v y, float32v z ) const
9464
{
9565
this->ScalePositions( x, y, z );
9666

@@ -125,19 +95,19 @@ class FastSIMD::DispatchClass<FastNoise::Simplex, SIMD> final : public virtual F
12595

12696
mask32v maskX1 = xGreaterEqualY & xGreaterEqualZ;
12797
mask32v maskY1 = FS::BitwiseAndNot( yGreaterEqualZ, xGreaterEqualY );
128-
mask32v maskZ1 = FS::BitwiseAndNot( ~xGreaterEqualZ, yGreaterEqualZ );
98+
mask32v maskZ1 = xGreaterEqualZ | yGreaterEqualZ; // Inv masked
12999

130-
mask32v nMaskX2 = ~( xGreaterEqualY | xGreaterEqualZ );
131-
mask32v nMaskY2 = xGreaterEqualY & ~yGreaterEqualZ;
100+
mask32v nMaskX2 = xGreaterEqualY | xGreaterEqualZ; // Inv masked
101+
mask32v nMaskY2 = FS::BitwiseAndNot( xGreaterEqualY, yGreaterEqualZ );
132102
mask32v nMaskZ2 = xGreaterEqualZ & yGreaterEqualZ;
133103

134104
float32v dx3 = dx0 - float32v( kReflectUnskew3 * 3 + 1 );
135105
float32v dy3 = dy0 - float32v( kReflectUnskew3 * 3 + 1 );
136106
float32v dz3 = dz0 - float32v( kReflectUnskew3 * 3 + 1 );
137107
float32v dx1 = FS::MaskedSub( maskX1, dx3, float32v( 1 ) ); // kReflectUnskew3 * 3 + 1 = kReflectUnskew3, so dx0 - kReflectUnskew3 = dx3
138108
float32v dy1 = FS::MaskedSub( maskY1, dy3, float32v( 1 ) );
139-
float32v dz1 = FS::MaskedSub( maskZ1, dz3, float32v( 1 ) );
140-
float32v dx2 = FS::MaskedIncrement( nMaskX2, dx0 ); // kReflectUnskew3 * 2 - 1 = 0, so dx0 + ( kReflectUnskew3 * 2 - 1 ) = dx0
109+
float32v dz1 = FS::InvMaskedSub( maskZ1, dz3, float32v( 1 ) );
110+
float32v dx2 = FS::MaskedIncrement( ~nMaskX2, dx0 ); // kReflectUnskew3 * 2 - 1 = 0, so dx0 + ( kReflectUnskew3 * 2 - 1 ) = dx0
141111
float32v dy2 = FS::MaskedIncrement( nMaskY2, dy0 );
142112
float32v dz2 = FS::MaskedIncrement( nMaskZ2, dz0 );
143113

@@ -157,8 +127,8 @@ class FastSIMD::DispatchClass<FastNoise::Simplex, SIMD> final : public virtual F
157127
falloff3 *= falloff3; falloff3 *= falloff3;
158128

159129
float32v gradientRampValue0 = GetGradientDotCommon( HashPrimes( seed, xPrimedBase, yPrimedBase, zPrimedBase ), dx0, dy0, dz0 );
160-
float32v gradientRampValue1 = GetGradientDotCommon( HashPrimes( seed, FS::MaskedAdd( maskX1, xPrimedBase, int32v( Primes::X ) ), FS::MaskedAdd( maskY1, yPrimedBase, int32v( Primes::Y ) ), FS::MaskedAdd( maskZ1, zPrimedBase, int32v( Primes::Z ) ) ), dx1, dy1, dz1 );
161-
float32v gradientRampValue2 = GetGradientDotCommon( HashPrimes( seed, FS::InvMaskedAdd( nMaskX2, xPrimedBase, int32v( Primes::X ) ), FS::InvMaskedAdd( nMaskY2, yPrimedBase, int32v( Primes::Y ) ), FS::InvMaskedAdd( nMaskZ2, zPrimedBase, int32v( Primes::Z ) ) ), dx2, dy2, dz2 );
130+
float32v gradientRampValue1 = GetGradientDotCommon( HashPrimes( seed, FS::MaskedAdd( maskX1, xPrimedBase, int32v( Primes::X ) ), FS::MaskedAdd( maskY1, yPrimedBase, int32v( Primes::Y ) ), FS::InvMaskedAdd( maskZ1, zPrimedBase, int32v( Primes::Z ) ) ), dx1, dy1, dz1 );
131+
float32v gradientRampValue2 = GetGradientDotCommon( HashPrimes( seed, FS::MaskedAdd( nMaskX2, xPrimedBase, int32v( Primes::X ) ), FS::InvMaskedAdd( nMaskY2, yPrimedBase, int32v( Primes::Y ) ), FS::InvMaskedAdd( nMaskZ2, zPrimedBase, int32v( Primes::Z ) ) ), dx2, dy2, dz2 );
162132
float32v gradientRampValue3 = GetGradientDotCommon( HashPrimes( seed, xPrimedBase + int32v( Primes::X ), yPrimedBase + int32v( Primes::Y ), zPrimedBase + int32v( Primes::Z ) ), dx3, dy3, dz3 );
163133

164134
constexpr double kBounding = 32.69428253173828125;
@@ -167,7 +137,7 @@ class FastSIMD::DispatchClass<FastNoise::Simplex, SIMD> final : public virtual F
167137
-1 / kBounding, 1 / kBounding );
168138
}
169139

170-
float32v FS_VECTORCALL Gen_Standard( int32v seed, float32v x, float32v y, float32v z, float32v w ) const
140+
float32v FS_VECTORCALL Gen( int32v seed, float32v x, float32v y, float32v z, float32v w ) const
171141
{
172142
this->ScalePositions( x, y, z, w );
173143

@@ -309,7 +279,12 @@ class FastSIMD::DispatchClass<FastNoise::Simplex, SIMD> final : public virtual F
309279
-1 / kBounding, 1 / kBounding );
310280
}
311281

312-
float32v FS_VECTORCALL Gen_Smooth( int32v seed, float32v x, float32v y ) const
282+
};
283+
284+
template<FastSIMD::FeatureSet SIMD>
285+
class FastSIMD::DispatchClass<FastNoise::SimplexSmooth, SIMD> final : public virtual FastNoise::SimplexSmooth, public FastSIMD::DispatchClass<FastNoise::VariableRange<ScalableGenerator>, SIMD>
286+
{
287+
float32v FS_VECTORCALL Gen( int32v seed, float32v x, float32v y ) const
313288
{
314289
this->ScalePositions( x, y );
315290

@@ -394,7 +369,7 @@ class FastSIMD::DispatchClass<FastNoise::Simplex, SIMD> final : public virtual F
394369
return this->ScaleOutput( value, -1 / kBounding, 1 / kBounding );
395370
}
396371

397-
float32v FS_VECTORCALL Gen_Smooth( int32v seed, float32v x, float32v y, float32v z ) const
372+
float32v FS_VECTORCALL Gen( int32v seed, float32v x, float32v y, float32v z ) const
398373
{
399374
this->ScalePositions( x, y, z );
400375

@@ -545,7 +520,7 @@ class FastSIMD::DispatchClass<FastNoise::Simplex, SIMD> final : public virtual F
545520
float32v falloffBase = FS::Min( ( sign ^ dxBase ) - falloffBaseStemB, float32v( 0.0f ) );
546521
value = FS::FMulAdd( ( falloffBase * falloffBase ) * ( falloffBase * falloffBase ), gradientRampValue, value );
547522
}
548-
523+
549524
// Vertex <1, 0, 0> or <-1, 0, 0>
550525
{
551526
mask32v signMask = xNormal < float32v( 0 );
@@ -593,10 +568,10 @@ class FastSIMD::DispatchClass<FastNoise::Simplex, SIMD> final : public virtual F
593568
return this->ScaleOutput( value, -1 / kBounding, 1 / kBounding );
594569
}
595570

596-
float32v FS_VECTORCALL Gen_Smooth( int32v seed, float32v x, float32v y, float32v z, float32v w ) const
571+
float32v FS_VECTORCALL Gen( int32v seed, float32v x, float32v y, float32v z, float32v w ) const
597572
{
598573
this->ScalePositions( x, y, z, w );
599-
574+
600575
constexpr double kRoot5 = 2.2360679774997896964091736687313;
601576
constexpr double kSkew4 = 1.0 / ( kRoot5 + 1.0 );
602577
constexpr double kUnskew4 = -1.0 / ( kRoot5 + 5.0 );
@@ -658,7 +633,7 @@ class FastSIMD::DispatchClass<FastNoise::Simplex, SIMD> final : public virtual F
658633
maxScore -= wNormal;
659634
considerVertex( maxScore, moveMaskBits, yNormal, 0b1010 );
660635
considerVertex( maxScore, moveMaskBits, zNormal, 0b1100 );
661-
636+
662637
mask32v moveX = ( moveMaskBits & int32v( 0b0001 ) ) != int32v( 0 );
663638
mask32v moveY = ( moveMaskBits & int32v( 0b0010 ) ) != int32v( 0 );
664639
mask32v moveZ = ( moveMaskBits & int32v( 0b0100 ) ) != int32v( 0 );
@@ -679,7 +654,7 @@ class FastSIMD::DispatchClass<FastNoise::Simplex, SIMD> final : public virtual F
679654
int32v yPrimedBase = FS::Convert<int32_t>( ySkewedBase ) * int32v( Primes::Y );
680655
int32v zPrimedBase = FS::Convert<int32_t>( zSkewedBase ) * int32v( Primes::Z );
681656
int32v wPrimedBase = FS::Convert<int32_t>( wSkewedBase ) * int32v( Primes::W );
682-
657+
683658
float32v skewedCoordinateSum = dxSkewed + dySkewed + dzSkewed + dwSkewed;
684659
float32v twiceUnskewDelta = float32v( kTwiceUnskew4 ) * skewedCoordinateSum;
685660
float32v xNormal = dxSkewed + twiceUnskewDelta;

src/FastNoise/FastSIMD_Build.inl

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ FASTNOISE_REGISTER_NODE( PositionOutput );
9191
FASTNOISE_REGISTER_NODE( DistanceToPoint );
9292

9393
FASTNOISE_REGISTER_NODE( Simplex );
94+
FASTNOISE_REGISTER_NODE( SimplexSmooth );
9495
FASTNOISE_REGISTER_NODE( Perlin );
9596
FASTNOISE_REGISTER_NODE( Value );
9697

@@ -103,6 +104,7 @@ FASTNOISE_REGISTER_NODE( FractalPingPong );
103104
FASTNOISE_REGISTER_NODE( FractalRidged );
104105

105106
FASTNOISE_REGISTER_NODE( DomainWarpSimplex );
107+
//FASTNOISE_REGISTER_NODE( DomainWarpSimplexSmooth );
106108
FASTNOISE_REGISTER_NODE( DomainWarpGradient );
107109

108110
FASTNOISE_REGISTER_NODE( DomainWarpFractalProgressive );

tools/NodeEditor/FastNoiseNodeEditor.cpp

+19-8
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ void FastNoiseNodeEditor::Node::GeneratePreview( bool nodeTreeChanged, bool benc
199199
genRGB->SetSource( scale );
200200
scale->SetSource( generator );
201201
scale->SetScaling( editor.mNodeScale );
202-
203-
FastNoise::SmartNode<FastNoise::ConvertRGBA8> l(nullptr);
204202

205203
auto startTime = std::chrono::high_resolution_clock::now();
206204

@@ -335,7 +333,7 @@ bool FastNoiseNodeEditor::MetadataMenuItem::CanDraw( std::function<bool( const F
335333

336334
const FastNoise::Metadata* FastNoiseNodeEditor::MetadataMenuItem::DrawUI( std::function<bool( const FastNoise::Metadata* )> isValid, bool drawGroups ) const
337335
{
338-
std::string format = FastNoise::Metadata::FormatMetadataNodeName( metadata, true );
336+
std::string format = FastNoise::Metadata::FormatMetadataNodeName( metadata, drawGroups );
339337

340338
if( ImGui::MenuItem( format.c_str() ) )
341339
{
@@ -589,6 +587,7 @@ void FastNoiseNodeEditor::SetupSettingsHandlers()
589587

590588
FastNoiseNodeEditor::FastNoiseNodeEditor( NodeEditorApp& nodeEditorApp ) :
591589
mNodeEditorApp( nodeEditorApp ),
590+
mMainContext( ImGui::GetCurrentContext() ),
592591
mOverheadNode( *this, new FastNoise::NodeData( &FastNoise::Metadata::Get<FastNoise::Constant>() ), false )
593592
{
594593
if( !mNodeEditorApp.IsDetachedNodeGraph() )
@@ -830,9 +829,10 @@ void FastNoiseNodeEditor::Draw( const Matrix4& transformation, const Matrix4& pr
830829
OpenStandaloneNodeGraph();
831830
}
832831

832+
ImGui::SetCurrentContext( mMainContext );
833833
DoHelp();
834-
835834
DoContextMenu();
835+
ImGui::SetCurrentContext( ImNodes::GetNodeEditorImGuiContext() );
836836

837837
DoNodes();
838838

@@ -1048,10 +1048,19 @@ void FastNoiseNodeEditor::DoNodes()
10481048
}
10491049

10501050
ImNodes::EndNodeTitleBar();
1051+
ImGuiID popupId = ImGui::GetItemID();
1052+
1053+
if( ImGui::IsMouseReleased( ImGuiMouseButton_Right ) && ImGui::IsItemHovered( ImGuiHoveredFlags_AllowWhenBlockedByPopup ) )
1054+
{
1055+
ImGui::SetCurrentContext( mMainContext );
1056+
ImGui::OpenPopup( popupId );
1057+
}
10511058

1059+
ImGui::SetCurrentContext( mMainContext );
10521060
// Right click node title to change node type
10531061
ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 4, 4 ) );
1054-
if( ImGui::BeginPopupContextItem() )
1062+
1063+
if( ImGui::BeginPopupEx( popupId, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings ) )
10551064
{
10561065
if( ImGui::MenuItem( "Copy Encoded Node Tree" ) )
10571066
{
@@ -1074,7 +1083,7 @@ void FastNoiseNodeEditor::DoNodes()
10741083
MatchingMembers( newMetadata->memberNodeLookups, nodeMetadata->memberNodeLookups ) &&
10751084
MatchingMembers( newMetadata->memberHybrids, nodeMetadata->memberHybrids ) )
10761085
{
1077-
nodeMetadata = newMetadata;
1086+
nodeMetadata = newMetadata;
10781087
}
10791088
else
10801089
{
@@ -1104,7 +1113,7 @@ void FastNoiseNodeEditor::DoNodes()
11041113
links.pop();
11051114
}
11061115

1107-
*node.second.data = std::move( newData );
1116+
*node.second.data = std::move( newData );
11081117
}
11091118

11101119
node.second.GeneratePreview();
@@ -1114,6 +1123,8 @@ void FastNoiseNodeEditor::DoNodes()
11141123
}
11151124
ImGui::PopStyleVar();
11161125

1126+
ImGui::SetCurrentContext( ImNodes::GetNodeEditorImGuiContext() );
1127+
11171128
ImGui::PushItemWidth( 90.0f );
11181129

11191130
ImNodes::PushAttributeFlag( ImNodesAttributeFlags_EnableLinkCreationOnSnap );
@@ -1286,7 +1297,7 @@ void FastNoiseNodeEditor::DoHelp()
12861297
ImGui::Text( " Help" );
12871298
if( ImGui::IsItemHovered() )
12881299
{
1289-
ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 4.f, 4.f ) );
1300+
ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 6.f, 6.f ) );
12901301
ImGui::BeginTooltip();
12911302
constexpr float alignPx = 110;
12921303

tools/NodeEditor/FastNoiseNodeEditor.h

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ namespace Magnum
126126
void UpdateSelected();
127127

128128
NodeEditorApp& mNodeEditorApp;
129+
ImGuiContext* mMainContext;
129130

130131
std::unordered_map<FastNoise::NodeData*, Node> mNodes;
131132
FastNoise::NodeData* mDroppedLinkNode = nullptr;

0 commit comments

Comments
 (0)