Render targets with alpha

Started by
13 comments, last by RobM 11 years, 1 month ago
Thought I'd start a new topic on this one. I'm having an issue rendering my screen layers.

My first layer, the game scene, is rendered to the back buffer, my next scene, the HUD (which currently is just a bunch of text quads), is rendered to a render target. I then blend the HUD render target onto the back buffer with a very simple full screen quad shader.

The problem is that my HUD render target doesn't appear to be fully transparent in the areas where I haven't drawn text. When I Clear the render target I clear it with 0,0,0,0 which I thought would give me a fully transparent surface. I then render my text quads to that target.

When I blend, the HUD layer just appears to cover the back buffer surface completely. If I adjust the alpha component in the output of the simple blend pixel shader to something like 0.5 then I get half brightness on the background and half brightness on the HUD layer.

Is there some special blend mode parameters I need to set for rendering alpha to rendertargets?

My blending is:

BlendOp=ADD;
SrcBlend=SRCALPHA;
DestBlend=INVSRCALPHA;
AlphaBlendEnable=TRUE;

This shader is very simple, renders to the back buffer and just takes a sample from the HUD layer.
Advertisement

Are you drawing anything to your HUD other than text, or are you saying that the places where you have drawn absolutely *nothing* to your HUD rendertarget show up as opaque when you render the HUD to your back buffer?

The HUD only has a couple of lines of text, the rest of the area (which is 99% of it) should be transparent but is coming through as opaque.

If I manually set the alpha in the blend shader pixel shader return value to 0.5 it works, but obviously the areas of the HUD that haven't been drawn on should be alpha 0.
Do a single frame capture in pix, and check whether your HUD layer's alpha channel is really valid.

I assume your pixel shader is basically just 'return tex2d...'?

What texture formats are you using?
I saved the texture from pix (dds) and the opacity was 255 (full)...

Yes, just a very simple tex2d

Texture format for the render target is A8R8G8B8.

So I guess it means my clear is not clearing it to transparent...?

Are you clearing with D3DCOLOR_ARGB(0,0,0,0)?

Even D3DCOLOR_XRGB(0,0,0) should do (no warranty), just make sure its three zeros and not like 255.

Betting it's clear color too.

clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

Betting it's clear color too.

Should I not be clearing colour?

Are you clearing with D3DCOLOR_ARGB(0,0,0,0)?

Even D3DCOLOR_XRGB(0,0,0) should do (no warranty), just make sure its three zeros and not like 255.

Yes, definitely clearing with 4 zeros. I can't quite remember whether it's XRGB or ARGB (I'll check) but it's definitely 4 zeros.

Betting it's clear color too.

Should I not be clearing colour?

>Are you clearing with D3DCOLOR_ARGB(0,0,0,0)?

Even D3DCOLOR_XRGB(0,0,0) should do (no warranty), just make sure its three zeros and not like 255.

Yes, definitely clearing with 4 zeros. I can't quite remember whether it's XRGB or ARGB (I'll check) but it's definitely 4 zeros.

Not quite, I just suspect you're clearing it to an 'opaque' alpha value when you really want it to be cleared to a transparent one. You can try flipping the alpha to 1.0f/255u and seeing if that changes anything. Of course, all this is irrelevant if you're using an XRGB render target!

clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

Thats what my clear call is looking like:


m_lpDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 1.0f, 0);

What does yours look like? Did you make sure the texture is still bound to the device when clearing? Does this happen in release and debug mode? I remember having a very similar issue with alpha transparency, only in release mode, I try to find the thread (it's quite old), can't recall the solution anymore...

This topic is closed to new replies.

Advertisement