• Advertisement
Sign in to follow this  

DirectX Texture Blending to create alpha

This topic is 1903 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'm trying to figure out how to take one image and use the black (or level or darkness) to create the alpha channel for another image. I'm not sure what the best way to do this is - I thought something like this might do it:
[source lang="cpp"]
Device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
Device->SetTextureStageState(0, D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

//first create the image that will later also be used as the alpha channel in the other image;
Device->SetRenderTarget(0,g_RenderSurface);
Device->BeginScene();
Device->Clear(0,NULL,D3DCLEAR_TARGET,0x00000000,1.0f,0);
g_sprite->Begin(D3DXSPRITE_ALPHABLEND);
DRAWC(g_sun_background.texture,NULL,&g_sun_background.pos1,color_intesity);
DRAWC(g_f_m_background.texture,NULL,&g_f_m_background.pos1,0xFF000000); //black silhoette to be used as alpha transparency;
DRAWC(g_f_m_background.texture,NULL,&g_f_m_background.pos2,0xFF000000); // ";
g_sprite->End();Device->EndScene();

//try to show the second image using the first image as an alpha channel;
Device->SetRenderTarget(0,g_BackBuffer);
Device->BeginScene();
Device->Clear(0,NULL,D3DCLEAR_TARGET,0x00000000,1.0f,0);
Device->SetTexture( 0, g_RenderTexture); //(uses the g_RenderSurface);
Device->SetTexture( 1, g_sunny_texture);
Device->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 ); //render final 2d image;
Device->EndScene();
Device->Present(NULL,NULL,NULL,NULL);
[/source]
I'm not sure if this is the best way to try to do this or if maybe I should learn to use a pixel shader or something? Any advice is welcome! (^__^)

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement