Game Development Reference
In-Depth Information
the transform matrices, lighting, and materials were defined. This process only needs
to be done once, as long as the ID3D11Device remains valid.
The next method is run in each frame and initializes all the data for the shader:
HRESULT GameCode4_Hlsl_VertexShader::SetupRender(Scene *pScene, const SceneNode
*pNode)
{
HRESULT hr;
// Set the vertex shader and the vertex layout
DXUTGetD3D11DeviceContext()->VSSetShader( m_pVertexShader, NULL, 0 );
DXUTGetD3D11DeviceContext()->IASetInputLayout( m_pVertexLayout11 );
// Get the projection & view matrix from the camera class
Mat4x4 mWorldViewProjection =
pScene->GetCamera()->GetWorldViewProjection(pScene);
Mat4x4 mWorld = pScene->GetTopMatrix();
D3D11_MAPPED_SUBRESOURCE MappedResource;
// - - - - - Transform Matrices - - - - -
V( DXUTGetD3D11DeviceContext()->Map(
m_pcbVSMatrices, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ) );
ConstantBuffer_Matrices* pVSMatrices =
( ConstantBuffer_Matrices* )MappedResource.pData;
D3DXMatrixTranspose( &pVSMatrices->m_WorldViewProj, &mWorldViewProjection );
D3DXMatrixTranspose( &pVSMatrices->m_World, &mWorld );
DXUTGetD3D11DeviceContext()->Unmap( m_pcbVSMatrices, 0 );
// - - - - - Lighting - - - - -
V( DXUTGetD3D11DeviceContext()->Map( m_pcbVSLighting, 0,
D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ) );
D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ) );
ConstantBuffer_Lighting* pLighting =
( ConstantBuffer_Lighting* )MappedResource.pData;
if (m_enableLights)
pScene->GetLightManager()->CalcLighting(pLighting, pNode);
else
{
pLighting->m_nNumLights = 0;
pLighting->m_vLightAmbient = Vec4(1.0f, 1.0f, 1.0f, 1.0f);
}
DXUTGetD3D11DeviceContext()->Unmap( m_pcbVSLighting, 0 );
Search WWH ::




Custom Search