Terrain3D Documentation
repository·main·Indexed 26 days ago
https://github.com/tokisangames/terrain3dA high-performance terrain system for Godot 4 implemented as a C++ GDExtension. It features large-scale terrain regions (up to 65.5km), foliage instancing with shadow impostors, and comprehensive sculpting and painting tools. The system supports up to 32 textures, 10 LOD levels, and heightmap imports from tools like Gaea, World Creator, and World Machine. It includes built-in ocean support, configurable physics collision, and API methods for mesh generation, raycasting, and navigation.
What's inside Terrain3D
- Terrain3D is a high-performance, editable terrain system designed specifically for Godot 4. It provides tools for terrain manipulation, texture painting, and advanced environmental integration within the Godot engine.
Overview of Terrain3D
mainTerrain3D is a high-performance, editable terrain system designed for Godot 4. It is implemented as a C++ GDExtension, making it compatible with official Godot Engine builds. It can be used via GDScript, C#, or any other language supported by Godot.
Key Capabilities:
- Scale: Supports terrain regions ranging from 64x64m up to 65.5x65.5km (4295km^2) in non-contiguous and variable-sized configurations.
- Visuals: Supports up to 32 textures and up to 10 levels of detail (LOD) for the terrain mesh.
- Foliage: Includes foliage instancing with up to 10 levels of detail and shadow impostors.
- Editing: Features sculpting, hole creation, texture painting, texture detailing, color painting, and wetness painting.
- Importing: Supports heightmap imports from HTerrain, Gaea, World Creator, World Machine, Unity, Unreal, and any tool capable of exporting heightmaps.
Understand the Terrain3DData class
mainThe
Terrain3DDataclass is the central manager for terrain data in Terrain3D. It handles the loading and unloading of regions, data retrieval, and data manipulation.Terrain3D organizes data into regions arranged on a world grid (known as region locations). The actual map data is stored in
Terrain3DRegioninstances, which are saved to individual files.Terrain3DDatacoordinates these pieces to provide a unified interface for the terrain.Understand the two instancing systems in Terrain3D
mainTerrain3D offers two distinct methods for rendering foliage and objects:
Particle Shader (
particles): Uses the GPU to automatically generate meshes around the camera. This is ideal for high-density, procedurally generated meshes like grass. An example is available inextras/particle_example.Terrain3DInstancer (
instances): Uses Godot'sMultiMeshclass to optimally render hundreds of thousands of meshes that have been placed manually or via code. This is better for specific objects like rocks, trees, or debris.
Understand Vertex Painting Constraints
mainTerrain3D is a vertex painter, not a pixel painter.
Performance vs. Precision:
- To maintain high performance, texel density is spread out. For example, 1024x1024 pixels might cover 1024m x 1024m.
- Each square meter is influenced by only 4 pixels of data at its corners.
- Limitation: Pixel-perfect painting is not practical. The system is designed for natural blending of quality textures between vertices rather than high-frequency pixel detail.
- Use Case: It is optimized for producing natural environments using sophisticated blending algorithms.
Understand the Terrain3DRegion resource
mainTheTerrain3DRegionis aResourcethat stores all map data for a specific terrain region in Terrain3D. It contains height maps, control maps, and color maps, along with metadata like region size, location, and vertex spacing.Use Terrain3DTextureAsset to manage terrain textures
mainThe
Terrain3DTextureAssetis aResourcethat contains a set of texture files and specific settings. These assets are intended to be added to aTerrain3DAssetsresource.Important: Textures must be prepared according to the project's specific texture preparation guidelines before use.
Understand Clipmap Terrain and LOD
mainTerrain3D uses a Geomorphing Geometric Clipmap Mesh Terrain (similar to the system used in The Witcher 3).
Key characteristics:
- Automatic LOD: The terrain consists of several flat meshes with varying density; density is higher near the center (camera) and lower further away.
- LOD Blending: Levels of Detail (LODs) are blended together in a circular pattern.
- Camera-Centric: Meshes are centered on the camera to maintain high LODs near the player. While meshes move, the terrain appears stable because the underlying height data remains fixed in world space.
Understand Terrain3D Shader Design and Painting Model
mainTerrain3D uses a vertex-based painting system rather than a pixel-based one. Texture codes are painted at each vertex (defaulting to 1m intervals) and represented as pixels on a Control map. The shader uses material parameters to interpolate and blend these values between vertices.
To inspect the generated shader code, you can enable
shader_override_enabledin the material and leave theshader overrideslot empty. For a minimal implementation of terrain height without texturing, refer toaddons/terrain_3D/extras/shaders/minimum.gdshader.Use Terrain3DEditor for sculpting and painting
mainTheTerrain3DEditorclass is responsible for all sculpting and painting operations within Terrain3D. It allows you to manipulate terrain height, textures, colors, and other properties through various tools and operations.Understand Geometry Clipmap Terrain Rendering
mainTerrain3D uses a geometry clipmap approach for terrain rendering rather than a traditional grid of mesh chunks.
Key characteristics:
- Mesh Generation: Mesh components are generated once at startup and periodically recentered on the camera location.
- LOD (Level of Detail): LODs are built into the initial mesh generation. Lower detail levels are automatically placed at a distance as mesh components recenter on the camera.
- Vertex Updates: Vertex heights are adjusted on each update via a GPU vertex shader that reads from the terrain heightmap.
- Memory Efficiency: The system allows for allocating regions for sculpting and texturing only where needed. This means you only pay VRAM and storage costs for used areas (e.g., islands in a large ocean), rather than the entire world bounds.
Getting Started with Terrain3D
mainTo begin using Terrain3D in your Godot 4 project, follow these steps:
- Understand the System: Read the Introduction to learn how the terrain system operates.
- Install the Addon: Follow the Installation & Upgrade instructions.
- Learn via Tutorials: Watch the tutorial videos and consult the official documentation.
- Get Support: If you encounter issues, refer to the Getting Help guide or join the Discord server.