Skip to content

Commit

Permalink
- add ability to get the value of the distance2 point (#9)
Browse files Browse the repository at this point in the history
- change api to use char * instead of std::string
- little clean up
- turn perturb on
  • Loading branch information
caseymcc authored Sep 1, 2019
1 parent 2bc4f03 commit 91fcf49
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 178 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ set(hastyNoise_inline
HastyNoise/simd_init.inl
)

#project expects debug libs to have d at the end
if("${CMAKE_DEBUG_POSTFIX}" STREQUAL "")
set(CMAKE_DEBUG_POSTFIX "d")
endif()

add_library(hastyNoise SHARED
${hastyNoise_sources}
${hastyNoise_headers}
Expand Down
9 changes: 3 additions & 6 deletions HastyNoise/hastyNoise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,10 @@ int phdr_callback(struct dl_phdr_info *info, size_t size, void *data)
}
#endif

bool loadSimd(std::string libPath)
bool loadSimd(const char *path)
{
//#if HN_USE_FILESYSTEM == 0
// assert(false);
// return false;
//#else
std::string libPath(path);

if(libPath.empty())
{//find where we are loaded from and look in that directory
libPath="./";
Expand Down Expand Up @@ -469,7 +467,6 @@ bool loadSimd(std::string libPath)
}

return true;
//#endif
}

void FillVectorSet(VectorSet* vectorSet, int xSize, int ySize, int zSize)
Expand Down
4 changes: 2 additions & 2 deletions HastyNoise/hastyNoise.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ struct HASTYNOISE_EXPORT NoiseFuncs


// Loads all available simd libraries from directory
HASTYNOISE_EXPORT bool loadSimd(std::string directory="");
HASTYNOISE_EXPORT bool loadSimd(const char *path="");


namespace details
Expand Down Expand Up @@ -478,7 +478,7 @@ class HASTYNOISE_EXPORT NoiseSIMD

// // Enables position perturbing for all noise types
// // Default: None
// void SetPerturbType(PerturbType perturbType) { m_perturbType = perturbType; }
void SetPerturbType(PerturbType perturbType) { m_perturbType = perturbType; }

// Sets the maximum distance the input position can be perturbed
// Default: 1.0
Expand Down
2 changes: 1 addition & 1 deletion HastyNoise/hastyNoise_avx512.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ template class HASTYNOISE_EXPORT NoiseSIMD<SIMDType::AVX512>;
//template struct Constants<typename SIMD<SIMDType::AVX512>::Float, typename SIMD<SIMDType::AVX512>::Int, SIMDType::AVX512>;

}//namespace details
}//namespace FastNoiseSIMD
}//namespace HastyNoise

3 changes: 2 additions & 1 deletion HastyNoise/hastyNoise_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,14 @@ template<> HASTY_INLINE_VAR std::vector<NameTypeKey<CellularDistance>> EnumKeys<
{"Natural", HastyNoise::CellularDistance::Natural}
};

