Jump to content
  • Advertisement
Sign in to follow this  

DX11 DX11 - Post Processing

This topic is 2129 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys. wink.png


So right now I'm having a problem with some post processing, optimizing and improving it, though, one issue that came up was somewhat like this:


So I basically have some preset post processing effects, like Bloom, God rays, etc.. All integrated into one shader. I decided to make the user able to create his own post processing effects, works great for now, but, an issue pups up. When the user does the post processing, he'd like to get the current output (The colors that were present before this effect, so, the backbuffer), but, as this user defined effect already writes to the backbuffer, it gets a bit tricky.


How could I approach this issue?

Is it even possible to write and read from the same buffer?

Can I somehow create a copy of the backbuffer?

Could I unbind the backbuffer just before the effect, send the backbuffer, capture the result of the effect, rebind the backbuffer, blend it in?


Thanks, as always. happy.png


Share this post

Link to post
Share on other sites
You'll need two render targets that you bounce back and forth between. Start with rtA which is where you rendered your scene prior to post processing, then bind rtA as a texture and render the post processing to rtB. Then at the next post process stage bind rtB as a texture and render to rtA. And back and forth, like so.

It takes a bit more memory, but you have to do it because you can't bind a buffer as a shader resource and a render target at the same time.

Share this post

Link to post
Share on other sites

Thank you for your input Samith! smile.png


I do seem to have a small problem here, things work fine, but, there's one thing that I do not quite understand. The situation:


How i loop over all the post processing materials: (Optimizations are not the goal) [Not actual code]

loop over materials

    RenderPostProcess(RTA); // Send RTA (render target) to the shader



Everything's working fine! But, it seems like that when doing RenderRTToScreen(RTB) (Not actual functions), the output is multiplied by 2 or something, it's much brighter than the input:


Input send to shader (From Visual Graphics Debugger, start index at 0):



Output from the shader(From Visual Graphics Debugger):



The shader:

Texture2D t_dff : register(t0);
SamplerState ss;

struct VS_Output
	float4 Pos : SV_POSITION;              
	float2 Tex : TEXCOORD0;

VS_Output VShader(uint id : SV_VertexID)
	VS_Output Output;

	Output.Tex = float2((id << 1) & 2, id & 2);
	Output.Pos = float4(Output.Tex * float2(2,-2) + float2(-1,1), 0, 1);

	return Output;

float4 PShader(VS_Output input) : SV_TARGET
	return t_dff.Sample(ss, input.Tex);

The blend state that I'm using it:

D3D11_BLEND_DESC post = {0};
post.AlphaToCoverageEnable = true;
post.IndependentBlendEnable = false; // true

post.RenderTarget[0].BlendEnable = true;
post.RenderTarget[0].SrcBlend       = D3D11_BLEND_SRC_ALPHA;
post.RenderTarget[0].DestBlend      = D3D11_BLEND_INV_SRC_ALPHA;
post.RenderTarget[0].BlendOp        = D3D11_BLEND_OP_ADD;
post.RenderTarget[0].SrcBlendAlpha  = D3D11_BLEND_ONE;
post.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
post.RenderTarget[0].BlendOpAlpha   = D3D11_BLEND_OP_ADD;
post.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;

dev->CreateBlendState(&post, &PostBS);

I hope that I've supplied you with enough information to help solving this issue smile.png .


Thanks, as always!


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!