PDA

View Full Version : How can I efficiently render textures with translucency?



inlinevoid
10-20-2013, 06:16 PM
Let's say I have 200 different textures that all have the possibility of having translucent pixels in them and I wanted to draw 1000 textures on screen. The way I understand this is: in order for blending to work the textures all need to be sorted and rendered from back-to-front in draw order. Performance-wise, it's smartest to batch all of the quads that have a texture mapped to them into 1 draw call. The problem I'm having trouble solving is how do you draw all of these textures front-to-back while still batching them together to minimize on draw calls?

With no texture sorting, I'd end up having to make 1000 draw calls, 1 per texture.

With texture sorting, I'd only have 200 draw calls but my blending would be all screwed up.

So what's the solution here? The only possible thing I can thing of is packing all my textures into a few different texture atlases and hoping some high-level draw calls don't happen to draw textures from two different atlases repeatedly (because then it'd have to switch atlases every time).

Dark Photon
10-22-2013, 05:09 AM
Let's say I have 200 different textures that all have the possibility of having translucent pixels in them and I wanted to draw 1000 textures on screen. The way I understand this is: in order for blending to work the textures all need to be sorted and rendered from back-to-front in draw order.

In theory, yes. In practice, maybe not. It depends on your needs. For instance, see this 5 year old presentation:

* Order Independent Transparency (http://www.slideshare.net/acbess/order-independent-transparency-presentation) (Rigazzi)

In particular, notice Weighted Average Transparency. Others on the boards actually pointed this technique out a while back.


Performance-wise, it's smartest to batch all of the quads that have a texture mapped to them into 1 draw call. The problem I'm having trouble solving is how do you draw all of these textures front-to-back while still batching them together to minimize on draw calls?

Consider techniques which don't require you to sort at the draw call level. Either they don't require sorting (like Weighted Average) or they subsume the sorting in an efficient way (e.g. A-buffer with fragment linked lists, etc.). Note that I'm not talking depth peeling here since you seem to care about performance.