So I wanted to implement shadows in my D3D11 renderer. However, the Debug Layer gives me the warning
D3D11 WARNING: ID3D11DeviceContext::OMSetRenderTargets: Resource being set to OM DepthStencil is still bound on input! [ STATE_SETTING WARNING #9: DEVICE_OMSETRENDERTARGETS_HAZARD]
D3D11 WARNING: ID3D11DeviceContext::OMSetRenderTargets[AndUnorderedAccessViews]: Forcing PS shader resource slot 1 to NULL. [ STATE_SETTING WARNING #7: DEVICE_PSSETSHADERRESOURCES_HAZARD]
D3D11 WARNING: ID3D11DeviceContext::DrawIndexed: The Pixel Shader unit expects a Sampler to be set at Slot 1, but none is bound. This is perfectly valid, as a NULL Sampler maps to default Sampler state. However, the developer may not want to rely on the defaults. [ EXECUTION WARNING #352: DEVICE_DRAW_SAMPLER_NOT_SET]
D3D11 WARNING: ID3D11DeviceContext::DrawIndexed: The Pixel Shader unit expects a Sampler to be set at Slot 1, but none is bound. This is perfectly valid, as a NULL Sampler maps to default Sampler state. However, the developer may not want to rely on the defaults. [ EXECUTION WARNING #352: DEVICE_DRAW_SAMPLER_NOT_SET]
The relevant code is below :
void AppWindow::renderShadowMap()
{
//GraphicsEngine::get()->getRenderSystem()->getImmediateDeviceContext()->unbindSRV();
//CLEAR THE RENDER TARGET AND DEPTH STENCIL
GraphicsEngine::get()->getRenderSystem()->getImmediateDeviceContext()->clearRenderTargetColor(shadow_map_rtv, 1.0, 1.0f, 1.0f, 1);
GraphicsEngine::get()->getRenderSystem()->getImmediateDeviceContext()->clearDepthStencil(shadow_map_dsv);
GraphicsEngine::get()->getRenderSystem()->getImmediateDeviceContext()->SetRenderTarget(shadow_map_rtv, shadow_map_dsv);
//SET VIEWPORT OF RENDER TARGET IN WHICH WE HAVE TO DRAW
GraphicsEngine::get()->getRenderSystem()->getImmediateDeviceContext()->setViewportSize(1920, 1080);
lightViewMatrix = Matrix4x4::lookAt(Vector3D(2,2,0), Vector3D(0, 0, 0), Vector3D(0, 1, 0));
lightProjectionMatrix.setOrthoProj(20, 20, 1.0f, 10.0f);
lightSpaceMatrix = lightProjectionMatrix;
lightSpaceMatrix *= lightViewMatrix;
updateModel(Vector3D(0, 0, 0), MAT_shadow_map);
SM_mesh->drawMesh(MAT_shadow_map);
updateModel(Vector3D(0, -0.5f, 0), MAT_shadow_map);
SM_plane->drawMesh(MAT_shadow_map);
SM_sky_mesh->drawMesh(MAT_shadow_map);
//GraphicsEngine::get()->getRenderSystem()->getImmediateDeviceContext()->SetRenderTarget(NULL, NULL);
}
void AppWindow::render()
{
//CLEAR THE RENDER TARGET
GraphicsEngine::get()->getRenderSystem()->getImmediateDeviceContext()->clearRenderTargetColor(this->m_swap_chain, 0.3f, 0.4f, 0.5f, 1);
//SET VIEWPORT OF RENDER TARGET IN WHICH WE HAVE TO DRAW
RECT rc = this->getClientWindowRect();
GraphicsEngine::get()->getRenderSystem()->getImmediateDeviceContext()->setViewportSize(rc.right - rc.left, rc.bottom - rc.top);
update();
updateModel(Vector3D(0, 0, 0), MAT_mesh);
SM_mesh->drawMesh(MAT_mesh);
updateModel(Vector3D(0, -0.5f, 0), MAT_mesh);
SM_plane->drawMesh(MAT_mesh);
SM_sky_mesh->drawMesh(MAT_sky);
m_swap_chain->present(true);
oldDelta = newDelta;
newDelta = ::GetTickCount();
deltaTime = (oldDelta) ? ((newDelta - oldDelta) / 1000.0f) : 0.0f;
time += deltaTime;
GraphicsEngine::get()->getRenderSystem()->getImmediateDeviceContext()->unbindSRV();
}
void DeviceContext::unbindSRV()
{
ID3D11ShaderResourceView* nullSRV[1] = { nullptr };
m_device_context->PSSetShaderResources(0, 1, nullSRV);
}
I just need to know how and where do I unbind the shadow_map_rtv
and shadow_map_dsv
as that is what is causing the problem. Cannot find anything similar online.