Skip to content

Commit

Permalink
Description/documentation for nodes and members
Browse files Browse the repository at this point in the history
  • Loading branch information
Auburn committed Oct 28, 2022
1 parent 23aaf21 commit 2a42268
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 47 deletions.
61 changes: 52 additions & 9 deletions NoiseTool/FastNoiseNodeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

using namespace Magnum;

bool MatchingGroup( const std::vector<const char*>& a, const std::vector<const char*>& b )
static bool MatchingGroup( const std::vector<const char*>& a, const std::vector<const char*>& b )
{
std::string aString;
for( const char* c : a )
Expand All @@ -39,7 +39,7 @@ bool MatchingGroup( const std::vector<const char*>& a, const std::vector<const c
}

template<typename T>
bool MatchingMembers( const std::vector<T>& a, const std::vector<T>& b )
static bool MatchingMembers( const std::vector<T>& a, const std::vector<T>& b )
{
if( a.size() != b.size() )
{
Expand All @@ -56,6 +56,42 @@ bool MatchingMembers( const std::vector<T>& a, const std::vector<T>& b )
return true;
}

static std::string TimeWithUnits( int64_t time, int significantDigits = 3 )
{
if( time == 0 )
{
return "0us";
}

double f = time / 1e+3;

int d = (int)::ceil(::log10(::abs( f ))); /*digits before decimal point*/
std::stringstream ss;
ss.precision( std::max(significantDigits - d, 0) );
ss << std::fixed << f << "us";
return ss.str();
}

template<typename... T>
static bool DoHoverPopup( const char* format, T... args )
{
if( !*format )
{
return false;
}

if( ImGui::IsItemHovered() )
{
ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 4.f, 4.f ) );
ImGui::BeginTooltip();
ImGui::Text( format, args... );
ImGui::EndTooltip();
ImGui::PopStyleVar();
return true;
}
return false;
}

FastNoiseNodeEditor::Node::Node( FastNoiseNodeEditor& e, FastNoise::NodeData* nodeData, bool generatePreview, int id ) :
Node( e, std::unique_ptr<FastNoise::NodeData>( nodeData ), generatePreview, id )
{ }
Expand Down Expand Up @@ -160,11 +196,11 @@ std::vector<FastNoise::NodeData*> FastNoiseNodeEditor::Node::GetNodeIDLinks()
return links;
}

uint64_t FastNoiseNodeEditor::Node::GetLocalGenerateNs()
int64_t FastNoiseNodeEditor::Node::GetLocalGenerateNs()
{
int64_t localTotal = totalGenerateNs;

for( FastNoise::NodeData* link: GetNodeIDLinks() )
for( FastNoise::NodeData* link : GetNodeIDLinks() )
{
auto find = editor.mNodes.find( link );

Expand Down Expand Up @@ -775,10 +811,12 @@ void FastNoiseNodeEditor::DoNodes()
std::string formatName = FastNoise::Metadata::FormatMetadataNodeName( node.second.data->metadata );
ImGui::TextUnformatted( formatName.c_str() );

std::stringstream performanceStream;
performanceStream.precision( 3 );
performanceStream << node.second.GetLocalGenerateNs() / 1e+3f << "us";
std::string performanceString = performanceStream.str();
#ifdef NDEBUG
DoHoverPopup( "%s", node.first->metadata->description );
#else
DoHoverPopup( "%s : %d\n%s", node.first->metadata->name, node.first->metadata->id, node.first->metadata->description );
#endif
std::string performanceString = TimeWithUnits( node.second.GetLocalGenerateNs() );

ImGui::SameLine( Node::NoiseSize - ImGui::CalcTextSize( performanceString.c_str() ).x );
ImGui::TextUnformatted( performanceString.c_str() );
Expand All @@ -787,7 +825,8 @@ void FastNoiseNodeEditor::DoNodes()
{
ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 4.f, 4.f ) );
ImGui::BeginTooltip();
ImGui::Text( "Total: %.3gus", node.second.totalGenerateNs / 1e+3f );

ImGui::Text( "Total: %s", TimeWithUnits( node.second.totalGenerateNs ).c_str() );
ImGui::EndTooltip();
ImGui::PopStyleVar();
}
Expand Down Expand Up @@ -873,6 +912,8 @@ void FastNoiseNodeEditor::DoNodes()
formatName = FastNoise::Metadata::FormatMetadataMemberName( memberNode );
ImGui::TextUnformatted( formatName.c_str() );
ImNodes::EndInputAttribute();

DoHoverPopup( memberNode.description );
}

for( size_t i = 0; i < node.second.data->metadata->memberHybrids.size(); i++ )
Expand Down Expand Up @@ -900,6 +941,7 @@ void FastNoiseNodeEditor::DoNodes()
ImGui::PopItemFlag();
}
ImNodes::EndInputAttribute();
DoHoverPopup( nodeMetadata->memberHybrids[i].description );
}

