I am writing a bloom post processing shader at the moment, and I got a problem.
DirectX sets my textures views to NULL, because it thinks that they are bound as output already. But that is not true (Or it is?)!
Here is my code:
void PP_EngineEffect::OnRender(Mesh* PlaneMesh)
{
//RenderQuad(PlaneMesh,SimpleShader);
if(!PongTex || !PingTex)
{
return; //Those textures didn't get created
}
//------------------------
//Begin rendering the bloom. I use 2 textures (Ping and pong) to switch between them
//for doing such things like downscaleing and blurring.
//------------------------
//Downscale the rendertarget and apply brightpass
SetRenderTexture(PingTex->RenderTargetView); //Set the new backbuffer
BrightPass->SetBackBufferVar(NULL); //Set the texture, where the world is rendered to, to the shader (NULL uses the default backbuffer)
RenderQuadSized(PlaneMesh,BrightPass,0.25,0.25, 0.25,0.25); //Draw quad at size 0.25,0.25 and set the scissoring rect to 0.25,0.25 as well
//horizontaly blur the rendertarget
SetRenderTexture(PongTex->RenderTargetView);
HBlur->SetBackBufferVar(PingTex->ShaderResView);
RenderQuadSized(PlaneMesh,HBlur,1,1, 0.25,0.25);
HBlur->SetBackBufferVar(NULL);
//Verticaly blur the rendertarget
SetRenderTexture(PingTex->RenderTargetView);
VBlur->SetBackBufferVar(PongTex->ShaderResView);
RenderQuadSized(PlaneMesh,VBlur,1,1, 0.25,0.25);
VBlur->SetBackBufferVar(NULL);
//Upscale the blur
SetRenderTexture(PongTex->RenderTargetView);
SimpleShader->SetBackBufferVar(PingTex->ShaderResView);
RenderQuadSized(PlaneMesh,SimpleShader,4,4, 1,1);
SimpleShader->SetBackBufferVar(NULL);
//Apply the blooming to the rendertarget
SetRenderTexture(PingTex->RenderTargetView);
Combiner->SetBackBufferVar(NULL); //Original scene
if(Combiner->CustomTextureVariable)
{
Combiner->CustomTextureVariable->SetResource(PongTex->ShaderResView); //Blurred and brightpassed scene
}
RenderQuadSized(PlaneMesh,Combiner,1,1, 1,1);
if(Combiner->CustomTextureVariable)
{
Combiner->CustomTextureVariable->SetResource(NULL); //Need to NULL (default backbuffer) this (Do I?)
}
Combiner->SetBackBufferVar(NULL);
//And at least, copy the scene back to the backbuffer
SetRenderTexture(StartRenderTarget);
SimpleShader->SetBackBufferVar(PingTex->ShaderResView); //Original scene
RenderQuadSized(PlaneMesh,SimpleShader,1,1, 1,1);
SimpleShader->SetBackBufferVar(NULL);
}
The CustomTextureVariable of the Combiner-shader is a special variable for coders to do something with it, without hurting the users freedom of using other textures.
SetRenderTexture() sets the current backbuffer
And here is what directX says:
D3D10: WARNING: ID3D10Device::OMSetRenderTargets: Resource being set to OM RenderTarget slot 0 is still bound on input! [ STATE_SETTING WARNING #9: DEVICE_OMSETRENDERTARGETS_HAZARD ]
D3D10: WARNING: ID3D10Device::OMSetRenderTargets: Forcing PS shader resource slot 0 to NULL. [ STATE_SETTING WARNING #7: DEVICE_PSSETSHADERRESOURCES_HAZARD ]
These warnings cause that the whole downscale/blurring/etc stuff doesn't run. (It works, I tested it in a simple test)
So, how to fix it=