Game Development Reference
In-Depth Information
// - - - - - Material - - - - -
V( DXUTGetD3D11DeviceContext()->Map( m_pcbVSMaterial, 0,
D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ) );
ConstantBuffer_Material* pPSMaterial =
( ConstantBuffer_Material* )MappedResource.pData;
Color color = pNode->VGet()->GetMaterial().GetDiffuse();
pPSMaterial->m_vDiffuseObjectColor =
Vec4(color.r, color.g, color.b, color.a);
color = (m_enableLights) ?
pNode->VGet()->GetMaterial().GetAmbient() :
Color(1.0f, 1.0f, 1.0f, 1.0f);
pPSMaterial->m_vAmbientObjectColor =
Vec4(color.r, color.g, color.b, color.a);
pPSMaterial->m_bHasTexture = false;
DXUTGetD3D11DeviceContext()->VSSetConstantBuffers( 0, 1, &m_pcbVSMatrices );
DXUTGetD3D11DeviceContext()->VSSetConstantBuffers( 1, 1, &m_pcbVSLighting );
DXUTGetD3D11DeviceContext()->VSSetConstantBuffers( 2, 1, &m_pcbVSMaterial );
return S_OK;
}
This code looks a little more complicated than it is. Each time the vertices are ren-
dered, the ID3D11DeviceContext is informed of the shader being used and the
vertex layout it expects. The nearly dozen lines of code following grab the two trans-
form matrices we need from a class you will be introduced to in the next chapter, the
Scene class. The matrices are transposed, an operation that flips the rows into col-
umns and columns into rows. This is because the native format used by the DXUT
matrix structure isn ' t what is expected by the video card hardware. The D3D11_
MAPPED_SUBRESOURCE structure is what is defined and sent into the ID3D11Device
Context::Map() method to create a buffer space the transposed matrices can be
sent to.
I admit, I ' m cheating a bit by giving you a peek at some objects you ' ll see in the next
chapter. I
m talking about the Scene object stored in pScene . For now, just know
that this defines a scene in your game, and a part of that scene includes lights. The
SceneNode object stored in pNode stores a renderable object in that scene
'
in fact,
the very object that the pixel shader is about to render. A part of the SceneNode
class defines the material applied to the object. The call to pScene->
GetLightManager()->CalcLighting() is what fills the lighting structure with
all the information about what lights are currently affecting the vertices sent to the
shader.
Search WWH ::




Custom Search