Game Development Reference
In-Depth Information
DXUTGetD3D11DeviceContext()->OMGetBlendState(&m_pOldBlendState,
m_OldBlendFactor, &m_OldSampleMask);
m_pCurrentBlendState = NULL;
D3D11_BLEND_DESC BlendState;
ZeroMemory(&BlendState, sizeof(D3D11_BLEND_DESC));
BlendState.AlphaToCoverageEnable = false;
BlendState.IndependentBlendEnable = false;
BlendState.RenderTarget[0].BlendEnable = TRUE;
BlendState.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
BlendState.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
BlendState.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
BlendState.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO;
BlendState.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
BlendState.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
BlendState.RenderTarget[0].RenderTargetWriteMask =
D3D11_COLOR_WRITE_ENABLE_ALL;
DXUTGetD3D11Device()->CreateBlendState(&BlendState, &m_pCurrentBlendState);
DXUTGetD3D11DeviceContext()->OMSetBlendState(m_pCurrentBlendState, 0,
0xffffffff);
}
If you set a material color to 75% red, 50% translucency, you set the values of the
Color structure to (0.75f, 0.0f, 0.0f, 0.5f). That
s 75% red, 0% for blue and green,
and 50% for alpha. This value makes its way into the pixel shader where it is blended
with lights, as you saw in the previous chapter. If the ID3D11DeviceContext has a
blending state set, then the pixel just calculated by the pixel shader is blended with
the pixel value already on in the display buffer. The types and methods of blending
are pretty mind boggling, actually, so when you learn about them, have some
patience. When the alpha pass is done, the destructor of the class simple restores
the previous blending state:
'
D3DRendererAlphaPass11::~D3DRendererAlphaPass11()
{
DXUTGetD3D11DeviceContext()->OMSetBlendState(m_pOldBlendState,
m_OldBlendFactor, m_OldSampleMask);
SAFE_RELEASE(m_pCurrentBlendState);
SAFE_RELEASE(m_pOldBlendState);
}
You will see this technique again for setting and restoring device context states for
the skybox, which comes a little later.
 
Search WWH ::




Custom Search