DX11 render to texture issue...

Started by
12 comments, last by Hodgman 9 years, 11 months ago

I am rendering the scene to a texture in preparation for a bloom effect. The scene renders to the texture fine with the exception of objects with transparency. Here is a video illustrating the problem:

[media]http:

[/media]

I am toggling between render to texture and rendering to the back buffer. The back buffer rendering performs the transparency just fine, but the render to texture is not. It may not be apparent in the video, but the quads do have *some* alpha transparency with the RTT, but not fully...... There is a lot of code, so before I start flooding this post with code, I would like to know where to start......

Advertisement

What format is the texture?

How does the texture look in PIX/your debugger of choice?

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

So apparently there are some states that have different blending properties on the back buffer vs a RTT....


	blendStateDescription.RenderTarget[0].BlendEnable = TRUE;
	blendStateDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;//D3D11_BLEND_ONE;
	blendStateDescription.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;//D3D11_BLEND(int(tp1));//D3D11_BLEND_INV_SRC_ALPHA;

	blendStateDescription.RenderTarget[0].BlendOp = D3D11_BLEND_OP_MAX;
	blendStateDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
	blendStateDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
	blendStateDescription.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_MAX;
	blendStateDescription.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; //the same as 0x0f    (15)

This works fine for my point sprites using RTT.


	blendStateDescription.RenderTarget[0].BlendEnable = TRUE;
	blendStateDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;//D3D11_BLEND_ONE;
	blendStateDescription.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;//D3D11_BLEND_INV_SRC_ALPHA;
	blendStateDescription.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
	blendStateDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
	blendStateDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
	blendStateDescription.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
	blendStateDescription.RenderTarget[0].RenderTargetWriteMask = 0x0f;

This works fine for point sprites when not using RTT......

Don't know why, but that's how I got it to work.

Blend states do *not* operate differently with the backbuffer vs other render targets.

How are you presenting your texture to the screen? Did you leave blending enabled when you copied the texture to the backbuffer?

I don't think I explained it well. I RTT the entire scene including the objects with transparency in the exact same order as without RTT. If I only use the second blending state (above), it looks like the video-- when RTT, the blending doesn't show properly, and without RTT it show properly. If I only use the first blending state, RTT shows the transparency properly, but my solids blend when they are not supposed to. When I break up the rendering so that the solids use the first state and the transparent's use the second state everything works fine. If there is a *single* way of doing it, I can't figure it out-- please show me.....

After you've drawn your scene using RTT, you've got to do something to display it on the screen (e.g. Use a post processing shader to copy it to the backbuffer).
How do you do this step?

It's done as a sprite. I clear the backbuffer and then send the texture to a sprite function. This in turn modifies a quad and "renders" (as prep for shader) and then the a simple texture shader renders the quad with the texture applied. The whole DX11 render process is still a little fuzzy to me, but the problem is not actually in the post bloom shader function because I can take the original RTT and show it on the screen (without bloom) and the problem will still be there. So it must be something with the RTT itself.

without bloom:

-clear the back buffer and z-buffer(depth stencil)

-render the solids

-render the instanced billboards

-present the backbuffer(swap chain)

with bloom:

-set RTT as render target

-clear texture and z-buffer

-render solids

-render the instanced billboards

-do the bloom. This involves:

- H-blur, V-blur, and brightening. Each is a down-scaled RTT from the screen dimensions

- Up-scale image (same as screen dimensions)

- combine the up-scale and the original RTT for a final output texture

-set backbuffer as render target

-clear backbuffer and z-buffer

-render the bloom output image as a full-screen sprite(no transparency)

-present the back buffer(swap chain)

Even if I take out the "bloom" part of the process, the original image still has the problem (until I implemented the above solution).

If you know a single blend state solution to my problem, please show me.

It's done as a sprite. I clear the backbuffer and then send the texture to a sprite function. This in turn modifies a quad and "renders" (as prep for shader) and then the a simple texture shader renders the quad with the texture applied.

What blend state is active during this time? You can confirm with PIX or the visual studio graphics debugger.

I can take the original RTT and show it on the screen (without bloom) and the problem will still be there. So it must be something with the RTT itself,

or a problem with how you're showing it on the screen.

Correct me if I'm wrong. If I render the entire scene to a single image and then display that image on the back buffer (with NO transparency for that image), then any transparencies of objects that are rendered only on the RTT would be irrelevant to any rendering of that image.

If I render the entire scene to a single image and then display that image on the back buffer (with NO transparency for that image), then any transparencies of objects that are rendered only on the RTT would be irrelevant to any rendering of that image.

As stated, yes.

But in practice that depends.
Are you just fully copying the image directly over the back buffer or are you compositing it on top of the back buffer?
If we are talking about bloom, your last pass writes over the back buffer but performs the composite inside the last shader, taking some of the final image from the raw copy of the original image and blending the bloom on top of it.

Either way, no need to discard alpha. Always output a logical alpha and if it gets discarded later by copying over the back buffer, let it be.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement