// Copyright 2020 Phyronnaz #if 0 #include "VoxelGeneratorExample.h" #include "FastNoise/VoxelFastNoise.inl" #include "VoxelMaterialBuilder.h" TVoxelSharedRef UVoxelGeneratorExample::GetInstance() { return MakeVoxelShared(*this); } /////////////////////////////////////////////////////////////////////////////// FVoxelGeneratorExampleInstance::FVoxelGeneratorExampleInstance(const UVoxelGeneratorExample& MyGenerator) : Super(&MyGenerator) , NoiseHeight(MyGenerator.NoiseHeight) , Seed(MyGenerator.Seed) { } void FVoxelGeneratorExampleInstance::Init(const FVoxelGeneratorInit& InitStruct) { Noise.SetSeed(Seed); } v_flt FVoxelGeneratorExampleInstance::GetValueImpl(v_flt X, v_flt Y, v_flt Z, int32 LOD, const FVoxelItemStack& Items) const { const float Height = Noise.GetPerlin_2D(X, Y, 0.01f) * NoiseHeight; // Positive value -> empty voxel // Negative value -> full voxel // Value positive when Z > Height, and negative Z < Height float Value = Z - Height; // The voxel value is clamped between -1 and 1. That can result in a bad gradient/normal. To solve that we divide it Value /= 5; return Value; } FVoxelMaterial FVoxelGeneratorExampleInstance::GetMaterialImpl(v_flt X, v_flt Y, v_flt Z, int32 LOD, const FVoxelItemStack& Items) const { FVoxelMaterialBuilder Builder; // RGB Builder.SetMaterialConfig(EVoxelMaterialConfig::RGB); Builder.SetColor(FColor::Red); // Single index //Builder.SetMaterialConfig(EVoxelMaterialConfig::SingleIndex); //Builder.SetSingleIndex(0); // Multi index //Builder.SetMaterialConfig(EVoxelMaterialConfig::MultiIndex); //Builder.AddMultiIndex(0, 0.5f); //Builder.AddMultiIndex(1, 0.5f); return Builder.Build(); } TVoxelRange FVoxelGeneratorExampleInstance::GetValueRangeImpl(const FVoxelIntBox& Bounds, int32 LOD, const FVoxelItemStack& Items) const { // Return the values that GetValueImpl can return in Bounds // Used to skip chunks where the value does not change // Be careful, if wrong your world will have holes! // By default return infinite range to be safe return TVoxelRange::Infinite(); // Example for the GetValueImpl above // Noise is between -1 and 1 const TVoxelRange Height = TVoxelRange(-1, 1) * NoiseHeight; // Z can go from min to max TVoxelRange Value = TVoxelRange(Bounds.Min.Z, Bounds.Max.Z) - Height; Value /= 5; return Value; } FVector FVoxelGeneratorExampleInstance::GetUpVector(v_flt X, v_flt Y, v_flt Z) const { // Used by spawners return FVector::UpVector; } #endif