Skip to content

Transparency#29

Open
Finding-Fortune wants to merge 3 commits into
cgerikj:masterfrom
Finding-Fortune:transparency
Open

Transparency#29
Finding-Fortune wants to merge 3 commits into
cgerikj:masterfrom
Finding-Fortune:transparency

Conversation

@Finding-Fortune
Copy link
Copy Markdown
Contributor

Add support for transparency, based off of https://github.com/Inspirateur/binary-greedy-meshing.
Add an example to showcase the transparency working, its the 2nd tab example (MESH_TYPE::TRANSPARENT_TERRAIN)

@MountainLabz
Copy link
Copy Markdown

Whats the speed like on this?

@Finding-Fortune
Copy link
Copy Markdown
Contributor Author

Finding-Fortune commented Jul 20, 2025

@MountainLabz Here's the perf from the Terrain test scene I added - its a duplicate of the old one, just with transparent blocks instead.

The transparent code will skip a column if no transparent bits are set and only check bits where the Transparent mask is set, so this scene is sort of a worst case scenario.

Non-transparent terrain:
1000 iterations took 131144us (131.144ms)
vertex count: 7201

Transparent terrain:
1000 iterations took 960640us (960.64ms)
vertex count: 11374
image

@MountainLabz
Copy link
Copy Markdown

Woah, thats quite the performance cost. Thats like 7x more time.

@Finding-Fortune
Copy link
Copy Markdown
Contributor Author

Finding-Fortune commented Jul 20, 2025

@MountainLabz The change in my commits works for Transparent Blocks against Transparent Blocks, but if you really need the perf you can do the change below for all the faces. Basically just repeat the same code as for the opaqueMask with a binary or for the transparentMask. With this method transparent blocks will render fine against opaque blocks, its just that the face will be culled between differing transparent blocks.

It should be pretty much as fast as the Opaque terrain if you use this method in exchange for the inaccuracy. The fix I have in the pull request takes a lot longer since you need to check the block IDs of all the neighboring transparent blocks to see if they are the same.

faceMasks[baIndex + 0 * CS_2] = ((columnBits & ~opaqueMask[aCS_P + CS_P + b]) >> 1) | ((columnBits & ~transparentMask[aCS_P + CS_P + b]);

@Finding-Fortune
Copy link
Copy Markdown
Contributor Author

Finding-Fortune commented Aug 9, 2025

There was a bug in the transparent meshing when a transparent block was up against an opaque block (before and after below in my engine), so added another commit. I had to add an extra check against the opaqueMask which slows down the code when a chunk is only liquid (performance stats for that below). However, it should be faster if the liquid is right next to opaque blocks since we don't need to check the voxels array.

To make this a lot faster, we should consider checking if an entire chunk is only transparent blocks so we don't need to check the opaqueMask array. We might want to also add a special check for if a chunk is entirely only 1 block type (whether opaque or transparent), so we can skip meshing - which would speed up the generation time of Oceans as an example which have many chunks that are transparent water only.

Non-transparent terrain:
1000 iterations took 125071us (125.071ms)
vertex count: 4301

Transparent terrain:
1000 iterations took 1298618us (1298.62ms)
vertex count: 11374
image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants