Zylann / godot_voxel

Voxel module for Godot Engine
MIT License
2.65k stars 249 forks source link

The transparent block behind the transparent square does not display correctly. #204

Closed KylaCpper closed 3 years ago

KylaCpper commented 3 years ago

The glass inside the demo is placed next to the leaves, and then through the glass you can see the back of the leaves, and the leaves become completely transparent.

And when the glass is translucent, for example alpha = 100 in a different view of what's behind the glass is different in color.

Zylann commented 3 years ago

This? image

Either it needs different configuration or there is something to tweak in the culling algorithm

when the glass is translucent, for example alpha = 100 in a different view of what's behind the glass is different in color

This isn't related to the module. Also if you litterally set a value of 100 it often makes colors go crazy because colors usually are in 0..1. Either way the change of color would be due to Godot's renderer.

Zylann commented 3 years ago

Might sound a bit unintuitive, but if you set leaves to be transparent = false, you get this result:

image

However it occludes log blocks behind them now, so I think I can introduce an extra comparison to give a bit more control over occlusion. The idea is instead of having a transparent boolean, have a transparency_index. If two neighboring blocks occluding a face on each other have the same index, the faces will be culled. But if one has a different index, the face won't be culled.

Zylann commented 3 years ago

Using == made lots of faces appear and clip with each other, it was messy. So I settled on a variant of this using >: Instead of transparency, voxels have a transparency_index. If two voxels should occlude a face they have in common, the face with the lowest transparency_index is culled. If both voxels have the same transparency index, both faces are culled.

This gives the following result: image

Here solid blocks have 0, leaves have 1, and glass has 2.

I removed transparent from the inspector, but I left it in the API to keep compatibility. It will get removed eventually. If old voxels have transparent set to true and their transparency_index is 0, it will be set to 1, and 0 otherwise.

The demo will need to be updated to account for that.

KylaCpper commented 3 years ago

perfect