Sign in to follow this  
ankhd

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

Recommended Posts

[size="2"]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.

[/size][size="2"][code]

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

[/color][/size][/color][/size][size="2"]D3D10_BLEND_DESC blendDesc = {0};

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

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

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

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

[/color][/size][/color][/size][size="2"]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);

[/size]
[size="2"][/size][/code]


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.
[/size]

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 [b]MUST[/b] 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
[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 [b]MUST[/b] render them later than any objects that should be possibly visible through the transparent ones. That's given by how the blending works.
[/quote]

Usually that's right. But there are some techniques that allow you to render transparent and opaque objects in any order... [url="http://diaryofagraphicsprogrammer.blogspot.com/2009/11/order-independent-transparency.html"]Check it out[/url]

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='TiagoCosta' timestamp='1298470657' post='4777954']
[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 [b]MUST[/b] render them later than any objects that should be possibly visible through the transparent ones. That's given by how the blending works.
[/quote]

Usually that's right. But there are some techniques that allow you to render transparent and opaque objects in any order... [url="http://diaryofagraphicsprogrammer.blogspot.com/2009/11/order-independent-transparency.html"]Check it out[/url]
[/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

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