Splatmapping - any examples?

slapinslapin Posts: 43Member

Hi all!

Have anybodyd did terrain heightmap with splatmapping in Godot?

I need more than 4 splatmap channels and I need height data to put up objects.

Also have anybody managed to make collision shape for such terrain and some sort of navigation?

Also Bullet supports heightmap collision shape - was it integrated to Godot?

I use git master.

Answers

  • bluepangolin55bluepangolin55 Posts: 12Member
    edited July 31 Answer ✓

    Hey Slapin,
    I have implemented a procedurally generated terrain with splatmapping. So far however I have only implemented the simple version with 4 channels. For more channels my first approach would be to use 2 splatmap images, which should give you 4*4 channels. However maybe there are more clever way to do it (I haven't researched yet).
    In case you haven't seen it, this video explains how to use splatmaps in Godot: . The shader code might be outdated, so I'm posting the code that I'm currenty using:

    shader_type spatial;    
    uniform sampler2D texture1;
    uniform sampler2D texture2;
    uniform sampler2D texture3;
    uniform sampler2D texture4;
    uniform sampler2D splatmap;
    uniform float resolution = 16;
    void fragment () {
        vec3 result;
        float mix1 = texture(splatmap, UV).r;
        float mix2 = texture(splatmap, UV).g;
        float mix3 = texture(splatmap, UV).b;
        float mix4 = 1.0-texture(splatmap, UV).a;
        vec3 color1 = texture(texture1, UV*resolution).rgb*mix1;
        vec3 color2 = texture(texture2, UV*resolution).rgb*mix2;
        vec3 color3 = texture(texture3, UV*resolution).rgb*mix3;
        vec3 color4 = texture(texture4, UV*resolution).rgb*mix4;
        result = color1 + color2 + color3 + color4;
        ALBEDO = result;
    }
    

    I have also managed to implement navigation using Godot's Navmesh. I'm building the navigation mesh at together with the terrain mesh, but leave out vertices that are under water or an a location that is very steep. Characters are then able to find their way around lakes or up a hill using a reasonable path. I can post some example code if you're interested. The downside of this approach however is that it's hard to change the navmesh at runtime (or at least I'm not aware on how to do it). For example I'd like to be able to exclude an area after a building has been placed or a new tree has grown.
    I'm setting the height of an object by calculating the height, not using the terrain mesh. And I'm not using a heightmap, but just create the terrain using SurfaceTool to create meshes.
    I have not implemented collisions.

  • slapinslapin Posts: 43Member

    Well, code is always interesting.

    About dynamic navigation - if you see c++ navigation code from Godot source, it is possible to add navmesh pieces. A problem is that nobody gave appropriate handles to generate these at runtime.

    I hacked-up a module based on Detour and DetourCrowd, which is independent of Godot navigation and allows area tagging, fast obstacle placement and multi-agent navigation, but it is very crude and buggy now. Also there is certain opposition to it I guess, so the only hope to have decent navigation in Godot is that somebody adds these features to stock navigation code eventually. Currently I just basically bind DetourCrowd API functions, this uses about 10% of features, so the code as very far from complete. I hope to release that in form usable by others in a few months.

    I plan to use heightmap-based terrain (using shader), Bullet heightmap collision and DetourCrowd based navigation in my game (unless somebody implements some better systems in Godot by then). DetourCrowd and Detour are parts of the same "recastnavigation" suite as Recast itself.

  • bluepangolin55bluepangolin55 Posts: 12Member

    Detour sounds like an interesting alternative and I might check it out, thanks :)

    @slapin said:
    Well, code is always interesting.

    Regarding code samples: I'll only post it, if you are interested in a specific part of it (for example how to build a navmesh or how to set the splatmap parameters, etc.). I don't want to post everything here, since it's a lot and I would just have to write a big post explaining all the details. (Actually I was thinking about writing a blog with some small tutorials for Godot. I would love to see more Godot tutorials myself. )

  • ZireaelZireael Posts: 62Member

    @slapin said:
    Well, code is always interesting.

    About dynamic navigation - if you see c++ navigation code from Godot source, it is possible to add navmesh pieces. A problem is that nobody gave appropriate handles to generate these at runtime.

    I hacked-up a module based on Detour and DetourCrowd, which is independent of Godot navigation and allows area tagging, fast obstacle placement and multi-agent navigation, but it is very crude and buggy now. Also there is certain opposition to it I guess, so the only hope to have decent navigation in Godot is that somebody adds these features to stock navigation code eventually. Currently I just basically bind DetourCrowd API functions, this uses about 10% of features, so the code as very far from complete. I hope to release that in form usable by others in a few months.

    I plan to use heightmap-based terrain (using shader), Bullet heightmap collision and DetourCrowd based navigation in my game (unless somebody implements some better systems in Godot by then). DetourCrowd and Detour are parts of the same "recastnavigation" suite as Recast itself.

    Navmesh pieces can be generated at runtime (from the Navmesh class) but it doesn't take advantage of the Recast code so you have to manually make sure all the verts match if you have multiple pieces.

    I'd love to see your module, too.

    @bluepangolin55: A blog with Godot tutorials would be awesome!

Sign In or Register to comment.