Blending 3D Meshes

The default render script uses depth testing for meshes, but not for sprites. This makes sense because mesh vertices are not sorted by their z value in the engine, therefore requiring the depth buffer. Sprite vertices are sorted by their z value in the engine, therefore not requiring the depth buffer.

Blending is the main problem with this approach. The default render script enables blending for sprites, but disables it for meshes. The reason for this is that you must draw vertices from back to front for blending to work properly, which is how sprite vertices are treated. Unfortunately, mesh vertices are not sorted, so I don’t see any way to render partially transparent meshes.

How should this problem be solved? If I’m wrong about mesh vertices not being sorted, then please let me know, but that’s what it looks like based on how the render script is written.

I think the issue at hand here is that there should be some way to specify if mesh vertices that are part of a certain predicate should be sorted. This way, partially transparent meshes could be assigned to separate materials than fully opaque or fully transparent meshes.

that’s not quite correctly, sprites are sorted by only one point, by pivot, not by individual vertices.

you should separate materials and predicates for meshes with transparency and for solid fill meshes. And draw the predicate for solid meshes first, then for transparent meshes. Of course with the depth buffer on.

1 Like