A complete planet generation system using Surface Nets mesh generation with octree-based level of detail (LOD) for Unreal Engine 5.6.
- Surface Nets Algorithm: Smooth mesh generation from voxel density fields
- Octree-based LOD: Hierarchical spatial subdivision with automatic LOD switching
- Real-time Planet Generation: Spherical planets with procedural terrain
- Performance Optimized: Multi-threaded mesh generation and memory pooling
- Blueprint Integration: Runtime parameter adjustment and configuration
- Collision Support: Automatic collision mesh generation
- Seamless Transitions: Smooth LOD switching without visual artifacts
Main planet actor that manages the entire planet generation system.
Key Features:
- Mesh component pooling for performance
- Real-time mesh updates based on camera position
- Material and collision configuration
- Blueprint-exposed parameters
Manages the octree structure for spatial subdivision and LOD.
Key Features:
- Hierarchical octree with configurable depth
- Distance-based LOD switching
- Frustum culling integration
- Dynamic subdivision and merging
Implements the Surface Nets mesh generation algorithm.
Key Features:
- Smooth vertex positioning using gradient-based smoothing
- Efficient triangle generation
- Normal calculation for proper lighting
- Adaptive resolution based on LOD level
Procedural noise generation for planet terrain.
Key Features:
- Fractal noise with configurable octaves
- Planet radius and amplitude controls
- Density field sampling for Surface Nets
- Blueprint-configurable parameters
Individual terrain chunk representation.
Key Features:
- LOD-based voxel resolution
- Mesh data caching
- Distance-based subdivision/merging decisions
- Efficient memory management
- Unreal Engine 5.6
- Visual Studio 2022 (Windows) or Xcode (Mac)
- C++ development tools
-
Clone the Repository
git clone https://github.com/Tuafo/surface-nets-ue.git cd surface-nets-ue -
Generate Project Files
- Right-click on
SurfaceNetsUE.uproject - Select "Generate Visual Studio project files"
- Right-click on
-
Build the Project
- Open
SurfaceNetsUE.slnin Visual Studio - Build the solution in Development Editor configuration
- Open
-
Launch the Editor
- Open
SurfaceNetsUE.uprojectin Unreal Engine 5.6
- Open
-
Create a Planet
- In the editor, drag
APlanetActorinto your level - Configure planet parameters in the Details panel
- In the editor, drag
-
Configure Noise Parameters
- Adjust
NoiseGeneratorsettings for terrain variation - Modify
PlanetRadius,NoiseScale, andNoiseAmplitude
- Adjust
-
Tune LOD Settings
- Configure
OctreeComponentLOD distances - Adjust
MaxDepthandRootSizefor your use case
- Configure
-
Play and Test
- Press Play to see real-time planet generation
- Move around to observe LOD transitions
- PlanetRadius: Base radius of the planet sphere
- NoiseScale: Scale of terrain noise features
- NoiseAmplitude: Height variation amplitude
- Octaves: Number of noise octaves for detail
- Lacunarity: Frequency multiplier between octaves
- Persistence: Amplitude multiplier between octaves
- MaxDepth: Maximum octree subdivision depth (4-8 recommended)
- RootSize: Size of the root octree node
- LODDistances: Array of distances for LOD switching
- UpdateFrequency: How often to update LOD (in seconds)
- MaxMeshComponents: Maximum number of mesh components to pool
- EnableCollision: Whether to generate collision meshes
- EnableFrustumCulling: Enable camera frustum culling
The Surface Nets algorithm generates smooth meshes from voxel data:
- Density Sampling: Sample density field at voxel grid points
- Surface Detection: Identify cubes containing the surface
- Vertex Placement: Calculate smooth vertex positions using gradients
- Mesh Generation: Generate triangles connecting adjacent vertices
- Normal Calculation: Compute normals from density gradients
The octree manages spatial subdivision:
- Initialization: Create root node covering the entire planet
- Subdivision: Split nodes based on camera distance
- Merging: Combine distant nodes to reduce detail
- Frustum Culling: Skip invisible nodes
- Mesh Updates: Generate meshes for visible leaf nodes
Efficient memory usage through:
- Component Pooling: Reuse ProceduralMeshComponent instances
- Chunk Caching: Cache generated mesh data
- Dynamic Loading: Load/unload chunks based on visibility
- Smart Pointers: Automatic memory cleanup for octree nodes
- 60 FPS: Optimized for real-time use
- Scalable LOD: 4-5 LOD levels with smooth transitions
- Memory Efficient: Pooled components and cached data
- Multi-threaded: Asynchronous mesh generation (future enhancement)
- Tune LOD Distances: Adjust based on your camera movement speed
- Limit Max Depth: Higher depth = more detail but worse performance
- Reduce Update Frequency: Lower frequency for distant planets
- Use Frustum Culling: Enable for large planets
- Monitor Memory: Watch chunk count and mesh complexity
All major parameters are exposed to Blueprint:
- Planet radius and noise parameters
- Material assignment
- Collision configuration
- Performance settings
InitializePlanet(): Reinitialize with new parametersUpdatePlanetMeshes(): Force mesh updateSetNoiseGenerator(): Change noise configuration
Create custom noise generators by inheriting from UNoiseGenerator:
UCLASS(BlueprintType, Blueprintable)
class YOURPROJECT_API UCustomNoiseGenerator : public UNoiseGenerator
{
GENERATED_BODY()
public:
virtual float SampleDensity(const FVector& WorldPosition) const override;
};Implement alternative meshing algorithms by modifying FSurfaceNets:
// Custom vertex placement
FVector CustomVertexPosition(const TArray<float>& DensityField, ...);
// Custom triangle generation
void GenerateCustomMesh(...);Future enhancements could include:
- Terrain Editing: Real-time voxel modification
- Multiple Biomes: Different terrain types
- Atmospheric Rendering: Volumetric atmosphere
- Planetary Physics: Gravity and orbital mechanics
- Multi-threading: Parallel mesh generation
Planet not appearing:
- Check that
APlanetActoris in the level - Verify camera is within LOD range
- Ensure
NoiseGeneratoris configured
Poor performance:
- Reduce
MaxDepthin octree settings - Increase LOD distances
- Lower
UpdateFrequency - Enable frustum culling
Visual artifacts:
- Check mesh normals are being calculated
- Verify Surface Nets parameters
- Ensure proper LOD transitions
Compilation errors:
- Verify UE 5.6 installation
- Check module dependencies in Build.cs
- Regenerate project files
Enable verbose logging in Project Settings > Engine > Logging:
- Set
LogSurfaceNetstoVerbosefor detailed output
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
- Follow Unreal Engine coding standards
- Use clear, descriptive variable names
- Add comments for complex algorithms
- Document public APIs
This project is licensed under the MIT License - see the LICENSE file for details.
- Surface Nets algorithm based on research by Sarah Frisken
- Octree implementation inspired by UE4/5 hierarchical spatial data structures
- Noise generation techniques from various procedural generation sources
For questions and support:
- Create an issue on GitHub
- Check the documentation for common solutions
- Review the example configurations