World Generators

World generators are a central part of voxel plugin. You have 2 ways to create them:

Included World Generators

The plugin includes several world generators that can be used in the free version. If you are not familiar with C++, it is highly recommended to use these instead of writing your own generator!

How to use example generators

You can find example maps with the different generators under Examples/Maps/ (check Examples for more info).

The corresponding generators are under Examples/VoxelGraphs.

For example, open Examples/Maps/VoxelExample_Planet_Map.

You should see something like:

Under the generator, you can change its properties like radius, noise strength...

List of included generators

Cave

Large underground cave under some mountains

Cliffs

IQ Noise

Simple IQ noise map

Planet

Small planet example

Ravines

Map with simple 3D noise ravines, could make a fun map for a multiplayer shooter

Ring World

Classic ring world

Creating a new C++ World Generator

Creating the class files

  • Click Add New/New C++ Class

  • Choose None

  • Name it MyWorldGenerator, and click Public

  • Click Create Class. Visual Studio should open. If not, please refer to the UE4 documentation on creating a C++ class

Implementing the class

You should now have 2 files: MyWorldGenerator.h and MyWorldGenerator.cpp.

In Source/YourProject/YourProject.Build.cs, add the "Voxel" dependency to PublicDependencyModuleNames:

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Voxel" });

Now, replace the content of MyWorldGenerator.h/.cpp by the code at

https://github.com/Phyronnaz/VoxelPlugin/blob/master/Source/VoxelExamples/Public/VoxelGeneratorExample.h and

https://github.com/Phyronnaz/VoxelPlugin/blob/master/Source/VoxelExamples/Private/VoxelGeneratorExample.cpp

For both, make sure to remove the #if 0 and the #endif. They are here to avoid naming collisions when you reuse that example.

Using your World Generator

  • Set your voxel world World Generator to Class and choose MyWorldGenerator

  • You can also add MySeed to the Seeds map of the voxel world

  • Set your voxel world Material Config to RGB

  • Hit play: you should see a world with hills.

To have bigger hills, create a blueprint inheriting from MyWorldGenerator:

  • Right click content browser, new blueprint class

  • Expand All Classes and choose MyWorldGenerator

  • Open the new blueprint, and in Class Defaults change Noise Height to 100

  • Set your voxel world world generator class to that new blueprint

You should now have much bigger hills

Sphere World Generator

Change GetValueImpl to:

// Radius of the world
const float Radius = 100.f;

// Normalize the position to get the 3D noise sample position
const FVector SamplePosition = FVector(X, Y, Z).GetSafeNormal();

// Compute noise. Note that the noise has a much higher frequency since the sample position is normalized
const float Height = Radius + Noise.GetPerlin_3D(SamplePosition.X, SamplePosition.Y, SamplePosition.Z, 1.f) * NoiseHeight;

// Value = DistanceFromCenter - Height
float Value = FVector(X, Y, Z).Size() - Height;

// Smoother gradient
Value /= 5;

return Value;

Workflow

I recommend disabling Hot Reload and enabling Live Coding instead. Also consider getting Resharper C++ or Visual Assist.

Technical details

  • GetValueImpl and GetMaterialImpl can be called at any time from any thread. They must be thread-safe, and always return the same value.

  • To check if your GetValueImpl is helping, use voxel.renderer.ShowChunksEmptyStates 1

Example of result:

Here only the red chunks are actually computed, the green chunks are skipped.

Last updated