I'm currently trying to add post processing to an existing C++ DirectX11 application. The task is to apply a dynamic FX shader loaded from a file directly to the backbuffer, all rendering is already done before. In short: I have to get a copy of the backbuffer, apply some post processing effects and overwrite the buffer with those afterwards. "IDXGISwapChain->Present" is called at last.
This was pretty easy to achieve in DirectX9, however I'm running into multiple issues with DirectX11 now. I only found one example for post processing on D3D11 on MSN and it was written for a Windows 8 app, which I cannot build or run on my Windows 7 desktop and the code did not make a lot of sense to me.
The first one, a missing effects framework, could be solved by using "Effects 11" you can download from MSN already.
Now I'm a bit confused on how to continue. The basic idea on how it could work is as following:
- Load the effect from a ".fx" HLSL file and compile it using "D3DX11CompileEffectFromFile"
- Get a copy of the backbuffer using "IDXGISwapChain->GetBuffer" and save it to a "ID3D11Texture" object
- Get the description of the texture, to have width and height of the screen
- Create a new render target and tell the device to use it
- Create a fullscreen quad and draw the screen texture on it (using the loaded effect)
- Reset the render target and update the backbuffer with the drawn quad
The following code for step one and two already works:
I'm having problems with applying the effect and drawing the fullscreen quad though ...
The vertex struct and layout for the quad is declared as following:
The fullscreen quad is set up like this:
Drawing currently looks similar to the next code:
I'm clearing the render target to the color red before drawing the quad, but the screen is red then only, so sadly it doesn't seem to draw the quad at all...
I don't know if there is any way to check that.
Also, the a post processing shader normally requires me to pass the screen texture to it, so it can apply the effects on every pixel of it. The Effects Framework provides the "ID3DX11Effect->GetVariableByName" and allows one to set the variable to a specific object / data, but it has no definition for a texture. The nearest thing I found is "Variable->AsShaderResource()->SetResource(&MyResource)", but is that really the most efficient way, to create a shader resource for the screen texture to pass it to the pixel shader?
I'm sorry for the tons of code in this post, but I found it the easiest way to show what I got already. In DirectX9 the steps described earlier worked without any problems, but it wasn't required to create a vertex buffer here anyway, so the whole thing was shorter and easier to achieve.
I hope somebody has done something similar / post processing before in D3D11/D3D10 and can help me out here, I would really appreciate it.
Thank you and cheers,
Edited by Crosire, 18 April 2013 - 06:00 AM.