简体   繁体   中英

Cumulative alpha blending

Does anyone know what settings to use for glBlendFunc to achieve cumulative blending?

For example:

  1. 50% alpha + 50% alpha = 50% alpha
  2. 50% alpha + 40% alpha = 50% alpha
  3. 50% alpha + 60% alpha = 60% alpha

What I'm tryong to do is render multiple shapes, all of the same colour, but with different alpha values. Some shapes will overlap. I want each resulting pixel to be the equivalent of just rendering once with the largest alpha value.

I need to use vanilla GL10 so none of the min/max equation stuff is available.

I'm working on a couple of hotch-potch alternative solutions, one using depth and one using multi-pass rendering, but I have a gut feeling there's a neater way that I'm not seeing.

If you use a OpenGL 1.1. implementation, you can use the accumulation buffer.

The accumulation buffer accumulates different rendering passes, allowing you to mean each pixel color. Indeed, if you draw different shapes, the overlapping regions will cumulate color values of the overlapping shapes.

Fixed the number of rendering phases (say N ), a pixel which is owned by M shapes will have the color RGB * M / N; as I can understand, this is what you want to get.

See glAccum manual for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM