Archived

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

Alpha

This topic is 6359 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

Hi, just a quick question. I want to make some clouds in my project, so I setup my texture to have a colorkey (so you can see through to the sky behind around the clouds) and now I want to add some alpha to my clouds (I wanna have transparent layers for clouds). What is the best way of doing this? In my initialization code, I entered the following commands. The SDK help tells you to eliminate Render State changes since it slows down. So I set this up during initialization time. screen.d3ddevice->SetRenderState( D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA); screen.d3ddevice->SetRenderState( D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA); screen.d3ddevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE); Now when I do my DrawPrimitive for my clouds, is there any RenderState change or TextureState change I need to do to make it alpha? Or is there more involved? The SDK hasn''t really helped. Is there a command like "SetTextureAlpha" where you enter a value between 0.0f, and 1.0f... The reason I''m asking is because Retained Mode handles Alpha in this way... You just setup an Alpha for each texture loaded and everything else is automatic.

Share this post


Link to post
Share on other sites
If there is no alpha channel attached to the texture, then direct3d will use the alpha value of the diffuse material for the clouds. Is that code working?

*** Triality ***

Share this post


Link to post
Share on other sites
No, my code isn''t doing anything right now. It acts like as it does with no alpha enabled.

You gave me a hints though about attach alpha channel to the texture and the material setting. So with just a little research, I should be able to do alpha with both of those. I will check it out.

Thanks!

Share this post


Link to post
Share on other sites
Hi again. I''ve tried all but adding an alpha surface. This is my latest code.

screen.d3ddevice->SetRenderState( D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
screen.d3ddevice->SetRenderState( D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);

screen.d3ddevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);

screen.d3ddevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTFN_LINEAR );
screen.d3ddevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTFG_LINEAR );
screen.d3ddevice->SetTextureStageState( 0, D3DTSS_MIPFILTER, D3DTFP_LINEAR );
screen.d3ddevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
screen.d3ddevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
screen.d3ddevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);



D3DCOLORVALUE rgb;
D3DCOLORVALUE rgb2;
rgb.r = 1;
rgb.g = 1;
rgb.b = 1;
rgb.a = 1.0f;
rgb2.r = 1.0f;
rgb2.g = 1.0f;
rgb2.b = 1.0f;
rgb2.a = 1.0f;
global.matground.diffuse = rgb2;
global.matground.ambient = rgb;
global.matground.specular = rgb;
global.matground.emissive = rgb;
global.matground.power = 1;

rgb.r = 1;
rgb.g = 1;
rgb.b = 1;
rgb.a = 0.1f;
rgb2.r = 0.1f;
rgb2.g = 0.1f;
rgb2.b = 0.1f;
rgb2.a = 0.1f;
global.matsky.diffuse = rgb2;
global.matsky.ambient = rgb;
global.matsky.specular = rgb;
global.matsky.emissive = rgb;
global.matsky.power = 0.1f;



When I render the clouds, I set the device to use the global.matsky, and when rendering the ground, I use global.matground.

This is giving me an overall 50% alpha. With the ground and with the sky... And none of the properties change the amount of alpha. I know it has something to do with the alphaop properties I listed below, can anybody give me better settings?


screen.d3ddevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
screen.d3ddevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
screen.d3ddevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);

Thanks in advance!

Share this post


Link to post
Share on other sites