Closed spiderworm closed 9 months ago
There is a built-in VoxelGeneratorFlat
for testing, which doesn't produce the same artifacts, but when setting height 9.5 there is one:
Note, it seems some exceptional logic gets hit when I use your generator: the buffer passed to the generator is not cubic, but you assumed it was so it throws tons of errors (which are sadly poorly reported for some reason Oo not sure what's going on with Godot's error system but half of the message is surgically cut off from the rest). That also makes Godot freeze because it can't handle many error messages, yay.
So basically: meshing requires voxel buffers that are slightly bigger than regular chunks, to include neighbor voxels on all sides. Therefore, meshing tasks are sent the block of voxels to mesh, and all its neighbors too for sides to be meshed properly. When meshing occurs near a border, it finds no block on one side. The current behavior when a block is not provided is to fallback on the generator to produce a thin layer of voxels, to complete the side of the buffer that will be passed to the mesher. Hence the non-cubic size. I'm not sure it should always do that, the behavior stems more from how VoxelLodTerrain
works, but technically it is correct.
I haven't figured yet the artifact though.
I fixed the error in your script and now I see no artifacts. Can you confirm?
@tool
extends VoxelGeneratorScript
func _get_used_channels_mask() -> int:
return (1 << VoxelBuffer.CHANNEL_SDF)
func _generate_block(buffer : VoxelBuffer, origin : Vector3i, lod : int) -> void:
# var block_size := int(buffer.get_size().x)
var block_size := buffer.get_size()
for xo in block_size.x:
var x = origin.x + xo
for yo in block_size.y:
var y = origin.y + yo
for zo in block_size.z:
var z = origin.z + zo
var v: float = clamp(y - 9.5, -1, 1)
buffer.set_voxel_f(v, xo, yo, zo, VoxelBuffer.CHANNEL_SDF)
Thank you for finding that, yes, I believe my error is fixed and I didn't fully understand how to correctly use the buffer.
Describe the bug I'm not sure how to technically describe this issue, but it seems that SDF terrains generated by the Transvoxel mesher have unwanted artifacts. These artifacts appear to happen at the edges of chunks.
To Reproduce Steps to reproduce the behavior:
VoxelGenerator
@tool
script with the following code for_generate_block
:Run Stream in Editor
is enabledTerrain > Regenerate
Expected behavior A flat terrain will generate without odd artifacts on the sides
Screenshots
Screencast from 02-20-2024 03:19:16 PM.webm
Environment