Are you looking to achieve partial transparency? If so, then that’s usually done by sorting 3D meshes from back to front, or farther to closer, relative to the camera.
I remember reading that Defold doesn’t auto-sort 3D objects within a batch like it does with 2D objects. For example, when drawing 100 sprite components in a single batch, Defold sorts them based on their distance from the camera, which is set by each component’s z value. The result of this sorting operation is that sprites that are closer to the camera are drawn last, and therefore show up “in front of” the sprites behind them.
In the above image, each box is a sprite with the corresponding z value. The greater the z value, the closer to the camera, and the last to be drawn to the screen. If Defold decided not to sort them, then you can imagine these sprites appearing above or below other sprites in a seemingly random way.
If objects are not automatically sorted in a batch, then a depth buffer can be used in the render script as an alternative method to achieve that sorted look. As far as I know, Defold doesn’t sort 3D objects, so this depth buffer solution must be used instead.
So, what does this have to do with partial transparency? Let’s take a look. The following image shows 3D objects that are drawn to the screen in a random order, but use a depth buffer to make sure the correct object appears in front.
Looks okay. The problem arises when we try to make the green cube, say, 50% transparent. We would expect to see the red cube behind it through some basic alpha blending, right? But that’s not what happens. Remember we’re using a depth buffer, so the red cube’s fragments that are behind the green cube are discarded. The result is that part of the red cube simply isn’t drawn, effectively canceling the green cube’s transparency.
If we attempt to hack around this by removing the depth buffer, then there’s no guarantee which object will be drawn on top of the other, which of course is unacceptable. Imagine standing on a road looking at the front of a house, but instead of seeing the walls and front door, you see some of the kitchen appliances, a person lying in a bedroom, and a tree in the backyard floating in front of the house!
(The reason for back-to-front sorting instead of front-to-back is because alpha blending samples whatever fragment color already exists at that location. If transparent objects are drawn before all of the opaque objects are finished drawing, then whichever opaque objects haven’t been drawn yet won’t blend with the transparent ones. This would be like looking through a window and half of the objects outside disappearing, while the other half appear as expected.)
Like I’ve mentioned, the usual solution is to sort 3D objects by their distance from the camera, similar to how it’s done with sprites. There are however some complications and corner cases that are likely game-dependent on how to deal with them, like when some of a rotating object’s vertices swap z closeness with another object. This might be one of the issues that make it less obvious how to implement this feature in a stable and satisfying way.
Another solution you might use is instead of using the depth buffer and discarding farther fragments, you could switch blend functions to additive or multiplicative instead of the usual alpha mode. This would lighten or darken overlapping objects instead of completely remove them, but that coloring effect is likely undesirable most of the time.
There are supposedly other solutions out there that don’t require back-to-front sorting, however I’ve never implemented them myself, so I’m not sure how difficult or computationally expensive they are. Feel free to research them if that’s something you find interesting. I’d really like to hear about what you find, and if it’s doable with what Defold offers at the moment.
Edit: Ah, I forgot to mention. This is all assuming these 3D objects are drawn within the same batch. If you dedicate draw calls specifically to partially transparent objects, and draw them after the opaque objects, then partial transparency will work, assuming a depth buffer and alpha blending are enabled. This requires a number of additional predicates, materials, etc.