Jump to content
  • Advertisement
Sign in to follow this  
ibelchamber

Why isn't my alpha blending working?

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

I'm a directx starter, so apologies if this is a bit basic: I have a few objects drawn in 3d space. When I draw them, I do this: material.Diffuse = Color.FromArgb(128, R, G, B) Device3D.Material = material In my device setup I have this (I've tried many other things as well): Device3D.RenderState.AlphaBlendEnable = True Device3D.RenderState.AlphaSourceBlend = Blend.SourceAlpha Device3D.RenderState.AlphaDestinationBlend = Blend.InvSourceAlpha Device3D.RenderState.BlendOperation = BlendOperation.Add I expect that as I rotate my viewing position, and shapes overlap, I should see 1/2 of the front shape and 1/2 of what is behind it, but everything is still solid. What have I missed? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by ibelchamber
Device3D.RenderState.AlphaBlendEnable = True
Device3D.RenderState.AlphaSourceBlend = Blend.SourceAlpha
Device3D.RenderState.AlphaDestinationBlend = Blend.InvSourceAlpha
Device3D.RenderState.BlendOperation = BlendOperation.Add


replace:
Device3D.RenderState.AlphaSourceBlend = Blend.SourceAlpha
Device3D.RenderState.AlphaDestinationBlend = Blend.InvSourceAlpha

with:
Device3D.RenderState.SourceBlend = Blend.SourceAlpha
Device3D.RenderState.DestinationBlend = Blend.InvSourceAlpha

:)

Share this post


Link to post
Share on other sites
Thanks, there's definately some transparency going on now, but maybe I need something else- I can see shape A through shape B, but if I rotate my viewing position, I can't see shape B through shape A.

I have enabled the depth stencil with:
PresentParams.AutoDepthStencilFormat = DepthFormat.D24S8

and the objects appear in the right order from any angle, do I have to do something eles to get the transparency working correctly from all viewing positions?

Many thanks

Share this post


Link to post
Share on other sites
That could be a culling problem? Is it possible that maybe you can't see it because on looking from the opposite direction it isn't visible at all?

Share this post


Link to post
Share on other sites
Quote:
Original post by rjackets
That could be a culling problem? Is it possible that maybe you can't see it because on looking from the opposite direction it isn't visible at all?



No, I can see shape B, but not through shape A, it's like A is not transparent to B, but B is transparent to A

Thanks

Share this post


Link to post
Share on other sites
You also need to disable Z buffer, because if you draw closer triangle first, second one will fail depth test, and won`t be drawn at all...

Share this post


Link to post
Share on other sites
Many thanks for your help, but I'm a bit surprised- is it really the case that I have to work out the distances of all my meshes from the viewing point, and draw them in decreasing distance (just what I thought I had to do to get depth correct before I discovered depth stencils), to make transparency work correctly? What if I have meshes overlapping, so that part of mesh A is behind mesh B and part is in front? Is it really not possible to get transparency working correctly in this case?

Thanks.

Share this post


Link to post
Share on other sites
It's not perfect, but disabling z-writing before u render stuff with alpha values ussually looks pretty decent and saves u from sorting everything.

	m_pD3DDevice->GetRenderState(D3DRS_ZWRITEENABLE,  FALSE);


Matt Hughson

Share this post


Link to post
Share on other sites
Typically, games cheat. There are a lot of different methods and it depends what you're doing. The suggestion of disabling ZWrites can work well in some cases.

The only way to get transparent meshes to blend perfectly in arbitrary situations is to break them down and handle them 1 triangle at a time. Obviously this isn't feasible.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!