Project a grid on top of terrain

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ninfur

I want to project a repeatable grid on to a 3D terrain, similar to what can be seen in a lot of strategy, building or simulation games, like Civilization, or the Sims. How can I go about achieving this in Godot 4.0?

The most obvious choice would be to use the new Decal node to project a grid texture on to the terrain. This kind of works, but I haven’t found a way to make the texture repeat indefinately. I was hoping it would be possible to assign a shader material to the decal, so that I could modify the UV’s etc. But as far as I can tell this is not possible.

Another idea is to modify the terrain’s material shader to include a planar projection of the texture. This will likely also work, but I would prefer a solution that works on multiple different meshes and materials, not specific to some materials.

Any idea’s or suggestions are welcome.

Update:
Found that there is a proposal to add support for custom decal materials, but based on the comments, it seems to be difficult to do without affecting performance too much.

:bust_in_silhouette: Reply From: Wakatta

Option 3 is the easiest to implement.

in the Terrain’s material next_pass create a new material and set the albedo_texture to something like this

In UV1 select triplanar and adjust the scales as needed

If you’d like the grid to always be above the Terrain the same can be achieved using a Shader and offsetting the VERTEX.y using a heightmap

Yeah, this should be pretty simple to do. My main concern with this approach is that it would require adding the second material pass to, potentially, many different materials. For example if there is a rock with a different material to the terrain, that should also display the grid.

I’m not sure how decals handle this, because they will happily project to any mesh/material that matches the specified layer(s). Maybe it is just dynamically adding/removing a secondary material pass to any meshes that intersect with its bound.

Ninfur | 2022-11-01 15:04