Alpha Blending + State changes

Started by
3 comments, last by GameDev.net 17 years, 6 months ago
I'm having trouble considering an efficient way to draw my gui with alpha blending. Each gui component requires multiple state changes to draw. If I wasn't using transparency I could batch the different states together and vastly reduce the umber of state changes. However, because I'm using alpha blending I have to draw the gui components in order, so I can't batch the different states together. Is there a solution to this problem or will I just have to live with it?
Advertisement
It depends. Using transparency correctly requires sorting, so that bundling states becomes second priority.

Perhaps transparency means masking (i.e. either totally transparent or totally opaque on a per texel basis) in your case, then you need not to sort but can use the depth test and alpha test. That may introduce little artifacts if texels are not mapped 1:1 to pixels (i.e. texture interpolation takes place).
Well, as haegarr mentioned, when rendering primitives in a certain order, other groupings (by state, in this case) take less priority, *but* that doesn't mean you can't do any grouping. Though not a very trivial problem to solve, you can still group by state when rendering ordered primitives, but you'll have to accept the fact that in the worst case, no grouping can be done and then that's lots of extra state changes. On the other hand, in the best case, you can get the same grouping as if you *weren't* taking into account the order of the primitives in the first place.

Anyway, I'm currently finishing my solution for this on my renderer and it seems to be going quite well. If you want, we can take this discussion further, feel free to ask.


[]s,
M.
I see there could be potential for grouping by state for objects that don't overlap at all, so the z-order grouping doesn't matter. I'll look into that approach. Thanks.
You should group all state changes (along with alpha) together, to form something like a shader; this way, each object you draw into the scene will have its own set of render states.

Also, many objects may share the same set of properties, so you can group them together... You will get amazing results [smile]

This topic is closed to new replies.

Advertisement