Zylann / godot_voxel

Voxel module for Godot Engine
MIT License
2.59k stars 244 forks source link

Voxel Generator Graph can support blocky terrains #286

Open KarloNet opened 3 years ago

KarloNet commented 3 years ago

Hi. If i just set in: void VoxelGeneratorGraph::generate_block(VoxelBlockRequest &input) channel as color (channel = VoxelBuffer::CHANNEL_COLOR;) and change: 433 out_buffer.fill_area_f(air_sdf, rmin, rmax, channel); -> out_buffer.fill_area(0, rmin, rmax, channel);

438 out_buffer.fill_area_f(matter_sdf, rmin, rmax, channel); -> out_buffer.fill_area(1, rmin, rmax, channel);

442 out_buffer.fill_area_f(sdf_range.min, rmin, rmax, channel); -> if(sdf_range.min < 0) out_buffer.fill_area(1, rmin, rmax, channel); else out_buffer.fill_area(0, rmin, rmax, channel);

488 out_buffer.set_voxel_f(sdf_scale sdf_buffer.data[i], rx, ry, rz, channel); -> float d = sdf_scale sdf_buffer.data[i]; if(d < 0) out_buffer.set_voxel(1, rx, ry, rz, channel);

I can use all function in graph generator in editor and they are working like expected (create sphere, torus, 2D and 3D noises ect). but all are just blocky. So mayby its not so bad idea to add it ( after some clean up in code) to plugin. One issue I found by now is that editing terrain not working ( cant destroy using rockets ). Wonder why but quick fix = some bugs xD

Zylann commented 3 years ago

I am aware that the graph generator could be made to support blocky terrain, however it is not as trivial as this. What you did here is only the matter vs air differenciation, this does not give any control on the type of voxels, or their colors. This would have to be something included in the graph, as a special output.

Another thing: because blocky terrains assume to not use LOD, they can use per-block generation techniques that the graph generator cannot do because it works only per-voxel. This would require to introduce a second pass of some sort, or a second graph with different kinds of operations.

KarloNet commented 3 years ago

I didnt look in sdf right now, but You are telling that i can have more control about textures using sdf and voxel graph? I didnt saw any function for it in graph or i'm wrong?

Zylann commented 3 years ago

The graph generator has special output types that allow you to generate weights for every texture index, assuming they sum up to 1. However this is only relevant for the transvoxel mesher. A graph meant to be used for blocky terrain may have slightly different outputs.

Zylann commented 2 years ago

The master branch now includes an OutputType node to allow generating into the TYPE channel instead of SDF, so it can be used with VoxelMesherBlocky b8e8ba84b0f25b49c8998326242a4a8ae8acb25e Note: the master branch uses Godot 4 now.