Advertisement

Additive Transparency

Started by March 25, 2000 12:12 PM
5 comments, last by +AA_970+ 24 years, 7 months ago
Does anyone know how i can implement additive transparency, not just averaging the color values, but the way games like half-life & quake 3 do it in explosions and the special effects. BTW, i''m not making a 3d game, i''ve only used half like and Q3 as examples because i''ve only seen this done in 3d games. This site has the definition of what i''m talking about: http://mondomed.com/mlabs/glossary.html#AdditiveC
What API are you using?

With DX7 you can do it like this:

SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE);
SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE);

This will add the texture color to screen color.
Advertisement
i'm using DX 7, but i want to know how to do this in 2d with direct draw, is there an equation or something?

Edited by - +AA_970+ on 3/25/00 2:25:27 PM
The formula is simply

ScreenColor = Min(ScreenColor + TextureColor, MaxColor);

Of course you'll have to do this for each channel, i.e. red, green and blue. And MaxColor depends on the mode you're in 255 for 32bit and 24bit, 31 for 16bit. (RGB565 has 64 levels for green)

DirectDraw can't do alphablending, yet, so you'll will have to do yourself by applying above formula to each pixel when blitting the bitmap to the screen.

Edited by - Spellbound on 3/25/00 4:19:13 PM
Thanks Alot!!!

Oh, are you sure there are 64 levels for green in 565, if i do:

__min(ScreenColor + TextureColor, 64);

white areas are replaced with pink?!

but when i change the 64 to a 63 everything works fine. Also the macro i have for converting the green channel of a color value to RGB is: ((green>>5)&0x3f). I found this a while ago in a post and the 0x3f converts to 63 in decimal.

Are you sure about the 64 or did i mess up somewhere?
Yes I''m sure, and no you didn''t mess up.

There are 64 levels, but 63 is the maximum level and 0 is the minimum level.
Advertisement
oh right silly me, i forgot that things on computers start counting at 0 and not 1. Well i''ll just says thanks again you really helped me out.

This topic is closed to new replies.

Advertisement