# Alpha Blending performance on IOS

I've got few questions without responses about my game development, can you help me? Here is the questions:

• In my game when a large object appear on the screen, the GPU go to his limits, my framerate become very slow. How can I handle that? (I'm working on mobile). ( Currently, I'm sorting object from back to front)

• I've read some stuff about batching (How to draw efficiently large number of objects with alpha blending?), how can I handle batching when my game need to draw my scene from back to front with alpha blending?

• What is faster: Add a condition to test pixel transparency in fragment shader or enable Alpha blending? (I've got colors around my sprites without alpha blending or condition)

Thanks!

• The best way to sort your scene is actually to do it in at least two stages/buckets. It is true that you need back-to-front sorting for translucent geometry for proper alpha-blending, but you want front-to-back sorting for best Z-buffer performance on opaque geometry. You can often get away with not bothering to sort opaque objects at all, leaving them unsorted should give better performance than sorting them back-to-front.

The whole point of batch processing is to identify geometry that is opaque or translucent, or that requires a certain texture, shader or state, and then before submitting the draw commands to the GPU you can cluster all of the similar geometry into batches. This way you only have to bother with depth sorting the hand full of batches that have a combination of states that actually require it, and you can sort in the proper direction.

• Alpha blending and alpha testing are actually two separate things.

1. Blending occurs after a fragment is shaded and when its result is combined with something else in the color buffer to produce a new blended pixel.

2. Alpha testing is used to determine whether a fragment should be kept or discarded.

• On newer hardware it can be done in a fragment shader, using discard
• On older versions of OpenGL and OpenGL ES, you have the option of using the fixed-function alpha test.

• As for which is faster, neither. Even if you perform an alpha test in a fragment shader at the very beginning of the shader and discard, the sad truth is that most of the time your fragment shader will keep on executing and it is only after execution that the GPU actually discards the results of shading.

If your program is limited by the performance of blending, rather than fragment shading, then alpha testing might help. This is because any fragment that is rejected after fragment shading does not have to be blended. Usually fragment shading is the bigger bottleneck, though.

If you are thinking that alpha blending and alpha testing are the same thing, then chances are you are actually just using an alpha mask. In which case, depth sorting is not always necessary and you do not need to use alpha blending. Alpha blending is used when you have fragments with alpha values that lie somewhere inbetween 0.0 and 1.0.

Also note that you are dealing with tile-deferred rendering on iOS, because Apple uses all PowerVR GPUs. The only geometry you should sort using the CPU is translucent geometry on PowerVR GPUs, otherwise you are defeating the purpose of TBDR (tile-based deferred rendering).

• So, sorting opaques front-to-back (in the hopes of leveraging depth-test culling) has no advantages in TBDR? I'm depth-sorting and splitting into opaque/translucent in one pass (for loop), so both buckets end up sorted back-to-front. – Nicolas Miari Oct 8 '17 at 8:03