bool Run() { SkyBox.Render(); Renderer::camera->CameraMovement(); //DirectX::XMFLOAT4X4 matrix; //RenderSet* temp = &((RenderContext*)renderset->GetHead())->getRenderMaterials(); //((RenderShape*)temp->GetHead())->SetViewMatrix(Renderer::camera->viewMatrix); //((RenderShape*)temp->GetHead())->SetProjMatrix(Renderer::camera->projMatrix); Renderer::Render(renderset); //RenderShape::GetViewProjMatrix //float aspectRatio = 500.0f / 500.0f; // //camera->camera.viewMatrix = DirectX::XMMatrixIdentity(); //camera->camera.WorldMatrix = DirectX::XMMatrixIdentity(); //camera->camera.projMatrix = DirectX::XMMatrixPerspectiveFovLH(DirectX::XMConvertToRadians(75), aspectRatio, 0.1f, 1000.0f); Renderer::Present(); return true; }
//-------------------------------------------------------------------------------------- // 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(); }