godot_heightmap_plugin icon indicating copy to clipboard operation
godot_heightmap_plugin copied to clipboard

Mesh generation from terrain using editor tool does not have normals or UV, preventing correct rendering

Open Footkick72 opened this issue 4 years ago • 3 comments

Describe the bug When using "generate mesh (heavy)" in the editor, the generated mesh is broken in relation to material rendering on the mesh. The mesh does not display albedo textures, and the UV triplaner flag result in mesh being black.

As far as I can tell, the issue is with the mesh itself not being generated with either normals or UV, breaking rendering.

To Reproduce Use generate mesh on any terrain, set the mesh material to a new material and attempt to apply a texture. Also, set the UV triplaner flag to true.

Expected behavior The mesh will first not display the texture, and then when setting UV triplaner, will become completely black.

Screenshots Mesh with albedo set not displaying texture Screen Shot 2021-01-15 at 11 05 01 AM

Mesh with UV triplaner set: Screen Shot 2021-01-15 at 11 04 21 AM

Environment

  • OS: Mac OS Catalina 10.15.6
  • Graphics card: Radeon Pro 560X 4 GB
  • Godot version: 3.2.3
  • Plugin version: 1.5.2 (taken from assetlib)
  • Renderer used: GLES3

Footkick72 avatar Jan 15 '21 16:01 Footkick72

The reason this option exist is a workaround to generate pathfinding information, since Godot does not use colliders in 3D to do this, and since the terrain is not a classic mesh, it doesnt do anything. So I added this option to allow temporarily placing a mesh in the world which can be deleted afterward. It is not aimed for rendering.

What are you trying to do?

Zylann avatar Jan 15 '21 18:01 Zylann

@Zylann Thank you for the response. I am trying to make an environment with snow that can increase and decrease in depth, and was thinking to use the generated mesh as a snow layer, and adjust the y translation to simulate snow accumulation. Do you know of an alternative way of doing something along these lines?

Footkick72 avatar Jan 15 '21 18:01 Footkick72

I never thought of ways to do this tbh. I thought making snow didnt require to add a separate mesh or even to heighten the areas. Depends if you are looking for a very precise look and behavior. If you use a big mesh like this, it's going to cause huge amounts of overdraw.

One way to do it would be to create a texture representing the amount of snow (or use one of the splatmap channels). You can modify that texture at runtime if needed (or even generate it with a viewport) and modify the terrain shader so that it raises the parts covered in snow based on that texture. It would add a small increment to the Y coordinate of each vertex, starting from a minimum density above which the ground would be covered in snow and would start accumulating higher. It can also be used in the fragment shader to fade textures to snow. It would not change collisions but it might be expected for snow. Usually when modifying height, normals would need to be adjusted, but if snow accumulates relatively uniformly and less on high slopes it might be all right. That's something I would try, I havent experimented yet with "sedimenting" like this :)

If you really need a separate mesh to have a real cut between the two, you could use a second terrain, maybe lower resolution, or indeed maybe a big mesh but it might not perform well if it's too big. Then do the same thing by adjusting height in the shader. Areas that aren't covered in snow would need to be discarded in the vertex shader or chunked to reduce overdraw. In fact, if you plan to use the mesh the plugin can make, you can obtain normals from the terrain's normalmap and assign NORMAL in the vertex shader (the terrain shader also uses meshes with only positions in them and nothing else). For UVs you don't need anything more than the XZ coordinates with a scale. You could almost even use the heightmap such that in the end you only need a subdivided planemesh, which is why I ended up saying that you could use another terrain^^ but you may decide what you think suits your need better I think.

Zylann avatar Jan 15 '21 18:01 Zylann