void App::RenderGBuffer(ID3D11DeviceContext* d3dDeviceContext, CDXUTSDKMesh& mesh_opaque, CDXUTSDKMesh& mesh_alpha, const CFirstPersonCamera* viewerCamera, const D3D11_VIEWPORT* viewport, const UIConstants* ui) { // Clear GBuffer // NOTE: We actually only need to clear the depth buffer here since we replace unwritten (i.e. far plane) samples // with the skybox. We use the depth buffer to reconstruct position and only in-frustum positions are shaded. // NOTE: Complementary Z buffer: clear to 0 (far)! d3dDeviceContext->ClearDepthStencilView(mDepthBuffer->GetDepthStencil(), D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0); d3dDeviceContext->IASetInputLayout(mMeshVertexLayout); d3dDeviceContext->VSSetConstantBuffers(0, 1, &mPerFrameConstants); d3dDeviceContext->VSSetShader(mGeometryVS->GetShader(), 0, 0); d3dDeviceContext->GSSetShader(0, 0, 0); d3dDeviceContext->RSSetViewports(1, viewport); d3dDeviceContext->PSSetConstantBuffers(0, 1, &mPerFrameConstants); d3dDeviceContext->PSSetSamplers(0, 1, &mDiffuseSampler); // Diffuse texture set per-material by DXUT mesh routines // Set up render GBuffer render targets d3dDeviceContext->OMSetDepthStencilState(mDepthState, 0); d3dDeviceContext->OMSetRenderTargets(static_cast<UINT>(mGBufferRTV.size()), &mGBufferRTV.front(), mDepthBuffer->GetDepthStencil()); d3dDeviceContext->OMSetBlendState(mGeometryBlendState, 0, 0xFFFFFFFF); // Render opaque geometry if (mesh_opaque.IsLoaded()) { d3dDeviceContext->RSSetState(mRasterizerState); d3dDeviceContext->PSSetShader(mGBufferPS->GetShader(), 0, 0); mesh_opaque.Render(d3dDeviceContext, 0); } // Render alpha tested geometry if (mesh_alpha.IsLoaded()) { d3dDeviceContext->RSSetState(mDoubleSidedRasterizerState); d3dDeviceContext->PSSetShader(mGBufferAlphaTestPS->GetShader(), 0, 0); mesh_alpha.Render(d3dDeviceContext, 0); } // Cleanup (aka make the runtime happy) d3dDeviceContext->OMSetRenderTargets(0, 0, 0); }
//-------------------------------------------------------------------------------------- // RenderSky //-------------------------------------------------------------------------------------- void RenderSky( ID3D10Device* pd3dDevice ) { D3DXMATRIX mWorld; D3DXVECTOR3 vEye; D3DXVECTOR3 vDir; D3DXMATRIX mCamWorld; D3DXMATRIX mView; D3DXMATRIX mProj; D3DXMatrixRotationY( &mWorld, -D3DX_PI / 2.5f ); GetCameraData( &mCamWorld, &mView, &mProj, &vEye, &vDir ); mView._41 = mView._42 = mView._43 = 0.0f; D3DXMATRIX mWVP = mWorld * mCamWorld * mView * mProj; g_pmWorldViewProj->SetMatrix( ( float* )&mWVP ); g_pmWorld->SetMatrix( ( float* )&mWorld ); pd3dDevice->IASetInputLayout( g_pBasicDecl10 ); g_SkyMesh.Render( pd3dDevice, g_pRenderSky, g_ptxDiffuse ); }
//-------------------------------------------------------------------------------------- // Render the scene using the D3D9 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) { HRESULT hr = S_OK; // If the settings dialog is being shown, then render it instead of rendering the app's scene if( g_SettingsDlg.IsActive() ) { g_SettingsDlg.OnRender( fElapsedTime ); return; } D3DXMATRIX mWorld = *g_Camera.GetWorldMatrix(); D3DXMATRIX mView = *g_Camera.GetViewMatrix(); D3DXMATRIX mProj = *g_Camera.GetProjMatrix(); D3DXMATRIX mWorldViewProjection = mWorld * mView * mProj; // Clear the render target and the zbuffer V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 160, 160, 250 ), 1.0f, 0 ) ); // Render the scene if( SUCCEEDED( pd3dDevice->BeginScene() ) ) { g_pEffect9->SetMatrix( g_hmWorld, &mWorld ); g_pEffect9->SetMatrix( g_hmWorldViewProjection, &mWorldViewProjection ); g_pEffect9->SetTexture( g_htxDiffuse, g_pTexture9 ); pd3dDevice->SetVertexDeclaration( g_pDecl9 ); g_Mesh.Render( pd3dDevice, g_pEffect9, g_hRenderScene ); DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); // These events are to help PIX identify what the code is doing RenderText(); V( g_HUD.OnRender( fElapsedTime ) ); V( g_SampleUI.OnRender( fElapsedTime ) ); DXUT_EndPerfEvent(); V( pd3dDevice->EndScene() ); } }
//-------------------------------------------------------------------------------------- // Render the scene using the D3D11 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime, float fElapsedTime, void* pUserContext ) { HRESULT hr; // If the settings dialog is being shown, then render it instead of rendering the app's scene if( g_D3DSettingsDlg.IsActive() ) { g_D3DSettingsDlg.OnRender( fElapsedTime ); return; } // Clear the render target and depth stencil auto pRTV = DXUTGetD3D11RenderTargetView(); pd3dImmediateContext->ClearRenderTargetView( pRTV, Colors::MidnightBlue ); auto pDSV = DXUTGetD3D11DepthStencilView(); pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 ); // Get the projection & view matrix from the camera class XMMATRIX mWorld = g_Camera.GetWorldMatrix(); XMMATRIX mProj = g_Camera.GetProjMatrix(); XMMATRIX mView = g_Camera.GetViewMatrix(); // Get the light direction XMVECTOR vLightDir = g_LightControl.GetLightDirection(); // Render the light arrow so the user can visually see the light dir V( g_LightControl.OnRender( Colors::Yellow, mView, mProj, g_Camera.GetEyePt() ) ); // Ambient Light static const XMVECTORF32 s_vLightColorA = { 0.1f, 0.1f, 0.1f, 1.0f }; g_pAmbientLightColor->SetFloatVector( s_vLightColorA ); g_pAmbientLightEnable->SetBool(true); // Hemi Ambient Light static const XMVECTORF32 s_vLightColorH1 = { 0.3f, 0.3f, 0.4f, 1.0f }; g_pHemiAmbientLightColor->SetFloatVector( s_vLightColorH1 ); g_pHemiAmbientLightEnable->SetBool(true); XMFLOAT4 vLightGrndClr( 0.05f, 0.05f, 0.05f, 1.f ); g_pHemiAmbientLightGroundColor->SetFloatVector( reinterpret_cast<float*>( &vLightGrndClr ) ); XMFLOAT4 vVec(0.0f, 1.0f, 0.0f, 1.0f); g_pHemiAmbientLightDirUp->SetFloatVector( reinterpret_cast<float*>( &vVec ) ); // Directional Light g_pDirectionalLightColor->SetFloatVector( Colors::White ); g_pDirectionalLightEnable->SetBool(true); XMFLOAT4 tmp; XMStoreFloat4( &tmp, vLightDir ); tmp.w = 1.f; g_pDirectionalLightDir->SetFloatVector( reinterpret_cast<float*>( &tmp ) ); // Environment Light - color comes from the texture g_pEnvironmentLightColor->SetFloatVector( Colors::Black ); g_pEnvironmentLightEnable->SetBool(true); // Setup the Eye based on the DXUT camera XMVECTOR vEyePt = g_Camera.GetEyePt(); XMVECTOR vDir = g_Camera.GetLookAtPt() - vEyePt; XMStoreFloat4( &tmp, vDir ); tmp.w = 1.f; g_pEyeDir->SetFloatVector( reinterpret_cast<float*>( &tmp ) ); //Get the mesh //IA setup pd3dImmediateContext->IASetInputLayout( g_pVertexLayout11 ); UINT Strides[1]; UINT Offsets[1]; ID3D11Buffer* pVB[1]; pVB[0] = g_Mesh11.GetVB11( 0, 0 ); Strides[0] = ( UINT )g_Mesh11.GetVertexStride( 0, 0 ); Offsets[0] = 0; pd3dImmediateContext->IASetVertexBuffers( 0, 1, pVB, Strides, Offsets ); pd3dImmediateContext->IASetIndexBuffer( g_Mesh11.GetIB11( 0 ), g_Mesh11.GetIBFormat11( 0 ), 0 ); // Set the per object constant data XMMATRIX mWorldViewProjection = mWorld * mView * mProj; // VS Per object XMFLOAT4X4 tmp4x4; XMStoreFloat4x4( &tmp4x4, mWorldViewProjection ); g_pWorldViewProjection->SetMatrix( reinterpret_cast<float*>( &tmp4x4 ) ); XMStoreFloat4x4( &tmp4x4, mWorld ); g_pWorld->SetMatrix( reinterpret_cast<float*>( &tmp4x4 ) ); // Setup the Shader Linkage based on the user settings for Lighting ID3DX11EffectClassInstanceVariable* pLightClassVar; // Ambient Lighting First - Constant or Hemi? if ( g_bHemiAmbientLighting ) { pLightClassVar = g_pHemiAmbientLightClass; } else { pLightClassVar = g_pAmbientLightClass; } if (g_pAmbientLightIface) { g_pAmbientLightIface->SetClassInstance(pLightClassVar); } // Direct Light - None or Directional if (g_bDirectLighting) { pLightClassVar = g_pDirectionalLightClass; } else { // Disable ALL Direct Lighting pLightClassVar = g_pAmbientLightClass; } if (g_pDirectionalLightIface) { g_pDirectionalLightIface->SetClassInstance(pLightClassVar); } // Setup the selected material class instance E_MATERIAL_TYPES iMaterialTech = g_iMaterial; switch( g_iMaterial ) { case MATERIAL_PLASTIC: case MATERIAL_PLASTIC_TEXTURED: // Bind the Environment light for reflections pLightClassVar = g_pEnvironmentLightClass; if (g_bLightingOnly) { iMaterialTech = MATERIAL_PLASTIC_LIGHTING_ONLY; } break; case MATERIAL_ROUGH: case MATERIAL_ROUGH_TEXTURED: // UnBind the Environment light pLightClassVar = g_pAmbientLightClass; if (g_bLightingOnly) { iMaterialTech = MATERIAL_ROUGH_LIGHTING_ONLY; } break; } if (g_pEnvironmentLightIface) { g_pEnvironmentLightIface->SetClassInstance(pLightClassVar); } ID3DX11EffectTechnique* pTechnique = g_pTechnique; if (g_pMaterialIface) { #if USE_BIND_INTERFACES // We're using the techniques with pre-bound materials, // so select the appropriate technique. pTechnique = g_MaterialClasses[ iMaterialTech ].pTechnique; #else // We're using a single technique and need to explicitly // bind a concrete material instance. g_pMaterialIface->SetClassInstance( g_MaterialClasses[ iMaterialTech ].pClass ); #endif } // PS Per Prim // Shiny Plastic XMFLOAT3 clr1(1, 0, 0.5f); g_MaterialClasses[MATERIAL_PLASTIC].pColor->SetFloatVector( reinterpret_cast<float*>( &clr1 ) ); g_MaterialClasses[MATERIAL_PLASTIC].pSpecPower->SetInt(255); // Shiny Plastic with Textures XMFLOAT3 clr2(1, 0, 0.5f); g_MaterialClasses[MATERIAL_PLASTIC_TEXTURED].pColor->SetFloatVector( reinterpret_cast<float*>( &clr2 ) ); g_MaterialClasses[MATERIAL_PLASTIC_TEXTURED].pSpecPower->SetInt(128); // Lighting Only Plastic XMFLOAT3 clr3(1, 1, 1); g_MaterialClasses[MATERIAL_PLASTIC_LIGHTING_ONLY].pColor->SetFloatVector( reinterpret_cast<float*>( &clr3 ) ); g_MaterialClasses[MATERIAL_PLASTIC_LIGHTING_ONLY].pSpecPower->SetInt(128); // Rough Material XMFLOAT3 clr4(0, 0.5f, 1); g_MaterialClasses[MATERIAL_ROUGH].pColor->SetFloatVector( reinterpret_cast<float*>( &clr4 ) ); g_MaterialClasses[MATERIAL_ROUGH].pSpecPower->SetInt(6); // Rough Material with Textures XMFLOAT3 clr5(0, 0.5f, 1); g_MaterialClasses[MATERIAL_ROUGH_TEXTURED].pColor->SetFloatVector( reinterpret_cast<float*>( &clr5 ) ); g_MaterialClasses[MATERIAL_ROUGH_TEXTURED].pSpecPower->SetInt(6); // Lighting Only Rough XMFLOAT3 clr6(1, 1, 1); g_MaterialClasses[MATERIAL_ROUGH_LIGHTING_ONLY].pColor->SetFloatVector( reinterpret_cast<float*>( &clr6 ) ); g_MaterialClasses[MATERIAL_ROUGH_LIGHTING_ONLY].pSpecPower->SetInt(6); if (g_bWireFrame) g_pFillMode->SetInt(1); else g_pFillMode->SetInt(0); // Apply the technique to update state. pTechnique->GetPassByIndex(0)->Apply(0, pd3dImmediateContext); //Render g_Mesh11.Render( pd3dImmediateContext, 0, 1, INVALID_SAMPLER_SLOT); // Tell the UI items to render DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); g_HUD.OnRender( fElapsedTime ); g_SampleUI.OnRender( fElapsedTime ); RenderText(); DXUT_EndPerfEvent(); }
//-------------------------------------------------------------------------------------- // render callback //-------------------------------------------------------------------------------------- void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime, float fElapsedTime, void* pUserContext ) { static int s_iCounter = 0; // If the settings dialog is being shown, then render it instead of rendering the app's scene if( g_D3DSettingsDlg.IsActive() ) { g_D3DSettingsDlg.OnRender( fElapsedTime ); return; } if( g_pScenePS == NULL && s_iCounter == 0 ) { s_iCounter = 4; } if( s_iCounter > 0 ) s_iCounter --; if( s_iCounter == 1 && g_pScenePS == NULL ) { HRESULT hr = S_OK; // Create the shaders ID3DBlob* pBlob = NULL; // VS hr = CompileShaderFromFile( L"ContactHardeningShadows11.hlsl", "VS_RenderScene", "vs_5_0", &pBlob ); hr = pd3dDevice->CreateVertexShader( pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &g_pSceneVS ); DXUT_SetDebugName( g_pSceneVS, "VS_RenderScene" ); // Define our scene vertex data layout const D3D11_INPUT_ELEMENT_DESC SceneLayout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXTURE", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; hr = pd3dDevice->CreateInputLayout( SceneLayout, ARRAYSIZE( SceneLayout ), pBlob->GetBufferPointer(), pBlob->GetBufferSize(), &g_pSceneVertexLayout ); SAFE_RELEASE( pBlob ); DXUT_SetDebugName( g_pSceneVertexLayout, "SceneLayout" ); hr = CompileShaderFromFile( L"ContactHardeningShadows11.hlsl", "VS_RenderSceneSM", "vs_5_0", &pBlob ); hr = pd3dDevice->CreateVertexShader( pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &g_pSM_VS ); SAFE_RELEASE( pBlob ); DXUT_SetDebugName( g_pSM_VS, "VS_RenderSceneSM" ); // PS hr = CompileShaderFromFile( L"ContactHardeningShadows11.hlsl", "PS_RenderScene", "ps_5_0", &pBlob ); hr = pd3dDevice->CreatePixelShader( pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &g_pScenePS ); SAFE_RELEASE( pBlob ); DXUT_SetDebugName( g_pScenePS, "PS_RenderScene" ); s_iCounter = 0; } else if( g_pScenePS != NULL ) { ID3D11RenderTargetView* pRTV[2] = { NULL,NULL }; ID3D11ShaderResourceView* pSRV[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; // Array of our samplers ID3D11SamplerState* ppSamplerStates[3] = { g_pSamplePoint, g_pSampleLinear, g_pSamplePointCmp }; pd3dImmediateContext->PSSetSamplers( 0, 3, ppSamplerStates ); // Store off original render target, this is the back buffer of the swap chain ID3D11RenderTargetView* pOrigRTV = DXUTGetD3D11RenderTargetView(); ID3D11DepthStencilView* pOrigDSV = DXUTGetD3D11DepthStencilView(); // Clear the render target float ClearColor[4] = { 0.0f, 0.25f, 0.25f, 0.55f }; pd3dImmediateContext->ClearRenderTargetView( DXUTGetD3D11RenderTargetView(), ClearColor ); pd3dImmediateContext->ClearDepthStencilView( DXUTGetD3D11DepthStencilView(), D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0, 0 ); // Get the projection & view matrix from the camera class D3DXMATRIXA16 mWorld; D3DXMATRIXA16 mView; D3DXMATRIXA16 mProj; D3DXMATRIXA16 mViewProjLight; D3DXMATRIXA16 mWorldViewProjection; D3DXVECTOR3 vLightDir; // disable color writes pd3dImmediateContext->OMSetBlendState(g_pBlendStateColorWritesOff, 0, 0xffffffff); RenderShadowMap( pd3dDevice, pd3dImmediateContext, mViewProjLight, vLightDir ); // enable color writes pd3dImmediateContext->OMSetBlendState(g_pBlendStateNoBlend, 0, 0xffffffff); mView = *g_Camera.GetViewMatrix(); mProj = *g_Camera.GetProjMatrix(); mWorldViewProjection = mView * mProj; // Setup the constant buffer for the scene vertex shader D3D11_MAPPED_SUBRESOURCE MappedResource; pd3dImmediateContext->Map( g_pcbConstants, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ); CB_CONSTANTS* pConstants = ( CB_CONSTANTS* )MappedResource.pData; D3DXMatrixTranspose( &pConstants->f4x4WorldViewProjection, &mWorldViewProjection ); D3DXMatrixTranspose( &pConstants->f4x4WorldViewProjLight, &mViewProjLight ); pConstants->vShadowMapDimensions = D3DXVECTOR4(g_fShadowMapWidth, g_fShadowMapHeight, 1.0f/g_fShadowMapWidth, 1.0f/g_fShadowMapHeight); pConstants->vLightDir = D3DXVECTOR4( vLightDir.x, vLightDir.y, vLightDir.z, 0.0f ); pConstants->fSunWidth = g_fSunWidth; pd3dImmediateContext->Unmap( g_pcbConstants, 0 ); pd3dImmediateContext->VSSetConstantBuffers( g_iCONSTANTSCBBind, 1, &g_pcbConstants ); pd3dImmediateContext->PSSetConstantBuffers( g_iCONSTANTSCBBind, 1, &g_pcbConstants ); // Set the shaders pd3dImmediateContext->VSSetShader( g_pSceneVS, NULL, 0 ); pd3dImmediateContext->PSSetShader( g_pScenePS, NULL, 0 ); // Set the vertex buffer format pd3dImmediateContext->IASetInputLayout( g_pSceneVertexLayout ); // Rebind to original back buffer and depth buffer pRTV[0] = pOrigRTV; pd3dImmediateContext->OMSetRenderTargets(1, pRTV, pOrigDSV ); // set the shadow map pd3dImmediateContext->PSSetShaderResources( 1, 1, &g_pDepthTextureSRV ); // Render the scene g_SceneMesh.Render( pd3dImmediateContext, 0 ); g_Poles.Render( pd3dImmediateContext, 0 ); // restore resources pd3dImmediateContext->PSSetShaderResources( 0, 8, pSRV ); } // Render GUI DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); if( g_bGuiVisible ) { g_HUD.OnRender( fElapsedTime ); g_SampleUI.OnRender( fElapsedTime ); } RenderText(); DXUT_EndPerfEvent(); }
//-------------------------------------------------------------------------------------- // Renders the depth only shadow map //-------------------------------------------------------------------------------------- void RenderShadowMap( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, D3DXMATRIXA16& mViewProjLight, D3DXVECTOR3& vLightDir ) { D3D11_RECT oldrects[1]; D3D11_VIEWPORT oldvp[2]; UINT num = 1; pd3dImmediateContext->RSGetScissorRects( &num, oldrects ); num = 1; pd3dImmediateContext->RSGetViewports( &num, oldvp ); oldvp[ 1 ] = oldvp[ 0 ]; D3D11_RECT rects[1] = { { 0, UINT(g_fShadowMapWidth), 0, UINT(g_fShadowMapHeight) } }; pd3dImmediateContext->RSSetScissorRects( 1, rects ); D3D11_VIEWPORT vp[1] = { { 0, 0, g_fShadowMapWidth, g_fShadowMapHeight, 0.0f, 1.0f } }; pd3dImmediateContext->RSSetViewports( 1, vp ); // Set our scene render target & keep original depth buffer ID3D11RenderTargetView* pRTVs[2] = {0,0}; pd3dImmediateContext->OMSetRenderTargets( 2, pRTVs, g_pDepthStencilTextureDSV ); // Clear the render target pd3dImmediateContext->ClearDepthStencilView( g_pDepthStencilTextureDSV, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0, 0 ); // Get the projection & view matrix from the camera class D3DXMATRIXA16 mWorld; D3DXMATRIXA16 mView; D3DXMATRIXA16 mProj; D3DXVECTOR3 up(0,1,0); D3DXVECTOR4 vLight( 0.0f,0.0f,0.0f, 1.0f ); D3DXVECTOR4 vLightLookAt4d( 0.0f,-0.5f,1.0f, 0.0f ); vLightLookAt4d = vLight + vLightLookAt4d; D3DXVec4Transform( &vLight, &vLight, g_LCamera.GetWorldMatrix() ); D3DXVec4Transform( &vLightLookAt4d, &vLightLookAt4d, g_LCamera.GetWorldMatrix() ); D3DXMatrixOrthoOffCenterLH( &mProj, -8.5, 9, -15, 11, -20, 20 ); D3DXVECTOR3 vLight3d( vLight.x, vLight.y, vLight.z ); D3DXVECTOR3 vLightLookAt3d( vLightLookAt4d.x, vLightLookAt4d.y, vLightLookAt4d.z ); vLightDir = vLightLookAt3d - vLight3d; D3DXMatrixLookAtLH( &mView, &vLight3d, &vLightLookAt3d, &up); mViewProjLight = mView * mProj; // Setup the constant buffer for the scene vertex shader D3D11_MAPPED_SUBRESOURCE MappedResource; pd3dImmediateContext->Map( g_pcbConstants, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ); CB_CONSTANTS* pConstants = ( CB_CONSTANTS* )MappedResource.pData; D3DXMatrixTranspose( &pConstants->f4x4WorldViewProjection, &mViewProjLight ); D3DXMatrixTranspose( &pConstants->f4x4WorldViewProjLight, &mViewProjLight ); pConstants->vShadowMapDimensions = D3DXVECTOR4(g_fShadowMapWidth, g_fShadowMapHeight, 1.0f/g_fShadowMapWidth, 1.0f/g_fShadowMapHeight); pd3dImmediateContext->Unmap( g_pcbConstants, 0 ); pd3dImmediateContext->VSSetConstantBuffers( g_iCONSTANTSCBBind, 1, &g_pcbConstants ); pd3dImmediateContext->PSSetConstantBuffers( g_iCONSTANTSCBBind, 1, &g_pcbConstants ); // Set the shaders pd3dImmediateContext->VSSetShader( g_pSM_VS, NULL, 0 ); pd3dImmediateContext->PSSetShader( NULL, NULL, 0 ); // Set the vertex buffer format pd3dImmediateContext->IASetInputLayout( g_pSceneVertexLayout ); // Render the scene g_Poles.Render( pd3dImmediateContext, 0 ); // reset the old viewport etc. pd3dImmediateContext->RSSetScissorRects( 1, oldrects ); pd3dImmediateContext->RSSetViewports( 1, oldvp ); }