I am trying to implement deferred shading using MRTs. For that, I need to accumulate the color and the normals in two rendering targets. I defined two R32G32B32A32 textures for that end.
The pixel buffer outputs to both rendering targets. However, how do I instruct it to accumulate the values, rather than replace or blend them?
I tried defining the following blending state:
blendState.RenderTarget[0].BlendEnable = TRUE;
blendState.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
blendState.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
blendState.RenderTarget[0].DestBlend = D3D11_BLEND_ONE;
blendState.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
blendState.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendState.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
blendState.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blendState.RenderTarget[1].BlendEnable = TRUE;
blendState.RenderTarget[1].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
blendState.RenderTarget[1].SrcBlend = D3D11_BLEND_ONE;
blendState.RenderTarget[1].DestBlend = D3D11_BLEND_ONE;
blendState.RenderTarget[1].BlendOp = D3D11_BLEND_OP_ADD;
blendState.RenderTarget[1].SrcBlendAlpha = D3D11_BLEND_ONE;
blendState.RenderTarget[1].DestBlendAlpha = D3D11_BLEND_ONE;
blendState.RenderTarget[1].BlendOpAlpha = D3D11_BLEND_OP_ADD;
But the values I’m getting are weird.
Please help! How do I accumulate values?
To implement deferred shading you technically should not accumulate either normals or color, since when you will do the deferred processing (light calculations/occlusion/depth of field…), each MRT texture pixel(color/depth/normals), need to represent the closest object from the view point.
So only setting a depth state to read/write and comparison function to either less/lessequal, with no blend at all should be the way to go.