Sign in to follow this  

alpha blending in overlapping semi-transparent lines

This topic is 4015 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 using the Line class of Managed DirectX 1.1. I'd like to draw semi-transparent purple lines of width about 5. I'm drawing lines from a large data set and most of the place this works just great but sometimes the data causes lines to overlap. Where the lines overlap it effectively looks like the alpha channel for those "overlapped pixels" is 2X (or nX if there are 'n' overlapping lines). How can I keep it so that even where lines overlap the resultant transparency level remains constant? I have the following RenderStates set: Device.SetRenderState(RenderStates.SourceBlend, (int)Blend.SourceAlpha); Device.SetRenderState(RenderStates.DestinationBlend, (int)Blend.InvSourceAlpha); Device.SetRenderState(RenderStates.AlphaBlendEnable, true); Device.SetRenderState(RenderStates.ZEnable, false); Device.SetRenderState(RenderStates.ZBufferWriteEnable, true); In the screenshot below, to the right (labeled "good") is a single line appearing as i want all the purple lines to appear. The label "bad" is pointing to what appears to be two lines but is actually 3, two of which are perfectly overlapping. Here is a case where i would not want the overlap to appear as dark as it does but instead want for it to appear as in the label "good".

Share this post


Link to post
Share on other sites
A couple of ideas:

1. Render the lines into a render target, without alpha, then blend the entire render target.

2. Use stencil. This way you could mask the already drawn lines, and not draw again over them. Might also work with Z (which would be simpler).

Share this post


Link to post
Share on other sites

This topic is 4015 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.

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