Sign in to follow this  

RenderState question

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

Could someone please explain to me what D3DRS_SRCBLEND and D3DRS_DESTBLEND do and their relation to D3DRS_ALPHABLENDENABLE. I've searched the MSDN but they don't cover it in much detail and it seems like such a basic question that I can't find any details about it on the forum. Cheers

Share this post


Link to post
Share on other sites
with my limited understanding I know this: Their settings are required to turn on transparency in textures. typical usage in c#:

[source lang=c#]    
this.device.RenderState.SourceBlend = Blend.SourceAlpha; //set the source to be the source's alpha
this.device.RenderState.DestinationBlend = Blend.InvSourceAlpha; //set the destination to be the inverse of the source's alpha
this.device.RenderState.AlphaBlendEnable = true; //enable this.texture = TextureLoader.FromFile(device, "tex.bmp");

Share this post


Link to post
Share on other sites
Hi,

those parameters define how you will do alpha blending. Alpha blending is used to blend the color of a texture to what is currently on screen. For example, you draw the bottom of a lack with a sand texture, and then you render a semi-transparent water texture. The result of alpha blending allow you to see the sand throught the water texture.

Now, D3DRS_SRCBLEND tells the graphic card how to handle the input texture (in my example, the water texture) and D3DRS_DESTBLEND tells how to handle the pixels already on screen (the bottom of the lack which is already drawn on screen)

For example, is you use :

SetRenderstate(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
SetRenderstate(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

The resulting color will be : (input texture color) * (input texture alpha) + (screen pixel color) * (1 - input texture alpha)

The thing to remember : SRC is the current texture, and DEST is the pixel into which is drawn. So SRCALPHA is the alpha of the water texture, and INVSRCALPHA is the inverse of this value.

I hope this helps a little ^^

Share this post


Link to post
Share on other sites
Ahhh that makes a little more sense now. Does that mean though, that when I render the primary object (eg. a mirror) alpha blending doesn't need to be turned on as its not blending with anything when it is initially being drawn? I only need to turn on alpha blending when I am rendering the secondary objects (eg. anything reflected in the mirror). Or does it check to see if the primary object allows alpha blending?

Share this post


Link to post
Share on other sites
Alpha blending apply only to the object currently being drawn. After something has been drawn on the screen, it's just a bunch of pixels, with RGB color, alpha, and a depth (simply put ^^)

In my lake example, the bottom of the lake doesn't need alpha blending since it's not transparent. Only the water needs alpha blending to let the user see through it.

Notice that the order in which you draw things is important. In this case, you must draw the bottom of the lake before the water.

Share this post


Link to post
Share on other sites

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