enum class CellularReturnType { None, Value, Distance, Distance2, Distance2Add, Distance2Sub, Distance2Mul, Distance2Div, NoiseLookup, Distance2Cave };
enum class CellularReturnType { None, Value, Distance, Distance2, ValueDistance2, Distance2Add, Distance2Sub, Distance2Mul, Distance2Div, NoiseLookup, Distance2Cave };
template<> HASTY_INLINE_VAR std::vector<NameTypeKey<CellularReturnType>> EnumKeys<CellularReturnType>::keys=
{
{"None", HastyNoise::CellularReturnType::None},
{"Value", HastyNoise::CellularReturnType::Value},
{"Distance", HastyNoise::CellularReturnType::Distance},
{"Distance2", HastyNoise::CellularReturnType::Distance2},
{"ValueDistance2", HastyNoise::CellularReturnType::ValueDistance2},
{"Distance2Add", HastyNoise::CellularReturnType::Distance2Add},
{"Distance2Sub", HastyNoise::CellularReturnType::Distance2Sub},
{"Distance2Mul", HastyNoise::CellularReturnType::Distance2Mul},
Expand Down
297 changes: 133 additions & 164 deletions HastyNoise/hastyNoise_internal.inl

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion HastyNoise/internal_avx2.inl
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ struct SIMD<SIMDType::AVX2>
};

}//namespace details
}//namespace FastNoise
}//namespace HastyNoise
2 changes: 1 addition & 1 deletion HastyNoise/internal_avx512.inl
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,4 @@ struct SIMD<SIMDType::AVX512>
};

}//namespace details
}//namespace FastNoise
}//namespace HastyNoise
2 changes: 1 addition & 1 deletion HastyNoise/internal_sse2.inl
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ struct SIMD<SIMDType::SSE2>
#endif

}//namespace details
}//namespace FastNoise
}//namespace HastyNoise
2 changes: 1 addition & 1 deletion HastyNoise/internal_sse41.inl
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ struct SIMD<SIMDType::SSE4_1>:SIMD<SIMDType::SSE2>
#endif

}//namespace details
}//namespace FastNoise
}//namespace HastyNoise
37 changes: 37 additions & 0 deletions preview/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,18 @@ int main(int argc, char ** argv)
std::vector<std::string> cellularReturnTypes;
std::vector<char> cellularReturnTypesPacked=getTypeNamesPacked<HastyNoise::CellularReturnType>(cellularReturnTypes);

HastyNoise::PerturbType currentPerturbType=HastyNoise::PerturbType::None;
std::vector<std::string> perturbTypes;
std::vector<char> perturbTypesPacked=getTypeNamesPacked<HastyNoise::PerturbType>(perturbTypes);

float noisePerturbAmp=1.0f;
float noisePerturbFrequency=0.5f;
int noisePerturbOctaves=3;
float noisePerturbLacunarity=2.0f;
float noisePerturbGain=0.5f;
float noisePerturbNormaliseLength=1.0f;


bool noiseTextureDirty=false;
bool noiseTextureValid=false;

Expand Down Expand Up @@ -325,6 +337,17 @@ int main(int argc, char ** argv)
noiseBufferDirty=false;
}

noise->SetPerturbType(currentPerturbType);
if(currentPerturbType!=HastyNoise::PerturbType::None)
{
noise->SetPerturbAmp(noisePerturbAmp);
noise->SetPerturbFrequency(noisePerturbFrequency);
noise->SetPerturbFractalOctaves(noisePerturbOctaves);
noise->SetPerturbFractalLacunarity(noisePerturbLacunarity);
noise->SetPerturbFractalGain(noisePerturbGain);
noise->SetPerturbNormaliseLength(noisePerturbNormaliseLength);
}

chrono::high_resolution_clock::time_point startTime;
chrono::high_resolution_clock::time_point endTime;

Expand Down Expand Up @@ -419,6 +442,20 @@ int main(int argc, char ** argv)
ImGui::PopStyleVar();
}

ImGui::Text("");
ImGui::Text("Perturb Settings");

int perturbIndex=getIndexFromType(perturbTypes, currentPerturbType);
if(ImGui::Combo("Perturb Type", &perturbIndex, &perturbTypesPacked[0]))
currentPerturbType=getTypeFromIndex<HastyNoise::PerturbType>(perturbTypes, perturbIndex);

ImGui::SliderFloat("Perturb Amp", &noisePerturbAmp, 0.01f, 2.0f, "%.3f");
ImGui::SliderFloat("Perturb Frequency", &noisePerturbFrequency, 0.01f, 1.0f, "%.3f");
ImGui::SliderInt("Perturb Octaves", &noisePerturbOctaves, 1, 15);
ImGui::SliderFloat("Perturb Lacunarity", &noisePerturbLacunarity, 0.01f, 2.0f, "%.3f");
ImGui::SliderFloat("Perturb Gain", &noisePerturbGain, 0.01f, 10.0f, "%.3f");
ImGui::SliderFloat("Perturb Normalise Length", &noisePerturbNormaliseLength, 0.01f, 10.0f, "%.3f");

ImGui::End();

int imageWidth=g_windowInfo.width-350-20;
Expand Down

0 comments on commit 91fcf49

Please sign in to comment.