Sign in to follow this  
ramy

Alpha blending error

Recommended Posts

Hello guys, ?I have been fiddling arround with lens flares, and actually implemented one. the lens flare requires an alpha blend so the black in texture to be removed, i understand that. the problem is, it also requires the skybox to have an alpha value so it appears through it, and i can c it when im inside the skybox. the problem is, then i enable alpha for skybox, it turns to bluish color, and terrain inside the akybox turns to lite greenish. here is a screenshot of this happening. not that i set the AlphablendEnable to false before rendering the Terrain. http://img37.echo.cx/my.php?image=alphaproblem9cb.jpg Anybody has an idea why Skybox turns to bluish, and Terrain as well :s thx in advanced.

Share this post


Link to post
Share on other sites
Quote:
Original post by ramy
the problem is, it also requires the skybox to have an alpha value so it appears through it, and i can c it when im inside the skybox.


not with additive blending (which is what you want in this case). You simply set the destination (sky) set to D3DBLEND_ONE, that is, leave it unchanged and simply add the lens flare color on top.

it's really hard to believe that you're setting the alpha blending to false before rendering the terrain. The only thing I can guess is that a huge green lens flare is covering the entire screen because it looks as if they turn from reddish to greenish as they descend.

Share this post


Link to post
Share on other sites
I would like to add the folowing information about the alpha i am using.

the lens flare i declare the following the Renderstates:

dev.SetRenderState(RenderStates.Lighting, false);
dev.SetRenderState(RenderStates.AlphaBlendEnable, true);
dev.SetRenderState(RenderStates.BlendOperation, (int)BlendOperation.Add);
dev.SetRenderState(RenderStates.SourceBlend, (int)Blend.One);
dev.SetRenderState(RenderStates.DestinationBlend, (int)Blend.One);
dev.SetRenderState(RenderStates.ShadeMode, (int)ShadeMode.Flat);
dev.SetRenderState(RenderStates.ZEnable, false);
dev.SetRenderState(RenderStates.ZBufferWriteEnable, false);

and after rendering them, i set AlphaBlendEnable to false.



then in the Skybox i do following:

dev.SetRenderState(RenderStates.AlphaBlendEnable, true);
dev.SetRenderState(RenderStates.SourceBlend, (int)Blend.SourceAlpha);
dev.SetRenderState(RenderStates.BlendOperationAlpha, (int)BlendOperation.Add);
dev.SetRenderState(RenderStates.DestinationBlend, (int)Blend.One);

and after rendering the skybox, i set AlphaBlendEnable to false.


then in Terrain rendering i disable the AlphaBlendEnable in Render states to false, before rendering and after rendering.

any clues?

Share this post


Link to post
Share on other sites
Quote:
Original post by ramy
then in Terrain rendering i disable the AlphaBlendEnable in Render states to false, before rendering and after rendering.


this is tedious. Drawing something will not suddenly enable blending, it is remembered until the d3d device is lost (ctrl alt del) or released.

Share this post


Link to post
Share on other sites
Almost there,

i render the skybox first, then render the lens flare, and i disbled the alpha blending before and after rendering the lens flare. the result was, Terrain had correct color, and Lens flare were turned to something else :p

http://img199.echo.cx/img199/3816/alphaproblem9nn.jpg

Share this post


Link to post
Share on other sites
I fixed the thing, thx alot for ur help Lee_.

i disabled Alpha for Terrain and Skybox, and rendered the lens flae the last, and it works fine now.

thx again

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