HeightMap terrain for Godot implemented in GDScript

HeightMap terrain plugin for Godot Engine

Editor screenshot

Heightmap-based terrain for Godot 3.1.x, 3.2.x, 3.3.x and 3.4.x. It supports texture painting, colouring, holes, level of detail and grass, while still targetting the Godot API.

Note: The current Godot master branch isn't supported yet. Use Godot 3.x if you want to use this plugin.

This repository holds the latest development version, which means it has the latest features but can also have bugs. For a "stable" version, use the asset library or download from a commit tagged with a version. The master branch is the latest development version, and may have bugs. Some major features can also be in other branches until they are done. For release versions, check the Git branches named after those versions, like 0.10.

To get the last version that supported Godot 3.0.6, checkout branch 0.10.

Installation

This is a regular editor plugin. Copy the contents of addons/zylann.hterrain into the same folder in your project, and activate it in your project settings.

The plugin now comes with no extra assets to stay lightweight. If you want to try an example scene, you can install this demo once the plugin is setup and active: https://github.com/Zylann/godot_hterrain_demo

Usage

Documentation

Why this is a plugin

Godot has no terrain system for 3D at the moment, so I made one. The plugin is currently fully implemented in GDScript. I wish I could make it a C++ module, but being a GDScript plugin allows much faster iteration and everyone can try it and modify it much more easily. Recently, some parts started to be implemented as a GDNative library to speed them up (only on supported platforms). Godot could get a terrain system in the future, maybe in 4.x or after, but it's going to be a long wait, so developping this plugin allows me to explore a lot of things up-front, such as procedural generation and editor tools, which could still be of use later.

GLES2 support

Due to a number of things GLES2 doesn't support officially, and the disparity of extensions Godot is currently trying to use, making this plugin work in GLES2 is quite a lot of work. Some things might be easier, others need completely different implementations.

Here are some of the causes:

  • textureSize doesn't work in shaders. If the following issues can be solved, we could rewrite all shaders without using this function so they are compatible between both renderers.

  • High range textures get clamped to 0..1, making heightmaps completely flat (GLES2 actually supports this through an extension, but Godot doesn't appear to use it).

  • VisualServer has set_data_partial, but it's not implemented so editing terrain doesn't work. GLES2 should also support partial texture update.

  • GLES2 does not require texture fetch from vertex shader to work, so some rare mobile devices implement it, others don't. This plugin heavily relies on displacing vertices from shader. Generating unique meshes would require a huge rewrite just so it works on those devices and would use a ton more memory to store all the required meshes and LODs.

  • The procedural generator doesn't work, and likely never will in GLES2 because it relies on HDR framebuffers.

  • For more info, see https://github.com/Zylann/godot_heightmap_plugin/issues/96

Supporters

This plugin is a non-profit project developped by voluntary contributors. The following is the list of the current donors. Thanks for your support :)

Supporters

