Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

dr_slash_uh

Alpha Transparency

This topic is 5420 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I cannot figure out how to do alpha transpareny ona png file. I am trying to get the transparency cloudlike effect. Help would be greatly appreciated Thanks Robert

Share this post


Link to post
Share on other sites
Advertisement
to be more specific, I know how to add 1 alpha value to my pnf picture in paintshop pro but I cannot figure out how to get opacity like a stain glass windows or something similiar. Help would be greatly appreciated.

Robert

Share this post


Link to post
Share on other sites
Assuming D3D (DDraw doesn''t do alpha transparency, you have to do it yourself).


// Enable alpha blending

pDev->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
// Set to be newcolor*alpha + oldcolor*(1-alpha)

pDev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pDev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);


To get things to blend correctly, draw all solid things first. Then draw each semi-transparent object back to front (the math only works out when drawing in this order).

You can also do additive blending by changing the DESTBLEND to D3DBLEND_ONE. (newcolor*alpha + oldcolor*1) Using this method you don''t have to draw back to front, since you''re just adding to the existing value.

You''ll want to ensure the texture alpha is used. Here I mix the texture''s alpha with that of the material (or vertex diffuse alpha)

// color = texture * diffuse (vertex or lighting)

pDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
pDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pDev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
// alpha = texture * diffuse (vertex or material)

pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);

// Terminate texture stages

pDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pDev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);


When you''re done, remember to turn alpha blending back off.

Share this post


Link to post
Share on other sites
I already have direct3d setup to do that. I download png format picture to verify it. I just can't create my own.

Robert

[edited by - dr_slash_uh on January 12, 2004 11:27:49 PM]

Share this post


Link to post
Share on other sites
So you don''t have a DirectX problem at all, you just don''t know how to use your paint package... Your question made it sound like it was the other way around. I haven''t used PSP in many years, so I can''t help. Why not try a forum for PSP? Or an artist''s forum? Or your manual?

Share this post


Link to post
Share on other sites
*laughs* why not just use a different graphic format. You can make an entire image (even a simple bmp) semi/completly transparent at once by modulating the color of the graphic with another color with alpha values. (I use DXSprite class usually)

Share this post


Link to post
Share on other sites
It probably depends on your system, with the game I'm currently working on I've been getting 200 frames per second when I don't lock the frame rate. It's definatly fast enough for my needs.


[edited by - ShadowP13 on January 13, 2004 1:19:09 AM]

Share this post


Link to post
Share on other sites
If I remember correctly, Paint Shop Pro doesn't fully support PNGs. Most importantly, it doesn't fully support the transparency. So when you create an image and save it, it'll just ignore transparency. I know this is true for PSP 7, I don't know what newer versions there are and how they work, though. I believe Photoshop was one of the few programs that fully supported PNGs when I last checked. On the PNG webpage there should be an extensive list of what programs support PNGs, and to what extent, if you're interested.

What I've done sometimes to get transparency like you want is to use two textures, the second one being a simple grayscale mask that determines the transparency. Then D3D can be set up as such:


pDev->SetTexture(0, pTexture);
pDev->SetTexture(1, pTexture_Mask);

pDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
pDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pDev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

pDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
pDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTA_CURRENT);
pDev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
pDev->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

pDev->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
pDev->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);


I can't remember if there are any states I'm missing, but I wouldn't be surprised. Either way, that's the general idea. Although, now that I think about it, (there may be a better way to do this), but after loading the mask image, I had to lock it, and copy the color values to the alpha (I loaded the image into a D3DFMT_A8L8 format texture), and then unlock it; after that, it was ready to use.

On the other hand, within the start menu, the utilities menu for the DirectX SDK has a shortcut to a texture tool which allows you to import an image and a mask, and then save the image with transparency (from the mask) to a single file (specific to DirectX, though). That might actually be the easiest way to go.

Either way, best of luck.

[edited by - Agony on January 13, 2004 10:42:20 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!