Voxel Plugin
1.2 Legacy
1.2 Legacy
  • Getting Started
    • Quick Start
      • Examples
    • World Generation
      • C++ World Generators
      • Voxel Graph Quick Start
      • Floating Islands
  • Core Systems
    • VoxelWorlds
      • Import Content
      • Voxel Data Items
      • Collisions and Navmesh
      • World Size and Level Of Details
      • Save and Load
      • Multiplayer
      • Easy Systems RPG
    • Voxel Graphs
      • Voxel Graph General Concepts
      • Voxel Graphs Tips and Tricks
      • Voxel Graph Nodes Reference
      • Voxel Graph Outputs
      • Voxel Graph Parameters
      • Custom Graph Nodes
    • Voxel Spawners
    • Materials
      • Multi Index Materials
  • Technical Notes
    • Performance and Profiling
    • Console Commands
    • Blueprint API
    • Release Notes
      • Release Notes 1.1
      • Release Notes 1.2
    • UE5.1 - Material Crash
Powered by GitBook
On this page
  • Included World Generators
  • Creating a new C++ World Generator
  • Using your World Generator
  • Sphere World Generator
  • Workflow
  • Technical details

Was this helpful?

  1. Getting Started
  2. World Generation

C++ World Generators

PreviousWorld GenerationNextVoxel Graph Quick Start

Last updated 1 year ago

Was this helpful?

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

  • using C++

  • using (pro only)

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 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

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.

and

https://github.com/Phyronnaz/VoxelPlugin/blob/master/Source/VoxelExamples/Public/VoxelGeneratorExample.h
https://github.com/Phyronnaz/VoxelPlugin/blob/master/Source/VoxelExamples/Private/VoxelGeneratorExample.cpp
Voxel Graphs
Examples