- wacyym
- Sergey Lapin (slapin)
- Jonas (NoFr1ends)
- lenis0012
- Phyronnaz
- RonanZe
- furtherorbit
- jp.owo.Manda (segfault-god)
- hidemat
- Jakub Buriánek (Buri)
- Justin Swanhart (Greenlion)
- Sebastian Clausen (sclausen)
- MrGreaterThan
Owner
Comments
  • GNU/Linux doesn't seem to be 100% supported

    GNU/Linux doesn't seem to be 100% supported

    In the Editor everything works fine, but when I export the project the hterrain map doesn't have any textures.

    When I open the project in the Godot engine I get the error "does not have a library for the current platform.". In addons/zylann.hterrain/native/factory.gd there is only Windows in the _supported_os. In addons/zylann.hterrain/native/bin/ is only a win64 folder with a .dll, no linux with a .so library file.

    I'm working on Ubuntu 20.04 (64 Bit).

  • Ability to paint a lot of different textures

    Ability to paint a lot of different textures

    Currently the plugin is limited to 4, or maybe up to 8 different textures. Adding more would drop performance significantly.

    In order to support more, we could use texture arrays in a new shader, but Godot doesn't support them yet.

    Writing an atlas-based shader could help emulating texture arrays, however it has annoying limitations such as pixel bleeding with mipmaps and filter.

    Eventually there should be a more flexible API so shaders can be switched and the editor can adapt to which features it supports.

    Depends on https://github.com/godotengine/godot/issues/9008

  • Looping Error when assigning the data file

    Looping Error when assigning the data file

    When assigning the data file for the terrain, afterwards it loops this error. "res://addons/zylann.hterrain/hterrain.gd:1177 - Invalid call. Nonexistent function 'update' in base 'Nil'."

    To Reproduce Steps to reproduce the behavior:

    1. Enable addon
    2. Assign the data directory
    3. See error and lack of terrain

    Expected behavior The terrain to appear after assigning the folder

    Screenshots Taken When I added the Hterrain Node into the scene image

    Taken once i assigned the directory image

    Environment

    • OS: Windows
    • Graphics card: Intel(R) HD Graphics 400 (Don't judge lol)
    • Godot version V3.4.4
    • Plugin version: Master, 1.6.1 1.6 1.5 (I've tried many)
    • Renderer used: GLES3
  • Raycasting the terrain can be very slow (main cause of slowdown in Godot 3.0.6)

    Raycasting the terrain can be very slow (main cause of slowdown in Godot 3.0.6)

    I have a very simple scene set up with a very simple terrain, a directional light, and a camera. When collision is enabled and the scene is run or played in the editor, the scene struggles to achieve more than a few fps. If collision is disabled, the scene runs normally.

    Is there some setting I'm missing? I would like to use collision with my project if possible.

  • Native QuadTreeLod

    Native QuadTreeLod

    This PR ports QuadTreeLod to C++ GDNative with a GDScript fallback.

    @painfulexistence helped me fix some bugs in the implementation.

    On a 2k terrain with a GTX 1060, windows 10/64, I get about a 5-20% improvement in FPS depending on where I look.

  • Terrain directory always empty - Data not saving

    Terrain directory always empty - Data not saving

    It is entirely possible I'm just doing this wrong and don't know the steps to take to save the terrain file into the chosen directory, but for the moment I can't save it manually, and it doesn't save automatically. I have only started using this as of v1.1, and in the changelog it says you removed the save and load menu, but when I tired v1.0 it also doesn't work.

    My scene is as simple as it can be, with a pretty much flat HTerrain, a camera and an omnilight, yet I can't launch the scene without receiving the following errors. I have made the terrain data file and put it in a folder named terrain, but it doesn't seem to be doing anything.

    Any help would be greatly appreciated.

    Also, my apologies if this is the same issue as in issue #75 but the log and details seemed different enough to warrant a separate issue.

    Create HeightMap
    HTerrainCollider: creating body
    Set new data [Resource:32086]
    Connecting new HeightMapData
    HTerrainCollider: setting up heightmap
    Create grid for lod 0, 32x32
    Create grid for lod 1, 16x16
    Create grid for lod 2, 8x8
    Create grid for lod 3, 4x4
    Create grid for lod 4, 2x2
    Create grid for lod 5, 1x1
    Set data done
    Setting chunk size to 16
    Chunk size snapped to 16
    Destroy HTerrain
    Destroy HTerrainCollider
    Running: C:\Program Files (x86)\Godot\Godot_v3.0.6-stable_win64.exe --path C:/Users/**/Documents/Godot/Terrain%20Testing --remote-debug 127.0.0.1:6007 --allow_focus_steal_pid 3268 --position 448,240 res://Node.tscn
    running cmdline: "C:\Program Files (x86)\Godot\Godot_v3.0.6-stable_win64.exe" "--path" "C:/Users/**/Documents/Godot/Terrain%20Testing" "--remote-debug" "127.0.0.1:6007" "--allow_focus_steal_pid" "3268" "--position" "448,240" "res://Node.tscn"
    OpenGL ES 3.0 Renderer: GeForce GTX 1060/PCIe/SSE2
    ERROR: No loader found for resource: res://terrain/data.hterrain
       At: core/io/resource_loader.cpp:186
    ERROR: poll: res://Node.tscn:5 - Parse Error: [ext_resource] referenced nonexistent resource at: res://terrain/data.hterrain
       At: scene/resources/scene_format_text.cpp:439
    ERROR: load: Condition ' err != OK ' is true. returned: RES()
       At: core/io/resource_loader.cpp:149
    ERROR: Failed loading resource: res://Node.tscn
       At: core/io/resource_loader.cpp:186
    ERROR: Failed loading scene: res://Node.tscn
       At: main/main.cpp:1688
    Nothing read: Invalid argument
    ERROR: read: Server disconnected!
    
       At: drivers/windows/stream_peer_tcp_winsock.cpp:203
    WARNING: cleanup: ObjectDB Instances still exist!
         At: core/object.cpp:1989
    

    -- Anemony

  • preview_generator.gd fails in 3.1.Alpha4

    preview_generator.gd fails in 3.1.Alpha4

    Tried to install the plugin on Godot 3.1.Alpha 4 official and it failed to load with an error of:

    Unable to load addon script from path 'res://addons/zylann.hterrain/tools/plugin.gd' There seems to be an error in the code, please check the syntax.
    
    Godot Engine v3.1.alpha.official (c) 2007-2018 Juan Linietsky, Ariel Manzur & Godot Contributors.
     res://addons/zylann.hterrain/tools/preview_generator.gd:11 - Parse Error: Function signature doesn't match the parent. Parent signature is: 'Texture generate(Resource, Vector2)'.
     modules/gdscript/gdscript.cpp:580 - Method/Function Failed, returning: ERR_PARSE_ERROR
     res://addons/zylann.hterrain/tools/plugin.gd:8 - Parse Error: Could not fully preload the script, possible cyclic reference or compilation error.
     modules/gdscript/gdscript.cpp:580 - Method/Function Failed, returning: ERR_PARSE_ERROR
     res://addons/zylann.hterrain/tools/preview_generator.gd:11 - Parse Error: Function signature doesn't match the parent. Parent signature is: 'Texture generate(Resource, Vector2)'.
     modules/gdscript/gdscript.cpp:580 - Method/Function Failed, returning: ERR_PARSE_ERROR
    

    Downloaded zip from GitHub extracted the addons folder into the Godot project. Then in project settings -> plugin tab changed to active and failed.

  • Multisplat shader

    Multisplat shader

    This is to present a new shader I've been working on shortly after releasing the ARRAY shader, because while it has relatively simple code, it is hard to get right and has a few blending issues. This new shader is nicknamed MULTISPLAT16.

    Pros:

    • Allows to use up to 16 materials* on the whole terrain
    • Allows to blend up to 4 materials at the same time on a particular pixel. These materials are chosen dynamically amongst the highest weights on every pixel.
    • Better usability and results pretty much similar to CLASSIC4
    • Almost no artifacts (there are some, but subtle and much easier to avoid than ARRAY)
    • Supports same features as CLASSIC4: depth blending, normal maps, roughness, holes and fading to globalmap (no triplanar yet, I don't know exactly how to proceed without tripling texture fetches unnecessarily).
    • Is a starting point to support a lot more materials by "tiling" index sets, because it supports dynamic indexes due to its filtering of the 4 highest weights, and the 12 spare ones offer plenty of room to hide switching artifacts. However that's for much later.

    Cons:

    • High cost, despite sampling only 4 materials at a time (aka 8 texture calls) and not all 16 (which would be 32). For comparison, I tested the following frame times (duration of the whole render with vsync disabled in fullscreen, not just the shader, as Godot doesnt provide the tools to measure that):
      • Single quad with default material: 0.4 ms
      • CLASSIC4: 0.9 ms
      • ARRAY: 0.74 ms
      • MULTISPLAT16: 1.93 ms
    • Higher memory usage: instead of a single RGBA splatmap, it uses 4 of them, to get to 16 weights. It's mostly a big deal with huge terrains, so in the future streaming them out early to fallback on globalmap will have to be considered.

    This shader also requires texture arrays to work, so it's like a middle ground between ARRAY and CLASSIC4.

    I'm still looking for ways to further optimize it, but so far I could not find more tricks to do so. Lowering to 12 materials and blending only 3 is of course a possibility, if considered enough. Fading to globalmap also helps a lot here, because far away pixels can bypass the entire blending system and use the baked albedo instead. Amusingly, putting objects occluding the ground also help (characters, vehicles, grass, trees, roads, buildings), thanks to depth testing avoiding costy ground pixels from being calculated.

    It can be tested in the multisplat branch for now. Source: https://github.com/Zylann/godot_heightmap_plugin/blob/multisplat/addons/zylann.hterrain/shaders/multisplat16.shader


    *materials: not actual materials. In this plugin, one material actually corresponds to 2 textures: albedo_bump, and normal_roughness.

  • Add grass patches configuration

    Add grass patches configuration

    This adds the configuration option in the detail layer in order to improve grass rendering. In its current form the option is called patches and allows for 3 different values:

    • 1: Grass is rendered as a single quad
    • 2: Grass is rendered as 2 quads (90° rotated each)
    • 3: Grass is rendered as 3 quads (60° rotated each)

    Also this PR adds some type inference for declared variables. The type inference commits are separate to make this PR easily reviewable.

    Dock Screenshot

    2020-03-07-164643_373x1114_scrot

    Screenshots for the different Patches

    Patches = 1

    2020-03-07-164610_1776x1182_scrot

    Patches = 2

    2020-03-07-164536_1784x1186_scrot

    Patches = 3

    2020-03-07-164625_1773x1169_scrot

  • Importer not loading textures in array mode

    Importer not loading textures in array mode

    Describe the bug When I try to import new-additional texture to texture array importer does not load already present textures and it does not save import directory.

    Screenshots obraz Also I have defined 4 textures and am using MultiSplat16Lite cause else terrain looks like 1 big mirror

  • GLES2 support ?

    GLES2 support ?

    the info reads that it support gles2 While it do work on gles3 renderer, then while switched to gles2, the terrain surface is not visible and there are spam of shader compile errors.

    Does it support gles2 or .md info is wrong ?

  • Switching shader type

    Switching shader type

    If I wanted to switch from Classic 4 Lite to MultiSplat 16 would there be easy way to transfer texture data from one to other (I want to get more materials then 4)

  • The selected terrain brush shape is not updating in the editor

    The selected terrain brush shape is not updating in the editor

    The brush shape in the editor does not change from the default circle (round2.exr) when another brush shape is selected from the pop-up menu. It makes editing terrain very confusing.

    One suggestion would be to separate the brush shape list and brush settings altogether.

    image

  • Ragdolls jumping on Hterrain collision

    Ragdolls jumping on Hterrain collision

    Describe the bug Enabling ragdoll makes it jumpy when laying on HTerrain. Additional info is that generating collision mesh and using it fixes the issue, but it's a very large collision mesh, so using it is a bad idea cause its unoptimized unlike HTerrain's collision.

    To Reproduce Steps to reproduce the behavior:

    1. Create character with ragdoll
    2. Enable ragdoll whe ncharacter is standing on HTerrain
    3. See error Linking a reproduction project may help. If you see any errors in the console, that may also help.

    Expected behavior Ragdoll having same behaviour as on other collision shapes

    Screenshots Video: ragdoll_problem.webm

    Environment

    • OS: WIndows 10
    • Graphics card: RTX 2080
    • Godot version: 3.5.1.stable.official
    • Plugin version: (I dont get where to see but I pressed download few days ago)
    • Renderer used: GLES 3
  • rotating HTerrainDetailLayer objects to camera

    rotating HTerrainDetailLayer objects to camera

    Good afternoon, I ask you to add a similar function to your plugin, because I need it, but I can’t implement it in any way, I have to write to you. To make objects like Terrain Detail rotate towards the camera. please add this function to your plugin. an example of how it should look on the screenshot, grass and other objects should rotate towards the player изображение_2022-11-12_120544151

  • Black screen in android

    Black screen in android

    Works fine in pc, but when i export it to apk, It shows black screen in android device image My android device supports gles2, gles3, vulkan

    Environment

    • OS: [e.g. iOS]
    • Graphics card (you can find out in Godot's console log)
    • Godot version [e.g. 3.2.1]
    • Plugin version (or commit hash if you got it from Github directly)
    • Renderer used: note that GLES2 is not supported.
  • Raise brush has steps

    Raise brush has steps

    Describe the bug

    When applying the raise brush to a terrain it creates weird step patterns.

    I first noticed it when the terrain became unexpectedly bumpy after editing, but the issue is most visible when using a small opacity brush on the same very small area for a few seconds. (see screenshot).

    I suspected the reason is the small resolution brush but it seems that is not the case. I edited the raise shader to not use the bursh image but a gradient coded in the shader and I still run into the same issue.

    Another weird artifact that I noticed is when trying to mess with this raise shader is that I cannot seem to be able to adjust the height by very small amounts. When I tried to add the following code for debug purposes, the height did not change at all, until I raised the brush_value to 0.125.

    void fragment() {
    	float brush_value = u_factor * u_opacity * texture(TEXTURE, UV).r;
    	brush_value = 0.1;
    	float src_h = texture(u_src_texture, get_src_uv(SCREEN_UV)).r;
    	float h = src_h + brush_value;
    	COLOR = vec4(h, 0.0, 0.0, 1.0);
    }
    

    I suspect this is related.

    To Reproduce Steps to reproduce the behavior:

    1. Create a Hterrain
    2. Grab the raise brush
    3. set the size to about 200 and the opacity to 4
    4. Try to slowly draw on the terrain

    Expected behavior The plugin produces a smooth surface without steps.

    Screenshots image The hills were made with 20, 4 and 2 as opacity setting (left to right).

    Environment System: Host: pop-os Kernel: 5.19.0-76051900-generic x86_64 bits: 64 Desktop: GNOME 42.3.1 Distro: Pop!_OS 22.04 LTS

    Godot v3.5.stable Plugin version: 1.6.1 GLES3

A tic-tac-toe game with a simple Minimax AI implemented

Tic-Tac-Toe-in-Golang A tic-tac-toe game with a simple Minimax AI implemented I built this over a period of about a week, starting with first building

Dec 26, 2021
GDScript Syntax Highlighting in GNU Nano

nano-gdscript GDScript Syntax Highlighting in GNU Nano. Updated regularly every minor updates. Contributions are welcomed Installation This is 100% fr

Dec 20, 2022
A CLI tool implemented by Golang to manage `CloudComb` resource

CloudComb CLI tool: comb Get Started comb is a CLI tool for manage resources in CloudComb base on cloudcomb-go-sdk. Support Mac, Linux and Windows. We

Jan 4, 2021
Adaptive Radix Trees implemented in Go

An Adaptive Radix Tree Implementation in Go This library provides a Go implementation of the Adaptive Radix Tree (ART). Features: Lookup performance s

Dec 30, 2022
High-performance minimalist queue implemented using a stripped-down lock-free ringbuffer, written in Go (golang.org)

This project is no longer maintained - feel free to fork the project! gringo A high-performance minimalist queue implemented using a stripped-down loc

Oct 24, 2022
A MySQL-compatible relational database with a storage agnostic query engine. Implemented in pure Go.

go-mysql-server is a SQL engine which parses standard SQL (based on MySQL syntax) and executes queries on data sources of your choice. A simple in-memory database and table implementation are provided, and you can query any data source you want by implementing a few interfaces.

Dec 27, 2022
BGP implemented in the Go Programming Language

GoBGP: BGP implementation in Go GoBGP is an open source BGP implementation designed from scratch for modern environment and implemented in a modern pr

Dec 31, 2022
A persistent queue implemented in Go.

goq goq is a persistent queue implemented in Go. Features Communication over HTTP RESTful with JSON responses (trivial to write client libraries) Mini

Feb 10, 2022
URI Templates (RFC 6570) implemented in Go

uritemplates -- import "github.com/jtacoma/uritemplates" Package uritemplates is a level 4 implementation of RFC 6570 (URI Template, http://tools.ietf

Jan 15, 2022
NEAT (NeuroEvolution of Augmenting Topologies) implemented in Go
NEAT (NeuroEvolution of Augmenting Topologies) implemented in Go

CURRENTLY NOT WORKING! There will be a further notice when it's updated. NEAT (NeuroEvolution of Augmenting Topologies) is a neuroevolution algorithm

Dec 4, 2022
A multilayer perceptron network implemented in Go, with training via backpropagation.

Neural Go I'm in the process of making significant changes to this package, particularly, to make it more modular, and to base it around an actual lin

Sep 27, 2022
GNU GSL Statistics library (v1.15, GPLv3) implemented in Go

Statistics Pure Go implementation of the GSL Statistics library. For the API overview see Godoc. Why create this repository when there is also "github

Nov 23, 2021
FreeDesktop.org (xdg) Specs implemented in Go

xdg Package xdg provides access to the FreeDesktop.org (XDG) specs. Documentation Documentation is available via godoc. Here are direct links to the d

Nov 11, 2022
Firebase Cloud Messaging for application servers implemented using the Go programming language.

Firebase Cloud Notifications Client Firebase Cloud Messaging for application servers implemented using the Go programming language. It's designed for

Dec 17, 2022
Google Cloud Messaging for application servers implemented using the Go programming language.

gcm The Android SDK provides a nice convenience library (com.google.android.gcm.server) that greatly simplifies the interaction between Java-based app

Sep 27, 2022
A collection of well-known string hash functions, implemented in Go

This library is a collection of "well-known" 32-bit string hashes, implemented in Go. It includes: Java string hash ELF-32 Jenkins' One-A

Mar 3, 2022
Germanium is an alternative to Carbon and Silicon implemented in Go.
Germanium is an alternative to Carbon and Silicon implemented in Go.

Germanium is an alternative to Carbon and Silicon implemented in Go. Germanium can work without browser and internet like Silicon.

Dec 5, 2022
This project is a collection of many of the basic tools used on Unix-like operating systems implemented in Go as a learning exercize.

GoUnix This project is a collection of many of the basic tools used on Unix-like operating systems implemented in Go as a learning exercize. The idea

Jul 21, 2022
character-set conversion library implemented in Go

mahonia character-set conversion library implemented in Go. Mahonia is a character-set conversion library implemented in Go. All data is compiled into

Dec 22, 2022