Jump to content

  • Log In with Google      Sign In   
  • Create Account


DX11 render to texture issue...


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 Hawkblood   Members   -  Reputation: 723

Like
0Likes
Like

Posted 20 April 2014 - 12:27 PM

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:

 

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......



Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 13292

Like
0Likes
Like

Posted 20 April 2014 - 03:45 PM

What format is the texture?

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

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 Hawkblood   Members   -  Reputation: 723

Like
0Likes
Like

Posted 20 April 2014 - 06:58 PM

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.



#4 Hodgman   Moderators   -  Reputation: 29489

Like
0Likes
Like

Posted 20 April 2014 - 07:07 PM

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?

#5 Hawkblood   Members   -  Reputation: 723

Like
0Likes
Like

Posted 21 April 2014 - 10:11 AM

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.....



#6 Hodgman   Moderators   -  Reputation: 29489

Like
0Likes
Like

Posted 21 April 2014 - 10:09 PM

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?

#7 Hawkblood   Members   -  Reputation: 723

Like
0Likes
Like

Posted 22 April 2014 - 10:33 AM

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.



#8 Hodgman   Moderators   -  Reputation: 29489

Like
0Likes
Like

Posted 23 April 2014 - 05:14 PM

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.

#9 Hawkblood   Members   -  Reputation: 723

Like
0Likes
Like

Posted 24 April 2014 - 03:07 PM

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.



#10 L. Spiro   Crossbones+   -  Reputation: 13292

Like
0Likes
Like

Posted 24 April 2014 - 07:13 PM

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
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#11 Hawkblood   Members   -  Reputation: 723

Like
0Likes
Like

Posted 24 April 2014 - 07:25 PM

The issue started with the initial render texture, so all the other passes compounded the problem. I narrowed it down by displaying that first render texture as if it was the last "composite" texture. Let me say it another way: When I was trying to find the problem, I took out EVERYTHING except the first render texture and ONLY displayed it by rendering it as a sprite to the backbuffer.

 

Rendering the image as a sprite has no blending because the image has an alpha of 1.0...... Not to mention, the issue wasn't present in the rest of the image, just the quads that had the transparency. When I render all the objects(including the transparent ones) to a texture, blending occurs where appropriate. After that, the objects are no longer rendered-- it's just a texture that I apply to a quad.



#12 Hodgman   Moderators   -  Reputation: 29489

Like
0Likes
Like

Posted 24 April 2014 - 07:52 PM

took out EVERYTHING except the first render texture and ONLY displayed it by rendering it as a sprite to the backbuffer.
 
Rendering the image as a sprite has no blending because the image has an alpha of 1.0......

It won't have an alpha of 1 in each pixel if you've rendered objects who's alpha is less than 1 into it. You need to set a blend state with blending disabled.
What blend state is active when you render this sprite?

#13 Hawkblood   Members   -  Reputation: 723

Like
0Likes
Like

Posted 25 April 2014 - 01:36 PM

There is a solid object in the background (a plane) with a texture using alpha of 1.0f. The objects (with the transparency) are rendered on top and therefore each pixel they affect is "blended" according to the blend state. The final pixel may or may not have some transparency (due to the blend state). This is the whole reason I posted my problem. I don't know what blend states to use to make it work for both render methods and therefore I tried different ones until I could get two different ones to work-- one for each phase of rendering. All I am asking is "is there a single blend state method that will work for both RTT and render to back buffer?".....



#14 Hodgman   Moderators   -  Reputation: 29489

Like
1Likes
Like

Posted 27 April 2014 - 11:35 PM


All I am asking is "is there a single blend state method that will work for both RTT and render to back buffer?".....
Yes, there is no difference between the back buffer and RTT (every render-target works the same way), so your problem is elsewhere.

 

With back-buffer:

Set back-buffer as render-target

Set blend mode

Draw scene

 

With RTT:

Set texture as render-target

set blend mode

Draw scene

SET NEW BLEND STATE (ensure blending is disabled)

Set back-buffer as render-target

Draw quad using texture

 

With your RTT method, are you doing the bolded step?






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS