Jump to content
  • Advertisement
Sign in to follow this  
ankhd

Can DX10 BlendStates be set so i can render transparent meshes first

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

Hi all.

Is it possible to render the translucent mesh before rendering the terrain and still have the alpha blending.

I was rendering the terrain first then the meshes using this blend state here.



[color="#008000"][color="#008000"]//CREATE BLEND STATE

D3D10_BLEND_DESC blendDesc = {0};

blendDesc.AlphaToCoverageEnable = [color="#0000ff"][color="#0000ff"]false;

blendDesc.BlendEnable[0] = [color="#0000ff"][color="#0000ff"]true;

blendDesc.SrcBlend = D3D10_BLEND_SRC_ALPHA;[color="#008000"][color="#008000"]//D3D10_BLEND_BLEND_FACTOR;//

blendDesc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;[color="#008000"][color="#008000"]//D3D10_BLEND_BLEND_FACTOR;//

blendDesc.BlendOp = D3D10_BLEND_OP_ADD;

blendDesc.SrcBlendAlpha = D3D10_BLEND_ONE;

blendDesc.DestBlendAlpha = D3D10_BLEND_ZERO;

blendDesc.BlendOpAlpha = D3D10_BLEND_OP_ADD ;

blendDesc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;

hr = Device->CreateBlendState(&blendDesc, &mTransparentBS);





but now I need to render my objects first because I want to now render instancing and shadows within the same batch of instances so i dont need to
load the shaders buffers more then I need to.but when I do this I cant get the blending of the mesh with the terrain is there a way around this.

Or should I refactor my render manager to check for blending then just render shadow and move this object to render after the terrain.

Share this post


Link to post
Share on other sites
Advertisement
Hi.

I don't know DX10, but I bet this will be the same as in DX9. When rendering transparent objects, you MUST render them later than any objects that should be possibly visible through the transparent ones. That's given by how the blending works.
Let's say you have two objects, one is transparent and is in the front (objectA), the other one is partially behind it and it doesn't matter whether it is transparent or opaque (objectB), but let's presume it's opaque.

If you render objectB first, it will put properly its depth values in the Z-buffer and properly write all pixels without blending.
If you then render objectA, it will use the Z-buffer to realize that it should write the pixels (because objectA is in the front) and will blend objectA's pixels against those pixels already in the render target (the objectB's pixels). Result is that you will see objectB through objectA, as defined by the blend state.

If you render objectA first, it will put properly its depth values in the Z-buffer and properly write all pixels while blending against the current content of the render target - which (considering we have ONLY objectA and objectB) is the background color!
If you then render objectB, it will use the Z-buffer to realize that it should not write most pixels (because objectB is partially covered by objectA). Result is that you will see only the parts of objectB which are uncovered by objectA, and through objectA you'll see only the background color.

So, if you want to blend with something, it already needs to be rendered, becuase otherwise you don't have anything to blend with. Z-buffer will properly "organise" objects in space by their depth regardless their render order, but it cannot help with blending.

Share this post


Link to post
Share on other sites

Hi.

I don't know DX10, but I bet this will be the same as in DX9. When rendering transparent objects, you MUST render them later than any objects that should be possibly visible through the transparent ones. That's given by how the blending works.


Usually that's right. But there are some techniques that allow you to render transparent and opaque objects in any order... Check it out

Share this post


Link to post
Share on other sites
Thanks all.
I've read all the links and tha,t and I think for now I'll go with a render tranlucent list. It's for RTS style game should be ok.
Later all.

Share this post


Link to post
Share on other sites

[quote name='Tom KQT' timestamp='1298447718' post='4777873']
Hi.

I don't know DX10, but I bet this will be the same as in DX9. When rendering transparent objects, you MUST render them later than any objects that should be possibly visible through the transparent ones. That's given by how the blending works.


Usually that's right. But there are some techniques that allow you to render transparent and opaque objects in any order... Check it out
[/quote]

I didn't know that technique and it sounds interesting and certainly is useful, but after reading the article I think (if I understood it properly) that it doesn't go against what I said. It's just shifting the problem somewhere else; from having to sort object to having multiple buffers with layers.
You must render transparent objects after objects that are behing them if you're using one render target or you must render transparent objects in different depths into different render targets.

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!