for( size_t i = 0; i < nodeMetadata->memberVariables.size(); i++ )
Expand Down Expand Up @@ -940,6 +982,7 @@ void FastNoiseNodeEditor::DoNodes()
}

ImNodes::EndStaticAttribute();
DoHoverPopup( nodeMetadata->memberVariables[i].description );
}

ImGui::PopItemWidth();
Expand Down
2 changes: 1 addition & 1 deletion NoiseTool/FastNoiseNodeEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Magnum
Node( FastNoiseNodeEditor& editor, std::unique_ptr<FastNoise::NodeData>&& nodeData, bool generatePreview = true, int id = 0 );
void GeneratePreview( bool nodeTreeChanged = true, bool benchmark = false );
std::vector<FastNoise::NodeData*> GetNodeIDLinks();
uint64_t GetLocalGenerateNs();
int64_t GetLocalGenerateNs();
FastNoise::NodeData*& GetNodeLink( int attributeId );
void AutoPositionChildNodes( ImVec2 nodePos, float verticalSpacing = 380.0f );
void SerialiseIncludingDependancies( struct ImGuiSettingsHandler* handler, struct ImGuiTextBuffer* buffer, std::unordered_set<int>& serialisedNodeIds );
Expand Down
18 changes: 9 additions & 9 deletions NoiseTool/MeshNoisePreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,15 @@ void MeshNoisePreview::Chunk::AddQuadAO( std::vector<VertexData>& verts, std::ve
{
int32_t facingIdx = idx + facingOffset;

int32_t sideA0 = density[facingIdx - offsetA] <= isoSurface;
int32_t sideA1 = density[facingIdx + offsetA] <= isoSurface;
int32_t sideB0 = density[facingIdx - offsetB] <= isoSurface;
int32_t sideB1 = density[facingIdx + offsetB] <= isoSurface;

int32_t corner00 = (sideA0 & sideB0) || density[facingIdx - offsetA - offsetB] <= isoSurface;
int32_t corner01 = (sideA0 & sideB1) || density[facingIdx - offsetA + offsetB] <= isoSurface;
int32_t corner10 = (sideA1 & sideB0) || density[facingIdx + offsetA - offsetB] <= isoSurface;
int32_t corner11 = (sideA1 & sideB1) || density[facingIdx + offsetA + offsetB] <= isoSurface;
uint8_t sideA0 = density[facingIdx - offsetA] <= isoSurface;
uint8_t sideA1 = density[facingIdx + offsetA] <= isoSurface;
uint8_t sideB0 = density[facingIdx - offsetB] <= isoSurface;
uint8_t sideB1 = density[facingIdx + offsetB] <= isoSurface;
uint8_t corner00 = (sideA0 & sideB0) || density[facingIdx - offsetA - offsetB] <= isoSurface;
uint8_t corner01 = (sideA0 & sideB1) || density[facingIdx - offsetA + offsetB] <= isoSurface;
uint8_t corner10 = (sideA1 & sideB0) || density[facingIdx + offsetA - offsetB] <= isoSurface;
uint8_t corner11 = (sideA1 & sideB1) || density[facingIdx + offsetA + offsetB] <= isoSurface;

constexpr float aoAdjust = AO_STRENGTH / 3.0f;

Expand Down
31 changes: 23 additions & 8 deletions include/FastNoise/Generators/Cellular.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ namespace FastNoise
MetadataT()
{
groups.push_back( "Coherent Noise" );
this->AddHybridSource( "Jitter Modifier", 1.0f, &Cellular::SetJitterModifier, &Cellular::SetJitterModifier );
this->AddVariableEnum( "Distance Function", DistanceFunction::EuclideanSquared, &Cellular::SetDistanceFunction, kDistanceFunction_Strings );
this->AddHybridSource( { "Jitter Modifier", "Above 1.0 will cause grid artifacts" }, 1.0f, &Cellular::SetJitterModifier, &Cellular::SetJitterModifier );
this->AddVariableEnum( { "Distance Function", "How distance to closest cells is calculated\nHybrid is EuclideanSquared + Manhattan" },
DistanceFunction::EuclideanSquared, &Cellular::SetDistanceFunction, kDistanceFunction_Strings );
}
};
#endif
Expand All @@ -52,7 +53,12 @@ namespace FastNoise

MetadataT()
{
this->AddVariable( "Value Index", 0, &CellularValue::SetValueIndex, 0, CellularValue::kMaxDistanceCount - 1 );
this->AddVariable( { "Value Index", "Nth closest cell" }, 0, &CellularValue::SetValueIndex, 0, CellularValue::kMaxDistanceCount - 1 );

description =
"Returns value of Nth closest cell\n"
"Value is generated using white noise\n"
"Output is bounded -1 : 1";
}
};
#endif
Expand Down Expand Up @@ -92,9 +98,14 @@ namespace FastNoise

