Heightmap terrain plugin

ZylannZylann Posts: 31Member
edited May 19 in Resources
I made a simple heightmap terrain pluging for Godot:

Old post with super-old version:

Feel free to ask questions here :)

Tags :


  • MegalomaniakMegalomaniak Posts: 2,884Admin
    edited September 2016
    Been thinking of doing that too now that we have gdscript plugins api, I might be willing and interested in collaborating on improvements if you intend to keep this mit licensed.

    edit: is there a workflow for importing height- and splat-maps generated in external tools yet? I'm guessing it's doable in shader anyway however it would be nice to have bundled.

    edit2: Ok, the first thing to 'fix' would probably be to make sure that navigation still works while the terrain node is selected. :) But looks promising, I'll continue toying with it now...
  • ZylannZylann Posts: 31Member
    edited September 2016
    The plugin allows to export the heightmap as greyscale and normal map, but it should be doable to do importing. Images don't have enough color resolution (0-255) but should work. Otherwise it depends on which format you expect to load, because they might differ depending on the external tool used.

    My plugin doesn't supports texture painting yet because I mainly wonder how to do it^^ it can usually be done with additional vertex data, for example using UV2 to add two layers of textures with x and y values (0 = nothing, 1 = textured), however that means UV2 cannot be used with classic materials.

    Most notably, I have an issue with Godot and texturing terrains, I cannot use any uniform in 3D shaders, so I cannot test anything related until it's fixed :s
    Godot 3.0 should add many features that would be useful to terrains.

    Also, just a note for future questions:
    this is a GDScript plugin, if I find that a feature is too CPU-heavy (even when threaded), I may not implement it, and reserve this for a future C++ implementation in Godot 3.0.
  • MegalomaniakMegalomaniak Posts: 2,884Admin
    Whoa what do you mean you can't use uniforms in shaders? Is it a recent dev. build 'cause 2.1 seems to work for me. If it's a bug though I don't even... Scary.
  • KioriKiori Posts: 246Member
    The plugin in its self is fantastic, the fact that it's implemented in gdscript means it deserve an instant awesome.

    Good work!
  • KioriKiori Posts: 246Member
    One behavior that i would change is that when you click on a surface it increases the height up to a certain point, then stops. My expected result would be for it to increase the height on that point indefinitely, until i let go of the mouse button. Or maybe I'm missing something?
  • ZylannZylann Posts: 31Member
    @Kiori ;yeah, currently you have to move the mouse a little bit for the editor to continue painting. That's because I paint inside the _input() callback, I should do that in _process() too.
  • HumanSheepleHumanSheeple Posts: 1Member

    @Zylann First and foremost I want to say I love your terrain plugin. I have spent the last couple of days working on improving it to do a vertex paint mode. I'm currently a bit stuck and I think you are probably the only person in the world who can actually help.

    Modifying the menu to have a a vertex button and a dropper tool was the easy part:
    Image attatched:

    The reason I am doing this is because last year I was halfway through developing my very own game using the blender game engine and switched to the Uchronia blender fork. During my development I stumbled across a way of using vertex colors to map seemeless terrain types. I was previously told it was only possible to seemlessly blend 4 terrain types, by using combinations of sin and cosine nodes I have managed to do 8, now 9 thanks to makign use of normals similiar to how your terrain engine has green and brown tiles. So if there is a slope it does this rocky texture.

    As you can see from when I hooked up vertex color to diffuse this is what the terrain actually looks like just to further verify I am not lying or have cheated this process in any way shape or form:

    Here is how I linked up the nodes in the shader graph mode:

    I have found a way to change vertex colors within your terrain editor albeit crudely from code directly in the "_generate_mesh_at" function in terrain.gd using the lines of code:

    var meshData = MeshDataTool.new()
    meshData.create_from_surface(mesh, 0)
    var vertexindex = meshData.get_vertex_count()
    var vertexcolor = Color(0.0, 0.0, 1.0)
    for i in range(0,vertexindex):
        meshData.set_vertex_color(i, vertexcolor)

    This sets the terrain to Blue ( like you didn't know that already! :) )

    I've tried to rewrite the entire data structure from 2D arrays to 3D arrays.
    Your previous structure had grid[x][y] which would return a vector3 if I'm not mistaken. I'm trying to rewrite it so that it can store grid[x][y][z] where z has 5 var's [x][y][0] is the vector3, 1 2 3 4 are going to be red green blue and alpha floats.

    Anyway I've spent a long time trying to rewrite the code adding lots of [0]'s trying to trace the code back and I'm now really stuck and lost. I would really appreciate your help

    Here's one of the error messages:

    I have some code pastes of the work in progress I have done

    modified terrain.gd: https://paste.ee/p/APYa8
    modified terrain_brush.gd: https://paste.ee/p/NCICL
    modified terrain_plugin.gf: https://paste.ee/p/Kg7np
    And most importantly modified terrain_utils.gd: https://paste.ee/p/btrAc

    Please obi wan kenobi you are my only hope

  • MirceaKitsuneMirceaKitsune Posts: 43Member

    Greetings. I wanted to ask if Git master is compatible with the upcoming Godot 4.0. If not is there a deadline as to when a working version will exist? I'm very eager to switch go the new Godot once it's out but unsure if this plugin will stop working and put the project I'm using it for on hold in terms of upgrading. Thank you.

  • ZylannZylann Posts: 31Member

    The plugin does not work with Godot 4.0 yet, because that version of Godot is not ready for production. I will start working on that when it reaches beta stage, most likely.

Sign In or Register to comment.