• Advertisement
Sign in to follow this  

alpha blending

This topic is 3036 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 sure this is a very simple problem, but I haven't seen other articles or anyone running into it. I have one shader that I use to draw two lights on my model when it renders. Acting individually they work fine and produce the model as a opaque with properly lighting. When I render with one and then the other (without alpha blending). Only the second shader gets drawn. This makes sense. So I turn on alpha blending with the following states: graphics.GraphicsDevice.RenderState.AlphaBlendOperation = BlendFunction.Add; graphics.GraphicsDevice.RenderState.SourceBlend = Blend.One; // source rgb * source alpha graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.One; // dest rgb * (255 - source alpha) It draws both lights but for some reason my model becomes transparent! I even went into the shader and set the final resultant color's alpha to 1 and no luck. I've also tried using: graphics.GraphicsDevice.RenderState.AlphaTestEnable = true; graphics.GraphicsDevice.RenderState.SeparateAlphaBlendEnabled = true; No luck. Thanks for the help! I'm so close to getting lighting to work but it's these little qwerks that are getting in the way.

Share this post


Link to post
Share on other sites
Advertisement
Blend.One does not mean multiply by alpha. For that you need SourceAlpha and InverseSourceAlpha.

Perhaps this isn't your issue... but the comments in your code says (rgb * source alpha), which isn't correct, sorry if I misunderstand =)

Share this post


Link to post
Share on other sites
If I don't enable blending when I draw with the first light and then enable blending after drawing the first light it works.

I think what happens is the model gets drawn first with the first light, and the second light is rendered with some sort of alpha (unknown) to stack on top.

I don't want to have to disable alpha blending for the first light every time and the enable it after. This can be counter intuitive if I have an object being lit in different locations on the same map.

Share this post


Link to post
Share on other sites
You have to disable alpha blending when drawing it the first time. When drawing with One/One blending the light is just added on top of whatever is already there, as it is supposed to. If you want to cover what is behind, as you want with your first draw, you must disable blending.

Share this post


Link to post
Share on other sites
Thanks for the tip. After playing around for a while that's what I sort of concluded but I wasn't sure as to how I should draw it the first time.

In this case should I just use the standard mesh.Draw() function or define a global ambient light and use a shader to draw the mesh with only minimal ambience and then apply the other light shaders to it?

Share this post


Link to post
Share on other sites
Quote:
Original post by chibitotoro0_0
In this case should I just use the standard mesh.Draw() function or define a global ambient light and use a shader to draw the mesh with only minimal ambience and then apply the other light shaders to it?


Either way works. Some people have a single "ambient" pass that doesn't do blending but acts as a base for all of the dynamic lighting to build up on, or you can just have the first dynamic light not do blending have the ones after it blend.

Share this post


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

  • Advertisement