Is it possible to achieve MAX(As,Ad) openGL blending?

Posted by Jeff B on Stack Overflow See other posts from Stack Overflow or by Jeff B
Published on 2010-01-27T00:12:59Z Indexed on 2011/11/17 1:51 UTC
Read the original article Hit count: 184

I am working on a game where I want to create shadows under a series of sprites on a grid. The shadows are larger than the sprites themselves and the sprites are animated (i.e. move and rotate).

I cannot simply render them into the sprite png, or the shadows will overlap adjacent sprites.

I also cannot simply put shadows on a lower layer by themselves, because when they overlap, they will create dark bands at their intersection.

These sprites are animated, so it is not feasible to render these en masse.

Basically, I want the sprites' shadows to blend together such that they max out at a set opacity. Example:

alt text

I believe this is equivalent to an openGL blending of (Rs,Gs,Bs,Max(As,Ds)), where I don't really care about R,G, and B, as it will always be the same color in src and dst.

However, this is not a valid openGL blending mode. Is there an easy way to accomplish this, especially in cocos2d-iphone?

I would be able to approximate this by making the shadow sprites opaque, then applying them both to a parent sprite, and making the parent sprite 40% opacity. However, the way cocos2d works, this only sets the opacity of each child to 40%, rather than the combined sprite image, which results in the same stripe.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about opengl