MetadataT()
{
this->AddVariable( "Distance Index 0", 0, &CellularDistance::SetDistanceIndex0, 0, CellularDistance::kMaxDistanceCount - 1 );
this->AddVariable( "Distance Index 1", 1, &CellularDistance::SetDistanceIndex1, 0, CellularDistance::kMaxDistanceCount - 1 );
this->AddVariableEnum( "Return Type", CellularDistance::ReturnType::Index0, &CellularDistance::SetReturnType, "Index0", "Index0Add1", "Index0Sub1", "Index0Mul1", "Index0Div1" );
this->AddVariable( { "Distance Index 0", "Nth closest cell" }, 0, &CellularDistance::SetDistanceIndex0, 0, CellularDistance::kMaxDistanceCount - 1 );
this->AddVariable( { "Distance Index 1", "Nth closest cell" }, 1, &CellularDistance::SetDistanceIndex1, 0, CellularDistance::kMaxDistanceCount - 1 );
this->AddVariableEnum( { "Return Type", "How to combine Index 0 & Index 1" }, CellularDistance::ReturnType::Index0, &CellularDistance::SetReturnType, "Index0", "Index0Add1", "Index0Sub1", "Index0Mul1", "Index0Div1" );

description =
"Returns distance of Nth closest cell\n"
"Distance of Index0 and Index1 are combined according to return type\n"
"Returned value is always positive except when using Index0Sub1 and Index0 > Index1";
}
};
#endif
Expand All @@ -121,8 +132,12 @@ namespace FastNoise

