Game Development Reference
In-Depth Information
n Each node in the alpha list is rendered and then removed from the list.
n The old render states are restored to their old values.
void Scene::RenderAlphaPass()
{
D3DRendererAlphaPass11 alphaPass;
m_AlphaSceneNodes.sort();
while (!m_AlphaSceneNodes.empty())
{
AlphaSceneNodes::reverse_iterator i = m_AlphaSceneNodes.rbegin();
DXUTGetD3DDevice()->SetTransform(D3DTS_WORLD, &((*i)->m_Concat));
(*i)->m_pNode->VRender(this);
delete (*i);
m_AlphaSceneNodes.pop_back();
}
}
There is a special class, D3DRendererAlphaPass11 , that manages setting the
ID3D11DeviceContext for alpha blending. Upon construction the device settings
are set, and upon destruction the device is returned to the state it was previously in.
When you want to do an alpha pass in Direct3D 11, or actually any other kind of
blending, you define it with the D3D11_BLEND_DESC structure, create the blend
state by calling ID3D11Device::CreateBlendState() , and set the blend state
with a call to ID3D11DeviceContext::OMSetBlendState() . You can tell just
by looking at the blend state structure that blending is a large subject, one that is
best covered by a dedicated 3D graphics book. The parameters sent into the blend
state used here involve a simple alpha blend, using the source pixel
'
s alpha value.
class D3DRendererAlphaPass11
{
protected:
ID3D11BlendState* m_pOldBlendState;
FLOAT m_OldBlendFactor[ 4 ];
UINT m_OldSampleMask;
ID3D11BlendState* m_pCurrentBlendState;
public:
D3DRendererAlphaPass11();
~D3DRendererAlphaPass11();
};
D3DRendererAlphaPass11::D3DRendererAlphaPass11()
{
Search WWH ::




Custom Search