Zylann / godot_voxel

Voxel module for Godot Engine
MIT License
2.51k stars 236 forks source link

How to attach custom vertex information in smooth terrain? #590

Open id05 opened 6 months ago

id05 commented 6 months ago

How to attach custom data to vertexes in transvoxel mesher? Color, for example...

I tried to figure it out myself, but I know C++ only on basic level

Zylann commented 6 months ago

You can't attach custom data to meshes without modifying the mesher in C++. Also, that data needs to come from somewhere, and usually it's voxel data (one of the channels, which should preferably use the smallest format as possible to save memory). An alternative is to play with shaders using procedural math and textures (for biome colors it can be enough), though it wont be editable as voxel data.

Custom data can be attached either during polygonization (somewhere inside regular mesh and transition mesh functions), or afterwards just before vertex data is converted to Godot's format. In addition, just "adding" the data from voxel data isn't always trivial depending on what you want to do, because vertices can be anywhere between voxel cells, and must account for attribute interpolation in shaders. For color, I suppose you could interpolate voxel colors around each vertex and add it to the COLOR attribute (currently unused).

Note 1, there is already support for texturing data, in case you were thinking of using color for that. Or you only want it to volumetrically tinting the meshes in addition to textures? (reminder that any voxel data you add is a significant amount of extra memory/bandwidth usage)

Note 2, transvoxel meshes are relatively heavy, so adding more data to meshes may impact rendering performance a bit (in addition to CPU work for attaching the data).

id05 commented 6 months ago

Yes, the idea was to tint the meshes, to make an appearance of big amount of different materials. I was reading #560 and I thought for a second, that to make same effect with colors and 16 textures would be more simple, then changing texturing logic

Zylann commented 6 months ago

If it's just a visual trick to fake diversity of textures, using voxels and adding extra mesh data is probably not a good idea. I would rather use a shader trick for doing this, like using a few layers of noise textures.