void HumanView::VOnRender(double fTime, float fElapsedTime ) { m_currTick = timeGetTime(); if (m_currTick == m_lastDraw) return; // It is time to draw ? if( (m_currTick - m_lastDraw) > SCREEN_REFRESH_RATE ) { ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext(); float ClearColor[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView(); pd3dImmediateContext->ClearRenderTargetView( pRTV, ClearColor ); ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView(); pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 ); m_ScreenElements.sort(SortBy_SharedPtr_Content<IScreenElement>()); for(ScreenElementList::iterator i=m_ScreenElements.begin(); i!=m_ScreenElements.end(); ++i) { (*i)->VOnRender(fTime, fElapsedTime); } // record the last successful paint m_lastDraw = m_currTick; } }
void CDirect3DView::OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime, float fElapsedTime) { // Clear render target and the depth stencil //float ClearColor[4] = { 0.176f, 0.196f, 0.667f, 0.0f }; float ClearColor[4] = {0.39f, 0.58f, 0.929f, 0.0f}; ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView(); ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView(); pd3dImmediateContext->ClearRenderTargetView( pRTV, ClearColor ); pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH| D3D11_CLEAR_STENCIL, 1.0, 0 ); }
//-------------------------------------------------------------------------------------- // Render the scene using the D3D11 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime, float fElapsedTime, void* pUserContext ) { // Clear render target and the depth stencil float ClearColor[4] = { 0.176f, 0.196f, 0.667f, 0.0f }; ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView(); ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView(); pd3dImmediateContext->ClearRenderTargetView( pRTV, ClearColor ); pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 ); }
void DX11PhongLighting::renderStereo( ID3D11DeviceContext* pd3dDeviceContext, ID3D11ShaderResourceView* positions, ID3D11ShaderResourceView* normals, ID3D11ShaderResourceView* colors, ID3D11ShaderResourceView* ssaoMap, bool useMaterial, bool useSSAO ) { // Initialize Constant Buffers D3D11_MAPPED_SUBRESOURCE mappedResource; HRESULT hr = pd3dDeviceContext->Map(s_ConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); if(FAILED(hr)) return; cbConstant *cbufferConstant = (cbConstant*)mappedResource.pData; cbufferConstant->useMaterial = (int)useMaterial; cbufferConstant->useSSAO = (int)useSSAO; pd3dDeviceContext->Unmap(s_ConstantBuffer, 0); pd3dDeviceContext->PSSetConstantBuffers(0, 1, &s_ConstantBuffer); ID3D11Buffer* CBGlobalAppState = GlobalAppState::getInstance().MapAndGetConstantBuffer(pd3dDeviceContext); pd3dDeviceContext->PSSetConstantBuffers(8, 1, &CBGlobalAppState); static float ClearColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView(); pd3dDeviceContext->ClearRenderTargetView(s_pColorsStereoRTV, ClearColor); pd3dDeviceContext->ClearDepthStencilView(s_pDepthStencilStereoDSV, D3D11_CLEAR_DEPTH, 1.0f, 0); pd3dDeviceContext->OMSetRenderTargets(1, &s_pColorsStereoRTV, s_pDepthStencilStereoDSV); ID3D11ShaderResourceView* srvs[] = {positions, normals, colors, ssaoMap}; DX11QuadDrawer::RenderQuad(pd3dDeviceContext, s_PixelShaderPhong, srvs, 4); ID3D11RenderTargetView* rtv = DXUTGetD3D11RenderTargetView(); ID3D11DepthStencilView* dsv = DXUTGetD3D11DepthStencilView(); pd3dDeviceContext->OMSetRenderTargets(1, &rtv, dsv); ID3D11Buffer* nullCB[] = { NULL }; pd3dDeviceContext->PSSetConstantBuffers(0, 1, nullCB); pd3dDeviceContext->PSSetConstantBuffers(8, 1, nullCB); }
void DX11CustomRenderTarget::Unbind( ID3D11DeviceContext* pd3dDeviceContext ) { D3D11_VIEWPORT vp; vp.Width = (FLOAT)DXUTGetDXGIBackBufferSurfaceDesc()->Width; vp.Height = (FLOAT)DXUTGetDXGIBackBufferSurfaceDesc()->Height; vp.MinDepth = 0; vp.MaxDepth = 1; vp.TopLeftX = 0; vp.TopLeftY = 0; pd3dDeviceContext->RSSetViewports( 1, &vp ); ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView(); ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView(); pd3dDeviceContext->OMSetRenderTargets(1, &pRTV, pDSV); }
//-------------------------------------------------------------------------------------- // Render //-------------------------------------------------------------------------------------- void CALLBACK OnFrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime, float fElapsedTime, void* pUserContext ) { // Clear the render target and depth stencil auto pRTV = DXUTGetD3D11RenderTargetView(); pd3dImmediateContext->ClearRenderTargetView( pRTV, DirectX::Colors::Gray ); auto pDSV = DXUTGetD3D11DepthStencilView(); pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 ); pd3dImmediateContext->OMSetRenderTargets( 1, &pRTV, pDSV ); // Fluid RenderFluid( pd3dImmediateContext ); // HUD g_pHUD->OnRender( fElapsedTime ); // FPS and Statistics RenderText( fTime ); }
void CALLBACK OnD3D11FrameRender(ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime, float fElapsedTime, void* pUserContext) { pd3dImmediateContext->ClearRenderTargetView(DXUTGetD3D11RenderTargetView(), Colors::DeepSkyBlue); pd3dImmediateContext->ClearDepthStencilView(DXUTGetD3D11DepthStencilView(), D3D11_CLEAR_DEPTH, 1.0f, 0); CONSTANTBUFFER cb; ZeroMemory(&cb, sizeof(CONSTANTBUFFER)); XMMATRIX mat = XMLoadFloat4x4(&(g_mesh->getWorld())); XMStoreFloat4x4(&cb.world, XMMatrixTranspose(mat)); //cb.world = g_mesh->getWorld(); XMStoreFloat4x4(&cb.view, XMMatrixTranspose(g_camera.GetViewMatrix())); XMStoreFloat4x4(&cb.projection, XMMatrixTranspose(g_camera.GetProjMatrix())); /* 1 0 0 0 Side (Right) 0 1 0 0 Up 0 0 1 0 Foward x y z 1 Position */ //1. XMMATRIX -> FLOAT4X4 XMVECTOR v = XMVectorSet(1.0f, 1.0f, 1.0f, 1.0f); XMVECTOR litpos = XMVector4Transform(v, g_matLight); litpos = XMVector4Normalize(litpos); XMStoreFloat4(&cb.litDir, litpos); cb.litCol = XMFLOAT4(0.7f, 0.7f, 0.6f, 1.0f); g_shader->RenderPrepare(&cb); g_mesh->Render(); // mat = XMLoadFloat4x4(&(g_meshLight->getWorld())); XMStoreFloat4x4(&cb.world, XMMatrixTranspose(mat)); g_shader->RenderPrepare(&cb); g_meshLight->Render(); }
//-------------------------------------------------------------------------------------- // Render the scene using the D3D11 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D11FrameRender(ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double /*fTime*/, FLOAT fElapsedTime, void* /*pUserContext*/) { if (g_D3DSettingsDlg.IsActive()) { g_D3DSettingsDlg.OnRender(fElapsedTime); return; } FLOAT ClearColor[4] = { 0.0f, 0.25f, 0.25f, 0.55f }; ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView(); ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView(); pd3dImmediateContext->ClearRenderTargetView(pRTV, ClearColor); pd3dImmediateContext->ClearDepthStencilView(pDSV, D3D11_CLEAR_DEPTH, 1.0, 0); g_VarianceShadow.InitFrame(pd3dDevice, g_pSelectedMesh); g_VarianceShadow.RenderShadowsForAllCascades(pd3dDevice, pd3dImmediateContext, g_pSelectedMesh); D3D11_VIEWPORT vp; vp.Width = (FLOAT)DXUTGetDXGIBackBufferSurfaceDesc()->Width; vp.Height = (FLOAT)DXUTGetDXGIBackBufferSurfaceDesc()->Height; vp.MinDepth = 0; vp.MaxDepth = 1; vp.TopLeftX = 0; vp.TopLeftY = 0; g_VarianceShadow.RenderScene( pd3dImmediateContext, pRTV, pDSV, g_pSelectedMesh, g_pActiveCamera, &vp, g_bVisualizeCascades); pd3dImmediateContext->RSSetViewports(1, &vp); pd3dImmediateContext->OMSetRenderTargets(1, &pRTV, pDSV); DXUT_BeginPerfEvent(DXUT_PERFEVENTCOLOR, L"HUD / Stats"); g_HUD.OnRender(fElapsedTime); g_SampleUI.OnRender(fElapsedTime); RenderText(); DXUT_EndPerfEvent(); }
//-------------------------------------------------------------------------------------- // Render the scene using the D3D11 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime, float fElapsedTime, void* pUserContext ) { // Clear render target and the depth stencil float ClearColor[4] = { 0.176f, 0.196f, 0.667f, 0.0f }; ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView(); ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView(); pd3dImmediateContext->ClearRenderTargetView( pRTV, ClearColor ); pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 ); vegetationRendering->draw(pd3dDevice, GameTime(fElapsedTime, fTime)); std::wstringstream ws; ws << DXUTGetFPS(); textHelper.Begin(); textHelper.SetInsertionPos(5, 5); textHelper.SetForegroundColor(vegetationRendering->isInCaptureMode() ? D3DXCOLOR(1,0,0,1) : D3DXCOLOR(1, 1, 0, 1)); textHelper.DrawTextLine(ws.str().c_str()); textHelper.End(); }
//-------------------------------------------------------------------------------------- // 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; } //Render light arrow D3DXMATRIX mView; D3DXMATRIX mProj; mProj = ( *g_Camera.GetProjMatrix() ); mView = ( *g_Camera.GetViewMatrix() ); D3DXCOLOR arrowColor = D3DXCOLOR( 1, 1, 0, 1 ); //hr = g_LightControl.OnRender11( arrowColor, &mView, &mProj, g_Camera.GetEyePt() ); FirePart.calculate_particle(pd3dDevice,pd3dImmediateContext,fElapsedTime,&g_Camera,&g_LightControl); MissilePart.calculate_particle(pd3dDevice,pd3dImmediateContext,fElapsedTime,&g_Camera,&g_LightControl); board1.RenderTexture(pd3dDevice,pd3dImmediateContext,fTime,fElapsedTime,pUserContext,&g_LightControl); deboard.RenderTexture(pd3dDevice,pd3dImmediateContext,fTime,fElapsedTime,pUserContext,&g_LightControl); // Clear the render target and depth stencil float ClearColor[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; //ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView(); ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView(); pd3dImmediateContext->ClearRenderTargetView( rtv_render_to_texture_ori, ClearColor ); ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView(); pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 ); pd3dImmediateContext->OMSetRenderTargets(1,&rtv_render_to_texture_ori,pDSV); pd3dImmediateContext->OMSetDepthStencilState(NULL, 0); sky.Render(pd3dDevice,pd3dImmediateContext,fTime,fElapsedTime,pUserContext,&g_Camera,lightpos); lightsphere.Render(pd3dDevice,pd3dImmediateContext,fTime,fElapsedTime,pUserContext,&g_Camera,lightpos); tessplane.Render(pd3dDevice,pd3dImmediateContext,fTime,fElapsedTime,pUserContext,&g_Camera,lightpos); tesscube.Render(pd3dDevice,pd3dImmediateContext,fTime,fElapsedTime,pUserContext,&g_Camera,lightpos); fuse.Render(pd3dDevice,pd3dImmediateContext,fTime,fElapsedTime,pUserContext,&g_Camera,&g_LightControl); board1.Render(pd3dDevice,pd3dImmediateContext,fTime,fElapsedTime,pUserContext,&g_Camera,lightpos); deboard.Render(pd3dDevice,pd3dImmediateContext,fTime,fElapsedTime,pUserContext,&g_Camera,lightpos); test.Render(pd3dDevice,pd3dImmediateContext,fTime,fElapsedTime,pUserContext,&g_Camera,lightpos); if(show_buildings) { buildings.Render(pd3dDevice,pd3dImmediateContext,fTime,fElapsedTime,pUserContext,&g_Camera,lightpos); } geo_alien.Render(pd3dDevice,pd3dImmediateContext,fTime,fElapsedTime,pUserContext,&g_Camera,lightpos); FirePart.Render(pd3dDevice,pd3dImmediateContext,fTime,fElapsedTime,pUserContext,&g_Camera); MissilePart.Render(pd3dDevice,pd3dImmediateContext,fTime,fElapsedTime,pUserContext,&g_Camera); //ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView(); pd3dImmediateContext->OMSetDepthStencilState(NULL, 0); pd3dImmediateContext->OMSetBlendState(NULL,NULL,0xffffffff); //find bright spot pd3dImmediateContext->ClearRenderTargetView( rtv_render_to_texture_1, ClearColor ); pDSV = DXUTGetD3D11DepthStencilView(); pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 ); pd3dImmediateContext->OMSetRenderTargets(1,&rtv_render_to_texture_1,pDSV); pd3dImmediateContext->VSSetShader( VSPPFirstPass, NULL, 0 ); pd3dImmediateContext->PSSetShader( PSPPFirstPass, NULL, 0 ); pd3dImmediateContext->HSSetShader( NULL, NULL, 0 ); pd3dImmediateContext->DSSetShader( NULL, NULL, 0 ); pd3dImmediateContext->GSSetShader( NULL, NULL, 0 ); pd3dImmediateContext->PSSetSamplers(0, 1, &g_pSamLinear); pd3dImmediateContext->PSSetShaderResources(0,1,&sr_texture_original); //pd3dImmediateContext->RSSetState( g_pRasterizerStateSolid ); pd3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); pd3dImmediateContext->Draw(9,0); //blur hori pd3dImmediateContext->ClearRenderTargetView( rtv_render_to_texture_2, ClearColor ); pDSV = DXUTGetD3D11DepthStencilView(); pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 ); pd3dImmediateContext->OMSetRenderTargets(1,&rtv_render_to_texture_2,pDSV); Compute_blur(1.0f / width, 0); D3D11_MAPPED_SUBRESOURCE MappedResource; V( pd3dImmediateContext->Map( blur_cb_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ) ); blur_cbuffer* pPerFrame = ( blur_cbuffer* )MappedResource.pData; std::copy(&blur_cb_data.offset[0], &blur_cb_data.offset[15], pPerFrame->offset); //std::copy(&blur_cb_data.offset[0], &blur_cb_data.offset[15], pPerFrame->offset); //std::copy(&blur_cb_data.weight[0], &blur_cb_data.weight[15], pPerFrame->weight); pd3dImmediateContext->Unmap( blur_cb_buffer, 0 ); pd3dImmediateContext->VSSetShader( VSPPBlur, NULL, 0 ); pd3dImmediateContext->PSSetShader( PSPPBlur, NULL, 0 ); pd3dImmediateContext->HSSetShader( NULL, NULL, 0 ); pd3dImmediateContext->DSSetShader( NULL, NULL, 0 ); pd3dImmediateContext->GSSetShader( NULL, NULL, 0 ); pd3dImmediateContext->PSSetConstantBuffers(0,1,&blur_cb_buffer); pd3dImmediateContext->PSSetSamplers(0, 1, &g_pSamLinear); pd3dImmediateContext->PSSetShaderResources(0,1,&sr_texture1); //pd3dImmediateContext->RSSetState( g_pRasterizerStateSolid ); pd3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); pd3dImmediateContext->Draw(9,0); //blur vert pd3dImmediateContext->ClearRenderTargetView( rtv_render_to_texture_1, ClearColor ); pDSV = DXUTGetD3D11DepthStencilView(); pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 ); pd3dImmediateContext->OMSetRenderTargets(1,&rtv_render_to_texture_1,pDSV); Compute_blur(0, 1.0f / height); V( pd3dImmediateContext->Map( blur_cb_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ) ); pPerFrame = ( blur_cbuffer* )MappedResource.pData; std::copy(&blur_cb_data.offset[0], &blur_cb_data.offset[15], pPerFrame->offset); //std::copy(&blur_cb_data.offset[0], &blur_cb_data.offset[15], pPerFrame->offset); //std::copy(&blur_cb_data.weight[0], &blur_cb_data.weight[15], pPerFrame->weight); pd3dImmediateContext->Unmap( blur_cb_buffer, 0 ); pd3dImmediateContext->VSSetShader( VSPPBlur, NULL, 0 ); pd3dImmediateContext->PSSetShader( PSPPBlur, NULL, 0 ); pd3dImmediateContext->HSSetShader( NULL, NULL, 0 ); pd3dImmediateContext->DSSetShader( NULL, NULL, 0 ); pd3dImmediateContext->GSSetShader( NULL, NULL, 0 ); pd3dImmediateContext->PSSetConstantBuffers(0,1,&blur_cb_buffer); pd3dImmediateContext->PSSetSamplers(0, 1, &g_pSamLinear); pd3dImmediateContext->PSSetShaderResources(0,1,&sr_texture2); //pd3dImmediateContext->RSSetState( g_pRasterizerStateSolid ); pd3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); pd3dImmediateContext->Draw(9,0); //combine effect pd3dImmediateContext->ClearRenderTargetView( pRTV, ClearColor ); pDSV = DXUTGetD3D11DepthStencilView(); pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 ); pd3dImmediateContext->OMSetRenderTargets(1,&pRTV,pDSV); // V( pd3dImmediateContext->Map( blur_cb_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ) ); // pPerFrame = ( blur_cbuffer* )MappedResource.pData; //std::copy(&blur_cb_data.offset[0], &blur_cb_data.offset[15], pPerFrame->offset); // pd3dImmediateContext->Unmap( blur_cb_buffer, 0 ); pd3dImmediateContext->VSSetShader( VSPPComb, NULL, 0 ); pd3dImmediateContext->PSSetShader( PSPPComb, NULL, 0 ); pd3dImmediateContext->HSSetShader( NULL, NULL, 0 ); pd3dImmediateContext->DSSetShader( NULL, NULL, 0 ); pd3dImmediateContext->GSSetShader( NULL, NULL, 0 ); pd3dImmediateContext->PSSetConstantBuffers(0,1,&blur_cb_buffer); pd3dImmediateContext->PSSetSamplers(0, 1, &g_pSamLinear); pd3dImmediateContext->PSSetShaderResources(0,1,&sr_texture1);//bloom blurred pd3dImmediateContext->PSSetShaderResources(1,1,&sr_texture_original);//base tex //pd3dImmediateContext->RSSetState( g_pRasterizerStateSolid ); pd3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); pd3dImmediateContext->Draw(9,0); DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); g_HUD.OnRender( fElapsedTime ); g_SampleUI.OnRender( fElapsedTime ); RenderText(); DXUT_EndPerfEvent(); }
// Render the scene using the D3D11 device void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime, float fElapsedTime, void* pUserContext ) { // Recompress the texture gFrameDelay frames after the app has started. This produces more accurate timing of the // compression algorithm. if(gFrameNum == gFrameDelay) { RecompressTexture(); gSampleUI.SendEvent(IDC_TEXT, true, gSampleUI.GetStatic(IDC_TEXT)); gFrameNum++; } else if(gFrameNum < gFrameDelay) { gFrameNum++; } // If the settings dialog is being shown, then render it instead of rendering the app's scene if( gD3DSettingsDlg.IsActive() ) { gD3DSettingsDlg.OnRender( fElapsedTime ); return; } // Clear the render target and depth stencil float ClearColor[4] = { 0.02f, 0.02f, 0.02f, 1.0f }; ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView(); pd3dImmediateContext->ClearRenderTargetView( pRTV, ClearColor ); ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView(); pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 ); // Set the input layout. pd3dImmediateContext->IASetInputLayout( gVertexLayout ); // Set the vertex buffer. UINT stride = sizeof( Vertex ); UINT offset = 0; if (gImageView == eImageView_All) { pd3dImmediateContext->IASetVertexBuffers( 0, 1, &gVertexBuffer, &stride, &offset ); } else { pd3dImmediateContext->IASetVertexBuffers( 0, 1, &gQuadVB, &stride, &offset ); } // Set the primitive topology pd3dImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); // Update the Constant Buffer D3D11_MAPPED_SUBRESOURCE MappedResource; pd3dImmediateContext->Map( gConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ); VS_CONSTANT_BUFFER* pConstData = ( VS_CONSTANT_BUFFER* )MappedResource.pData; ZeroMemory(pConstData, sizeof(VS_CONSTANT_BUFFER)); SetView(&pConstData->mView); pConstData->exposure = powf(2.0, gLog2Exposure); pd3dImmediateContext->Unmap( gConstantBuffer, 0 ); // Set the shaders ID3D11Buffer* pBuffers[1] = { gConstantBuffer }; pd3dImmediateContext->VSSetConstantBuffers( 0, 1, pBuffers ); pd3dImmediateContext->VSSetShader( gVertexShader, NULL, 0 ); if (gSampleUI.GetCheckBox(IDC_ALPHA)->GetChecked()) { pd3dImmediateContext->PSSetShader( gRenderAlphaPS, NULL, 0 ); } else { pd3dImmediateContext->PSSetShader( gRenderFramePS, NULL, 0 ); } pd3dImmediateContext->PSSetConstantBuffers(0, 1, pBuffers ); // Set the texture sampler. pd3dImmediateContext->PSSetSamplers( 0, 1, &gSamPoint ); // Render the textures. if (gImageView == eImageView_Uncompressed || gImageView == eImageView_All ) { pd3dImmediateContext->PSSetShaderResources( 0, 1, &gUncompressedSRV ); } else if (gImageView == eImageView_Compressed) { pd3dImmediateContext->PSSetShaderResources( 0, 1, &gCompressedSRV ); } else if (gImageView == eImageView_Error) { pd3dImmediateContext->PSSetShaderResources( 0, 1, &gErrorSRV ); } pd3dImmediateContext->Draw( 6, 0 ); if (gImageView == eImageView_All) { pd3dImmediateContext->PSSetShaderResources( 0, 1, &gCompressedSRV ); pd3dImmediateContext->Draw( 6, 6 ); pd3dImmediateContext->PSSetShaderResources( 0, 1, &gErrorSRV ); pd3dImmediateContext->Draw( 6, 12 ); } DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); HRESULT hr; V(gHUD.OnRender( fElapsedTime )); V(gSampleUI.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(); }
VOID RenderTestObjects( ID3D11DeviceContext* pd3dImmediateContext, CXMMATRIX matVP ) { DXUT_BeginPerfEvent( 0, L"Frame Render" ); DXUTSetupD3D11Views( pd3dImmediateContext ); ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView(); ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView(); float ClearColor[4] = { 0, 0, 0, 1 }; pd3dImmediateContext->ClearRenderTargetView( pRTV, ClearColor ); pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 ); HRESULT hr; pd3dImmediateContext->IASetInputLayout( g_pDefaultInputLayout ); pd3dImmediateContext->VSSetShader( g_pVSTransform, NULL, 0 ); pd3dImmediateContext->PSSetSamplers( 0, 1, &g_pSamLinear ); FLOAT BlendFactor[4] = { 1, 1, 1, 1 }; pd3dImmediateContext->OMSetBlendState( g_pBlendState, BlendFactor, 0xFFFFFFFF ); pd3dImmediateContext->OMSetDepthStencilState( g_pDepthStencilState, 0 ); pd3dImmediateContext->RSSetState( g_pRasterizerState ); const UINT SceneObjectCount = (UINT)g_SceneObjects.size(); for( UINT i = 0; i < SceneObjectCount; ++i ) { DXUT_BeginPerfEvent( 0, L"Scene Object Render" ); SceneObject* pSO = g_SceneObjects[i]; pd3dImmediateContext->PSSetShader( pSO->pPixelShader, NULL, 0 ); D3D11_MAPPED_SUBRESOURCE MappedResource; V( pd3dImmediateContext->Map( g_pcbVSPerObject11, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ) ); CB_VS_PER_OBJECT* pVSPerObject = ( CB_VS_PER_OBJECT* )MappedResource.pData; XMMATRIX matWorld = XMLoadFloat4x4( &pSO->matWorld ); XMMATRIX matWVP = XMMatrixTranspose( matWorld * matVP ); XMStoreFloat4x4( (XMFLOAT4X4*)&pVSPerObject->m_mWorldViewProjection, matWVP ); pd3dImmediateContext->Unmap( g_pcbVSPerObject11, 0 ); pd3dImmediateContext->VSSetConstantBuffers( 0, 1, &g_pcbVSPerObject11 ); UINT Strides = { pSO->VertexStrideBytes }; UINT Offsets = { 0 }; pd3dImmediateContext->IASetVertexBuffers( 0, 1, &pSO->pVertexBuffer, &Strides, &Offsets ); pd3dImmediateContext->IASetPrimitiveTopology( pSO->PrimitiveType ); g_pd3dDeviceEx->PSSetShaderResources( 0, 1, &pSO->Textures[0].pTextureSRV ); UINT QualityShaderResourceSlot = 1; if( pSO->pPixelShader != g_pPSSceneRender ) { QualityShaderResourceSlot = 2; } ID3D11ShaderResourceView* pQualitySRV = pSO->Textures[0].pSamplingQualityManager->GetLODQualityTextureSRV(); pd3dImmediateContext->PSSetShaderResources( QualityShaderResourceSlot, 1, &pQualitySRV ); ID3D11SamplerState* pQualitySS = pSO->Textures[0].pSamplingQualityManager->GetSamplerState(); pd3dImmediateContext->PSSetSamplers( 1, 1, &pQualitySS ); if( pSO->pIndexBuffer != NULL ) { pd3dImmediateContext->IASetIndexBuffer( pSO->pIndexBuffer, DXGI_FORMAT_R16_UINT, 0 ); pd3dImmediateContext->DrawIndexed( pSO->IndexCount, 0, 0 ); } else { pd3dImmediateContext->Draw( pSO->VertexCount, 0 ); } DXUT_EndPerfEvent(); } DXUT_EndPerfEvent(); }