I am in the middle of Deferred renderer implementation.
So this is my global view on the renderer.
Correct me please if I am doing something wrong.
So the renderer consists of 5 parts:
- Geometry pass: store normals, depth, color, specular, … into several GBuffer’s RT
- For each light, use simple light-type shader (ambient, directional, point, spot, …) to calculate light and store it in to Light Accumulator RT.
- Render this Accumulator RT into back buffer
- Use forward renderer to render transparent meshes (2 passes: with front and back culling). Probably I will use only subset of lights on this stage.
- Render some system objects like plate, origins, buttons, ...
CD3D11_RASTERIZER_DESC desc{ D3D11_DEFAULT };
desc.CullMode = D3D11_CULL_FRONT;
desc.MultisampleEnable = TRUE;
desc.DepthClipEnable = FALSE;
_check_hr(m_device->CreateRasterizerState(&desc, m_transpRastStateFront.GetAddressOf()));
SetDebugName(m_transpRastStateFront.Get(), "Res::Transp.Front Rasterizer");
//Back cull mode rasterizer
desc.CullMode = D3D11_CULL_BACK;
_check_hr(m_device->CreateRasterizerState(&desc, m_transpRastStateBack.GetAddressOf()));
SetDebugName(m_transpRastStateBack.Get(), "Res::Transp.Back Rasterizer");
Here are 3 additional questions:
1. Is there a way to render directly into back buffer without light accumulator?
Right now if I use following blend state, but the final color is blended with background color.
With default blend state, only last color is rendered into backbuffer.
//Add current color to already in the Render Target (without alpha change)
D3D11_BLEND_DESC desc{ 0 };
desc.RenderTarget[0].BlendEnable = TRUE;
desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
desc.RenderTarget[0].DestBlend = D3D11_BLEND_ONE;
desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO;
desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED | D3D11_COLOR_WRITE_ENABLE_GREEN | D3D11_COLOR_WRITE_ENABLE_BLUE;
_check_hr(MGL::DevicePtr()->CreateBlendState(&desc, m_omBlendState.GetAddressOf()));
MGL::SetDebugName(m_omBlendState.Get(), "Additive light merge");
2. Adding some AA to final image.
As I know, antialiasing with GBuffer is not a trivial task.
So for first implementation, is it possible to use AA only in phase 4 (forward rendering) and in phase 5 (HUD rendering)?
Swap chain will create back buffers with multisampling, but GBuffer will be created with no AA.
Is it possible?
Will I have AA for transparent and HUD stages?
3. 2-pass rendering for transparent objects.
I read that 2-pass with different culling modes for transparent objects rendering is the only way (if I want to see light transformations from back side of an object).
When I tried on phase 4 use D3D11_CULL_NONE, some triangles were rendered with artifacts.
Is it my fault or this should be by default?
The only difference between images: 2 passes with D3D11_CULL_FRONT and D3D11_CULL_BACK vs 1 pass with D3D11_CULL_NONE.
[attachment=30126:2passes.jpg] [attachment=30125:1pass.jpg]