Sign in to follow this  
matt77hias

Rendering artefact

Recommended Posts

Any idea what happend to the "glowing" pillar? The flowers on the pillar seem to alpha blend with my background instead of with the pillar.

const XMVECTORF32 background_color = { 0.0f, 0.117647058f, 0.149019608f, 1.000000000f };
m_device_context->ClearRenderTargetView(m_render_target_view.Get(), background_color);

If I change the background_color to red, the pillar flowers become red as well?

Edited by matt77hias

Share this post


Link to post
Share on other sites
  • What are you drawing first, the pillar or the flowers?
  • Are you using alpha-testing to avoid writing depth for transparent pixels?

Sounds to me like you're clearing, alpha blending the leaves and writing depth for transparent/translucent pixels, and then when you come to draw the pillar behind it it's failing the depth test again the transparent pixels.

Share this post


Link to post
Share on other sites
What are you drawing first, the pillar or the flowers?

I use the order of the group definitions in the .OBJ file.

 

Are you using alpha-testing to avoid writing depth for transparent pixels?
desc.RenderTarget[0].BlendEnable           = true;
desc.RenderTarget[0].SrcBlend              = D3D11_BLEND_ONE;
desc.RenderTarget[0].SrcBlendAlpha         = D3D11_BLEND_ONE;
desc.RenderTarget[0].DestBlend             = D3D11_BLEND_INV_SRC_ALPHA;
desc.RenderTarget[0].DestBlendAlpha        = D3D11_BLEND_INV_SRC_ALPHA;
desc.RenderTarget[0].BlendOp               = D3D11_BLEND_OP_ADD;
desc.RenderTarget[0].BlendOpAlpha          = D3D11_BLEND_OP_ADD;
desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
Edited by matt77hias

Share this post


Link to post
Share on other sites

If you're going to use alpha blending, then you need to draw transparent objects after all the opaque objects.

Alpha-testing is different to alpha-blending. Alpha testing involves "killing" a pixel in the shader (in D3D11) by using the 'clip' or 'discard' intrinsics. However, it sounds like you probably aren't using that.

Your blend state doesn't look correct for normal alpha blending either. You want:

result = srcAlpha * Src + (1-srcAlpha) * Dest.

You need to change your SrcBlend to D3D11_BLEND_SRC_ALPHA after you've made the change to draw transparent objects last.

Share this post


Link to post
Share on other sites
You need to change your SrcBlend to D3D11_BLEND_SRC_ALPHA after you've made the change to draw transparent objects last.

That's my additive blend state:

srcBlend: D3D11_BLEND_SRC_ALPHA
dstBlend: D3D11_BLEND_ONE

But currently, I only have one pass (didn't do anything special for alphas, except that I didn't want to go full opaque with a dstBlend of D3D11_BLEND_ZERO.

 

So to handle alpha correctly: I must first render with my current blend state and then set blend state to my additive blend state and render again?

Edit: What I said last, makes no sense in practice and gives very strange results. I will look further into this as I am not familiar with blending at all.

Edited by matt77hias

Share this post


Link to post
Share on other sites

Your Additive blend state looks fine (SrcBlend = SrcAlpha, DestBlend = 1.0).

Alpha blended objects can only blend onto something if that "something" has already been rendered. So yes, the objects onto which you want to blend must already be rendered.

This becomes difficult when you want to start blending alpha-blended objects onto other alpha-blended objects. As best you can you will want to render alpha blended objects from back to front so that the next alpha blended object draws on top of the ones behind it.

Order-independent transparency is still an active area of research in computer graphics and is difficult to solve.

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