MetadataT()
{
this->AddGeneratorSource( "Lookup", &CellularLookup::SetLookup );
this->AddVariable( "Lookup Frequency", 0.1f, &CellularLookup::SetLookupFrequency );
this->AddGeneratorSource( { "Lookup", "Used to generate cell values" }, &CellularLookup::SetLookup );
this->AddVariable( { "Lookup Frequency", "Relative to the cellular frequency" }, 0.1f, &CellularLookup::SetLookupFrequency );

description =
"Returns value of closest cell\n"
"Value is generated at the cell center using the lookup source";
}
};
#endif
Expand Down
45 changes: 27 additions & 18 deletions include/FastNoise/Generators/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,11 @@ namespace FastNoise
{
protected:
template<typename T, typename U, typename = std::enable_if_t<!std::is_enum_v<T>>>
void AddVariable( const char* name, T defaultV, U&& func, T minV = 0, T maxV = 0 )
void AddVariable( NameDesc nameDesc, T defaultV, U&& func, T minV = 0, T maxV = 0 )
{
MemberVariable member;
member.name = name;
member.name = nameDesc.name;
member.description = nameDesc.desc;
member.valueDefault = defaultV;
member.valueMin = minV;
member.valueMax = maxV;
Expand All @@ -208,10 +209,11 @@ namespace FastNoise
}

template<typename T, typename U, typename = std::enable_if_t<!std::is_enum_v<T>>>
void AddVariable( const char* name, T defaultV, void(U::* func)(T), T minV = 0, T maxV = 0 )
void AddVariable( NameDesc nameDesc, T defaultV, void(U::* func)(T), T minV = 0, T maxV = 0 )
{
MemberVariable member;
member.name = name;
member.name = nameDesc.name;
member.description = nameDesc.desc;
member.valueDefault = defaultV;
member.valueMin = minV;
member.valueMax = maxV;
Expand All @@ -232,10 +234,11 @@ namespace FastNoise
}

template<typename T, typename U, typename = std::enable_if_t<std::is_enum_v<T>>, typename... ENUM_NAMES>
void AddVariableEnum( const char* name, T defaultV, void(U::* func)(T), ENUM_NAMES... enumNames )
void AddVariableEnum( NameDesc nameDesc, T defaultV, void(U::* func)(T), ENUM_NAMES... enumNames )
{
MemberVariable member;
member.name = name;
member.name = nameDesc.name;
member.description = nameDesc.desc;
member.type = MemberVariable::EEnum;
member.valueDefault = (int)defaultV;
member.enumNames = { enumNames... };
Expand All @@ -254,10 +257,11 @@ namespace FastNoise
}

template<typename T, typename U, size_t ENUM_NAMES, typename = std::enable_if_t<std::is_enum_v<T>>>
void AddVariableEnum( const char* name, T defaultV, void(U::* func)(T), const char* const (&enumNames)[ENUM_NAMES] )
void AddVariableEnum( NameDesc nameDesc, T defaultV, void(U::* func)(T), const char* const (&enumNames)[ENUM_NAMES] )
{
MemberVariable member;
member.name = name;
member.name = nameDesc.name;
member.description = nameDesc.desc;
member.type = MemberVariable::EEnum;
member.valueDefault = (int)defaultV;
member.enumNames = { enumNames, enumNames + ENUM_NAMES };
Expand All @@ -276,12 +280,13 @@ namespace FastNoise
}

template<typename T, typename U, typename = std::enable_if_t<!std::is_enum_v<T>>>
void AddPerDimensionVariable( const char* name, T defaultV, U&& func, T minV = 0, T maxV = 0 )
void AddPerDimensionVariable( NameDesc nameDesc, T defaultV, U&& func, T minV = 0, T maxV = 0 )
{
for( int idx = 0; (size_t)idx < sizeof( PerDimensionVariable<T>::varArray ) / sizeof( *PerDimensionVariable<T>::varArray ); idx++ )
{
MemberVariable member;
member.name = name;
member.name = nameDesc.name;
member.description = nameDesc.desc;
member.valueDefault = defaultV;
member.valueMin = minV;
member.valueMax = maxV;
Expand All @@ -304,10 +309,11 @@ namespace FastNoise
}

template<typename T, typename U>
void AddGeneratorSource( const char* name, void(U::* func)(SmartNodeArg<T>) )
void AddGeneratorSource( NameDesc nameDesc, void(U::* func)(SmartNodeArg<T>) )
{
MemberNodeLookup member;
member.name = name;
member.name = nameDesc.name;
member.description = nameDesc.desc;

member.setFunc = [func]( Generator* g, SmartNodeArg<> s )
{
Expand All @@ -327,15 +333,16 @@ namespace FastNoise
}

template<typename U>
void AddPerDimensionGeneratorSource( const char* name, U&& func )
void AddPerDimensionGeneratorSource( NameDesc nameDesc, U&& func )
{
using GeneratorSourceT = typename std::invoke_result_t<U, GetArg<U, 0>>::type::Type;
using T = typename GeneratorSourceT::Type;

for( int idx = 0; (size_t)idx < sizeof( PerDimensionVariable<GeneratorSourceT>::varArray ) / sizeof( *PerDimensionVariable<GeneratorSourceT>::varArray ); idx++ )
{
MemberNodeLookup member;
member.name = name;
member.name = nameDesc.name;
member.description = nameDesc.desc;
member.dimensionIdx = idx;

member.setFunc = [func, idx]( Generator* g, SmartNodeArg<> s )
Expand All @@ -358,10 +365,11 @@ namespace FastNoise


template<typename T, typename U>
void AddHybridSource( const char* name, float defaultValue, void(U::* funcNode)(SmartNodeArg<T>), void(U::* funcValue)(float) )
void AddHybridSource( NameDesc nameDesc, float defaultValue, void(U::* funcNode)(SmartNodeArg<T>), void(U::* funcValue)(float) )
{
MemberHybrid member;
member.name = name;
member.name = nameDesc.name;
member.description = nameDesc.desc;
member.valueDefault = defaultValue;

member.setNodeFunc = [funcNode]( Generator* g, SmartNodeArg<> s )
Expand Down Expand Up @@ -392,15 +400,16 @@ namespace FastNoise
}

template<typename U>
void AddPerDimensionHybridSource( const char* name, float defaultV, U&& func )
void AddPerDimensionHybridSource( NameDesc nameDesc, float defaultV, U&& func )
{
using HybridSourceT = typename std::invoke_result_t<U, GetArg<U, 0>>::type::Type;
using T = typename HybridSourceT::Type;

for( int idx = 0; (size_t)idx < sizeof( PerDimensionVariable<HybridSourceT>::varArray ) / sizeof( *PerDimensionVariable<HybridSourceT>::varArray ); idx++ )
{
MemberHybrid member;
member.name = name;
member.name = nameDesc.name;
member.description = nameDesc.desc;
member.valueDefault = defaultV;
member.dimensionIdx = idx;

Expand Down
4 changes: 4 additions & 0 deletions include/FastNoise/Generators/Perlin.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ namespace FastNoise
MetadataT()
{
groups.push_back( "Coherent Noise" );

description =
"Smooth gradient noise from N dimensional grid\n"
"Developed by Ken Perlin in 1983";
}
};
#endif
Expand Down
8 changes: 8 additions & 0 deletions include/FastNoise/Generators/Simplex.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ namespace FastNoise
MetadataT()
{
groups.push_back( "Coherent Noise" );

description =
"Smooth gradient noise from N dimensional simplex grid\n"
"Developed by Ken Perlin in 2001";
}
};
#endif
Expand All @@ -39,6 +43,10 @@ namespace FastNoise
MetadataT()
{
groups.push_back( "Coherent Noise" );

description =
"Smooth gradient noise from N dimensional simplex honeycomb grid\n"
"Developed by K.jpg in 2014";
}
};
#endif
Expand Down
Loading

0 comments on commit 2a42268

Please sign in to comment.