Jump to content
  • Advertisement
Sign in to follow this  

alpha render state Q for point sprites

This topic is 4739 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

lpDevice3D->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE ); That is the only alpha render state I set other than enabling it. Now I am very unfamiliar with how these states work. I am rendering a ton of point sprites and having them trail down the screen. It seems that any black in the texture I use is now transparent and whenever two point sprites overlap they get brighter. Well what I want is just the black transparent. I don't want two particles to overlap and get brighter since they are suppose to be solid. I think the texture I am using has had alpha value's set in it, but I'm not quite sure.

Share this post


Link to post
Share on other sites
Advertisement
Assuming your textures have proper alpha, this should work:

lpDevice3D->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
lpDevice3D->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
lpDevice3D->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );

These states cause the sprite color to be multiplied by its alpha, and the existing pixel on the screen to be multiplied by (1-spriteAlpha), and the two results added together.

Share this post


Link to post
Share on other sites
Unfortunetly that didn't work.
I can see the black square around each snow particle now.
My snow texture was found from a point sprite example so I'm not sure if the alpha value's are set.

So this leads me to conclude I have to fix up the alpha value's.

How do I go about modifying the alpha channel of a bmp?

Share this post


Link to post
Share on other sites
i suggest u use the following set, they work for me, for transparency and alpha, and getting the black of the texture.

device.SetRenderState(RenderStates.AlphaBlendEnable, true);
device.SetRenderState(RenderStates.SourceBlend, (int)Blend.SourceAlpha);
device.SetRenderState(RenderStates.DestinationBlend, (int)Blend.InvSourceAlpha);
device.SetRenderState(RenderStates.AlphaTestEnable, true);
device.SetRenderState(RenderStates.ReferenceAlpha, 0x08);
device.SetRenderState(RenderStates.AlphaFunction, (int)Compare.GreaterEqual);

they r in managed directx, but im sure u can map them back to unmanaged.

i presonally have problems with the alpha states. i dont quite get them till now.

Share this post


Link to post
Share on other sites
Still doesn't work.
The only one that has worked so far is BLEND_ONE, the states I posted in the first post.


I am very sure I need to modify the alpha channel of the bmp, but I do not know how. Well I could do it on the bit level but that would be annoying, there must be a program out there like PaintShopPro which can do it.

This is how it looks and it does not work:


//Disable zbuffer to help artifact fighting
lpDevice3D->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );


lpDevice3D->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
lpDevice3D->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
lpDevice3D->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
lpDevice3D->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
lpDevice3D->SetRenderState(D3DRS_ALPHAREF, 0x08);
lpDevice3D->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);

//Point sprite render states
lpDevice3D->SetRenderState( D3DRS_POINTSPRITEENABLE, TRUE );
lpDevice3D->SetRenderState( D3DRS_POINTSCALEENABLE, TRUE );

Share this post


Link to post
Share on other sites
If you only need to remove the solid black areas, you can pass a colour key to D3DXCreateTextureFromFileEx that specifies that black (0xFF000000) should be set to transparent.

You may end up with black fringes though if there are areas that are almost black, which is likely. In this case the easiest thing to do is edit the file in a pain program (Paintshop, photoshop, Gimp, etc) and save it in a format that supports alpha like PNG.

Share this post


Link to post
Share on other sites
D3DXCreateTextureFromFileEx (cringe) I cannot believe I forget there was an EX version of the function!

THANK YOU!

I hope this helps, I'll bump if it don't.

btw I like your sign off "Stay casual"

Thanks,
Halsafar

Share this post


Link to post
Share on other sites
Okay I set the color key and followed the render steps posted above.
Still a black square.
I use PsP9 and I made sure it is 0,0,0 black all around.

Share this post


Link to post
Share on other sites
With the color key you should use

lpDevice3D->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
lpDevice3D->SetRenderState(D3DRS_ALPHAREF, 0x08);
lpDevice3D->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);

if there's no gradient between opaque and transparent. This way things will even nicely stay z-sorted for you (no transparency problems).

Share this post


Link to post
Share on other sites
When using D3DXCreateTextureFromFileEx(), make sure that you specify an opaque color key value, otherwise it won't recognize color values without alpha as matching the specified color. For example, for a black color key, specify 0xff000000 (i.e. ARGB 255,0,0,0).

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!