Zylann / godot_heightmap_plugin

HeightMap terrain for Godot implemented in GDScript
Other
1.71k stars 159 forks source link

Use materials for textures #98

Closed GammaGames closed 4 years ago

GammaGames commented 4 years ago

I have a set of materials already set up (with albedo texture, albedo color, normal, uv scaling, etc), but I cannot use them to paint onto a terrain. Is this a planned feature?

GammaGames commented 4 years ago

I have the same issue with the detail layer, I can't find a place to set a material with a custom scale.

Zylann commented 4 years ago

It's not even close to be planned, due to how rendering works. Godot's rendering pipeline is too simple to have such a nice abstraction.

Terrain rendering works very differently than typical models. Multiple materials cannot work using the current Godot rendering API because they need to be able to blend and support very large seamless areas, which is impossible in forward rendering. It would force the terrain to be made of different meshes, each of them having their own material. Not only this would not blend at all, but is completely incompatible with how this plugin works. This plugin generates no geometry at all, it's all done in shader, that's what makes it fast. SpatialMaterial is not suited for this technique.

The approach is to take a pre-made grid, displace it with a single shader that can handle heightmaps, multiple textures and transitions in one go. That's why you don't create multiple materials for the terrain (you can't in Unity either, or you'd rewrite the whole thing), you instead configure one big material specifically designed for terrains.

By default the plugin comes with albedo, normal map, roughness and depth (the latter being used for blending). It also has optional triplanar mapping in the cliff slot, and supports up to 4 sets of textures. So it should have most common features out of the box. If you need more features you have to fork the shader, which is possible to override from the inspector.

About DetailLayer: This one is simpler, but it still does not allow you to use a SpatialMaterial for the same reasons. Grass is generated with GPU instancing and displaced and blended automatically using the heightmap, and that's all in shader as well, for speed. It also has default parameters for common use, but you should be able to add features to the shader by forking it too, from the inspector.

GammaGames commented 4 years ago

displace it with a single shader that can handle heightmaps

So does it essentially take this tutorial and make into into an asset? https://docs.godotengine.org/en/3.1/tutorials/3d/vertex_displacement_with_shaders.html

depth (the latter being used for blending)

That’s very cool!

I didn’t realize how customizable this is, if you’ve got some know how! Feel free to close the issue if you’d like

Zylann commented 4 years ago

Yes it uses the same technique as described in the docs tutorial.

I wrote some doc to get started with the plugin: https://github.com/Zylann/godot_heightmap_plugin/blob/master/addons/zylann.hterrain/doc/main.md