Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Tunisia hawker   Members   -  Reputation: 160

Like
0Likes
Like

Posted 18 June 2012 - 12:12 AM

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.
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?problem.jpg

What I want that Illusion Particle does
ball3.jpg

Edited by Tunisia hawker, 18 June 2012 - 09:37 PM.


Sponsor:

#2 Tom KQT   Members   -  Reputation: 1589

Like
0Likes
Like

Posted 18 June 2012 - 07:28 AM

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.

#3 Tunisia hawker   Members   -  Reputation: 160

Like
0Likes
Like

Posted 18 June 2012 - 09:39 AM

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]

Edited by Tunisia hawker, 18 June 2012 - 09:40 AM.


#4 Tunisia hawker   Members   -  Reputation: 160

Like
0Likes
Like

Posted 18 June 2012 - 09:57 AM

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, 18 June 2012 - 06:49 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS