# Blending 3D Meshes

**URL:** <https://forum.defold.com/t/blending-3d-meshes/75924>\
**Category:** General\
**Created:** [February 7, 2024, 12:35am UTC](https://forum.defold.com/t/blending-3d-meshes/75924 "2024-02-07T00:35:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![WhiteBoxDev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/whiteboxdev/32/36080_2.png) [@WhiteBoxDev](https://forum.defold.com/u/WhiteBoxDev)\
**Post date:** [February 7, 2024, 12:35am UTC](https://forum.defold.com/t/blending-3d-meshes/75924/1 "2024-02-07T00:35:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dragosha](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dragosha/32/5103_2.png) [@Dragosha](https://forum.defold.com/u/Dragosha)\
**Post date:** [February 7, 2024, 6:32am UTC](https://forum.defold.com/t/blending-3d-meshes/75924/2 "2024-02-07T06:32:09Z")

</div>

> [@WhiteBoxDev](#):
>
> Sprite vertices _are_ sorted by their z value in the engine, therefore not requiring the depth buffer.

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

> [@WhiteBoxDev](#):
>
> Unfortunately, mesh vertices are not sorted, so I don’t see any way to render partially transparent meshes

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.
