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

Started by
2 comments, last by aprilspirit89 11 years, 10 months ago
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]
Advertisement
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.

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.

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]
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.

This topic is closed to new replies.

Advertisement