Sign in to follow this  
aprilspirit89

How to remove the black background of a .tga texture with alpha channel

Recommended Posts

aprilspirit89    160
Recently,I'm trying to save the scene during rendering to .tga texture with alpha channel.When I did it,the whole picture seems darker than the way it looks on screen.Then I realise I should remove the background color which is default black.
[attachment=9517:rgb.jpg]
It‘s the same with Particle Illusion Software when it saves the alpha and give a choice whether to remove BG color. Here's my code.
[source lang="cpp"]
if(S_OK == pRenderSurface->LockRect(&rect,NULL,D3DLOCK_NO_DIRTY_UPDATE))
{
DWORD* pColor = (DWORD*)rect.pBits;
for( int y = 0 ; y < height ; y++ )
for(int x = 0 ; x < width ; x++ )
{
D3DXCOLOR color = pColor[y*rect.Pitch/4+x];
if(color.a > 0)
{
color.r /= color.a;
color.g /= color.a;
color.b /= color.a;
}
pColor[y*rect.Pitch/4+x]=color;
}
pRenderSurface->UnlockRect();
}
D3DXSaveSurfaceToFile(texPath1,D3DXIFF_TGA,pRenderSurface,NULL,NULL);
[/source]

Now the problem is,the picture seems too light,and some details lost.I'm confused about the result.Did I do it in a wrong way?[attachment=9516:problem.jpg]

What I want that Illusion Particle does
[attachment=9531:ball3.jpg] Edited by Tunisia hawker

Share this post


Link to post
Share on other sites
aprilspirit89    160
[quote name='Tom KQT' timestamp='1340026114' post='4950236']
Hi,
it seems you lost part of your code during copy-paste. Line number 8 doesn't make sense and certainly wouldn't compile without errors.
[/quote]
Thank you for pointing out my mistake.It looks OK during edit state,but some charactor just failed to show up.I guess it's
[source lang="cpp"]color.a < 1[/source] Edited by Tunisia hawker

Share this post


Link to post
Share on other sites
aprilspirit89    160
I came to realise maybe I should calculate the origin color each time when the draw call happens and any pixel get modified.Is that right?I just used method above but the color becomes brighter.Color buffer seems to have an explosion.small colorful paricles far away from each other are just alright,they only be written once.While the pixel in the central part are influenced by several particle systems,totally a mess. Edited by Tunisia hawker

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this