Sign in to follow this  
reallycoolme

Point sprites showing entire square

Recommended Posts

Hi, I'm using a particle engine, and everything is working perfectly except for one thing: The texture for the point sprites is being rendered as a square. What I want it to do is show the highlighted circle in the texture, and "ignore" the black background. I looked at many tutorials, and somehow they don't have this problem. I tried turning off fog, but that wasn't the problem. Could someone tell me how to stop it from displaying the black part(it is alphablending with the background, so I can see the square edges)?

Share this post


Link to post
Share on other sites
Alphablending needs to be turned on:

DEVICE->SetRenderState(D3DRS_ALPHABLENDINGENABLE, TRUE);
DEVICE->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ALPHA);
DEVICE->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);


And your image needs to have an alpha layer in it.

Share this post


Link to post
Share on other sites
reallycoolme,

It sounds like you've either got alpha blending turned off, there's no alpha channel in your texture, or your texture stages aren't set up quite right. You didnt say whether you're using OpenGL or DirectX, so I'll assume you're using DirectX. Make sure your texture stages are something similar to this:

m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

Which tells the shader to pull the alpha values from the texture's alpha channel. As for the alpha channel on the texture, make sure your texture and back buffer are a format which supports an alpha channel, such as A8R8G8B8 for 32 bit or A1R5G5B5 for 16 bit.

Cheers and good luck!

Share this post


Link to post
Share on other sites
Thx for the help...I'll try it when I get home. (Im at my parents work right now)
I think the problem is that the texture doesnt have an alpha channel because I did turn on alpha.

Share this post


Link to post
Share on other sites
Actually you will not use the alpha channel for this, but you need to enable alpha blending for it to work. What you need to do is to tell it to blend the black part of the texture with the background. So, this will only work if your background color (set in the IDirect3DDevice9::Clear() function) is black.

m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

m_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
m_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);

Share this post


Link to post
Share on other sites
You said that it will only work if the background is black....but my background has mountains (terrain) and fog in it, so I guess it will not work like that.
*more focused*
I made my picture have a transparent background..
perhaps another question should be: which file format should the texture be? .png? .gif doesnt work properly so I've not been using that.
.bmp doesnt have an alpha channel does it?

[Edited by - reallycoolme on April 29, 2006 4:51:36 PM]

Share this post


Link to post
Share on other sites
I think Targa's (TGA) and PNG's are common image formats that support alpha blending... Try those.
GIF's only allow transparency (no alpha blending).
As for BMP's, I'm not sure of any alpha channel, and I doubt it.

Share this post


Link to post
Share on other sites
I guess this directx question is soprt of turning into a painting question, but I'm saving my image (.png) with alpha, yet whenever i change the alpha, there is NO effect in the particle alpha. I know the particles are alphablending because when they overlap, they become brighter. is there something I have to do to read in alpha from the file?

Share this post


Link to post
Share on other sites
Seems like they are blending but not alpha blending. Additive blending would make particles brighter, but alpha blending shouldn't.

I'd suggest using alpha testing as an easy solution.

Share this post


Link to post
Share on other sites
I have used Photoshop to do this. You can start with your current .bmp image.

1) Save it as a .tga file;

2) Use the magic wand to select the black part and then do a select-inverse;

3) Save the selection as a channel to create the alpha channel.

That is an easy way. You can also play with the masking tools to create a feathered edge and make other adjustments.

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