VOID RenderHUD( ID3D11DeviceContext* pd3dImmediateContext, FLOAT fElapsedTime ) { DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); g_HUD.OnRender( fElapsedTime ); g_SampleUI.OnRender( fElapsedTime ); static FLOAT InspectionYOffset = 0; if( g_pInspectionTexture != NULL ) { const INT ViewportHeight = (INT)g_HalfClientHeightPixels * 2; INT TotalHeight = 0; INT SliceHeight = 0; g_PageDebugRender.Render( pd3dImmediateContext, g_pTitleResidencyManager, g_pInspectionTexture, 10, ViewportHeight - (INT)InspectionYOffset, &TotalHeight, &SliceHeight ); FLOAT fLerp = min( 1.0f, fElapsedTime * 8.0f ); FLOAT TargetOffset = (FLOAT)( SliceHeight * ( g_InspectionSliceIndex + 1 ) ); if( fabsf( TargetOffset - InspectionYOffset ) < 2.0f ) { InspectionYOffset = TargetOffset; } else { InspectionYOffset = ( TargetOffset * fLerp + (FLOAT)InspectionYOffset * ( 1.0f - fLerp ) ); } } else { InspectionYOffset = 0; g_InspectionSliceIndex = 0; } if( g_bDrawResidencySampleViews ) { ID3D11ShaderResourceView* pSRViewUVGradientID = NULL; ID3D11ShaderResourceView* pSRViewExtendedUVSlice = NULL; g_pTitleResidencyManager->GetViewShaderResources( g_LastResidencySampleViewID, &pSRViewUVGradientID, &pSRViewExtendedUVSlice ); if( pSRViewExtendedUVSlice != NULL && pSRViewUVGradientID != NULL ) { RECT ClientRect; GetClientRect( DXUTGetHWND(), &ClientRect ); UINT Width = 256; UINT Height = 144; UINT Margin = 10; UINT BottomMargin = 60 + Margin; RECT Rect2 = { ClientRect.right - ( Width + Margin ), ClientRect.bottom - ( Height + BottomMargin ), ClientRect.right - Margin, ClientRect.bottom - BottomMargin }; RECT Rect1 = { Rect2.left, Rect2.top - ( Height + Margin ), Rect2.right, Rect2.top - Margin }; g_PageDebugRender.RenderTexture( pd3dImmediateContext, pSRViewUVGradientID, Rect1 ); g_PageDebugRender.RenderTexture( pd3dImmediateContext, pSRViewExtendedUVSlice, Rect2 ); } } RenderText(); DXUT_EndPerfEvent(); }
void RenderArrows(float fElapsedTime) { WCHAR strWhite[MAX_PATH] = {26}; WCHAR strBlack[MAX_PATH] = {27}; CDXUTStatic* pStatic = NULL; pStatic = g_WhiteArrowDialog.GetStatic(IDC_WHITESCORE); if(pStatic != NULL) { pStatic->SetText(strWhite); } pStatic = g_BlackArrowDialog.GetStatic(IDC_BLACKSCORE); if(pStatic != NULL) { pStatic->SetText(strBlack); } if(!g_Board.pRenjuGame->bGameIsFinished) { if(g_Board.pRenjuGame->activeColor == White) { g_WhiteArrowDialog.OnRender(fElapsedTime); } if(g_Board.pRenjuGame->activeColor == Black) { g_BlackArrowDialog.OnRender(fElapsedTime); } } }
//-------------------------------------------------------------------------------------- // Render the scene using the D3D11 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime, FLOAT fElapsedTime, void* pUserContext ) { UNREFERENCED_PARAMETER(pUserContext); UNREFERENCED_PARAMETER(pd3dDevice); UNREFERENCED_PARAMETER(fTime); if( g_D3DSettingsDlg.IsActive() ) { g_D3DSettingsDlg.OnRender( fElapsedTime ); return; } auto pRTV = DXUTGetD3D11RenderTargetView(); // Clear color pd3dImmediateContext->ClearRenderTargetView( pRTV, Colors::DimGray ); // Start the frame g_Scene.InitFrame(&g_ViewerCamera, &g_LightCamera); // Draw Shadows g_Scene.RenderShadowCascades( &g_MeshPowerPlant ); // Render the GBuffer g_Scene.RenderGBuffer(&g_MeshPowerPlant); // Process the light linked list g_Scene.ProcessLinkedList(); // Composite the scene g_Scene.CompositeScene(pRTV); // Blended elements g_Scene.DrawAlpha(&g_TeapotMesh); // End the frame g_Scene.EndFrame(pRTV); // Hud { 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; pd3dImmediateContext->RSSetViewports( 1, &vp); pd3dImmediateContext->OMSetRenderTargets( 1, &pRTV, nullptr ); DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); g_HUD.OnRender( fElapsedTime ); g_SampleUI.OnRender( fElapsedTime ); RenderText(); DXUT_EndPerfEvent(); } }
//-------------------------------------------------------------------------------------- // This callback function will be called at the end of every frame to perform all the // rendering calls for the scene, and it will also be called if the window needs to be // repainted. After this function has returned, DXUT will call // IDirect3DDevice9::Present to display the contents of the next buffer in the swap chain //-------------------------------------------------------------------------------------- void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) { // 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; } HRESULT hr; D3DXMATRIXA16 mWorld; D3DXMATRIXA16 mView; D3DXMATRIXA16 mProj; D3DXMATRIXA16 mWorldViewProjection; // Clear the render target and the zbuffer V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 141, 153, 191 ), 1.0f, 0 ) ); // Render the scene if( SUCCEEDED( pd3dDevice->BeginScene() ) ) { // Get the projection & view matrix from the camera class mWorld = *g_Camera.GetWorldMatrix(); mView = *g_Camera.GetViewMatrix(); mProj = *g_Camera.GetProjMatrix(); mWorldViewProjection = mWorld * mView * mProj; // Update the effect's variables. V( g_pEffect->SetMatrix( g_hWorldViewProjection, &mWorldViewProjection ) ); V( g_pEffect->SetMatrix( g_hWorld, &mWorld ) ); V( g_pEffect->SetFloat( g_hTime, ( float )fTime ) ); V( g_pEffect->SetValue( g_hCameraPosition, g_Camera.GetEyePt(), sizeof( D3DXVECTOR3 ) ) ); UINT iCurSubset = ( UINT )( INT_PTR )g_SampleUI.GetComboBox( IDC_SUBSET )->GetSelectedData(); // A subset of -1 was arbitrarily chosen to represent all subsets if( iCurSubset == -1 ) { // Iterate through subsets, changing material properties for each for( UINT iSubset = 0; iSubset < g_MeshLoader.GetNumMaterials(); iSubset++ ) { RenderSubset( iSubset ); } } else { RenderSubset( iCurSubset ); } RenderText(); V( g_HUD.OnRender( fElapsedTime ) ); V( g_SampleUI.OnRender( fElapsedTime ) ); V( pd3dDevice->EndScene() ); } }
//-------------------------------------------------------------------------------------- // Render the scene using the D3D9 device //-------------------------------------------------------------------------------------- void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) { if( g_SettingsDlg.IsActive() ) { g_SettingsDlg.OnRender( fElapsedTime ); return; } HRESULT hr; D3DXMATRIXA16 mWorld; D3DXMATRIXA16 mView; D3DXMATRIXA16 mProj; D3DXMATRIXA16 mWorldViewProjection; // Clear the render target and the zbuffer V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 45, 50, 170 ), 1.0f, 0 ) ); // Render the scene if( SUCCEEDED( pd3dDevice->BeginScene() ) ) { // Get the projection & view matrix from the camera class mWorld = *g_Camera.GetWorldMatrix(); mProj = *g_Camera.GetProjMatrix(); mView = g_mView; mWorldViewProjection = mWorld * mView * mProj; // Update the effect's variables. Instead of using strings, it would // be more efficient to cache a handle to the parameter by calling // ID3DXEffect::GetParameterByName V( g_pEffect->SetMatrix( "g_mWorldViewProjection", &mWorldViewProjection ) ); V( g_pEffect->SetMatrix( "g_mWorld", &mWorld ) ); V( g_pEffect->SetFloat( "g_fTime", ( float )fTime ) ); g_pEffect->SetTechnique( "RenderScene" ); UINT cPasses; g_pEffect->Begin( &cPasses, 0 ); ID3DXMesh* pMesh = g_Mesh.GetMesh(); for( UINT p = 0; p < cPasses; ++p ) { g_pEffect->BeginPass( p ); for( UINT m = 0; m < g_Mesh.m_dwNumMaterials; ++m ) { g_pEffect->SetTexture( "g_txScene", g_Mesh.m_pTextures[m] ); g_pEffect->CommitChanges(); pMesh->DrawSubset( m ); } g_pEffect->EndPass(); } g_pEffect->End(); RenderText(); V( g_HUD.OnRender( fElapsedTime ) ); V( g_SampleUI.OnRender( fElapsedTime ) ); V( pd3dDevice->EndScene() ); } }
//-------------------------------------------------------------------------------------- // Render the scene using the D3D9 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) { HRESULT hr = S_OK; float ClearColor[4] = { 0,0,0,0 }; ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView(); pd3dDevice->ClearRenderTargetView( pRTV, ClearColor ); ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView(); pd3dDevice->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0 ); // 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; } // Render the scene { D3DXVECTOR4 vLightDir( -1,1,-1,1 ); D3DXVec4Normalize( &vLightDir, &vLightDir ); g_pvWorldLightDir->SetFloatVector( ( float* )&vLightDir ); g_pfTime->SetFloat( ( float )fTime ); g_pfElapsedTime->SetFloat( fElapsedTime ); VisibilityCullTiles(); DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"Render Sky" ); RenderSky( pd3dDevice ); DXUT_EndPerfEvent(); DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"Render Terrain" ); RenderTerrain( pd3dDevice ); DXUT_EndPerfEvent(); if( g_bRenderBalls ) { DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"Render Balls" ); RenderBalls( pd3dDevice ); DXUT_EndPerfEvent(); } if( g_bRenderGrass ) { DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"Render Grass" ); RenderGrass( pd3dDevice ); DXUT_EndPerfEvent(); } 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(); } }
//-------------------------------------------------------------------------------------- // This callback function will be called at the end of every frame to perform all the // rendering calls for the scene, and it will also be called if the window needs to be // repainted. After this function has returned, DXUT will call // IDirect3DDevice9::Present to display the contents of the next buffer in the swap chain //-------------------------------------------------------------------------------------- void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) { // 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; } HRESULT hr; // Clear the render target and the zbuffer V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 50, 50, 50 ), 1.0f, 0 ) ); // Render the scene if( SUCCEEDED( pd3dDevice->BeginScene() ) ) { // Get the projection & view matrix from the camera class D3DXMATRIXA16 mViewProjection = ( *g_Camera.GetViewMatrix() ) * ( *g_Camera.GetProjMatrix() ); g_Skybox.SetDrawSH( false ); g_Skybox.Render( &mViewProjection, 1.0f, 1.0f ); V( g_pEffect->SetMatrix( "g_mViewProjection", &mViewProjection ) ); V( g_pEffect->SetFloat( "g_fTime", ( float )fTime ) ); // Set the amount of transmitted light per color channel D3DXVECTOR3 vColorTransmit; vColorTransmit.x = g_SampleUI.GetSlider( IDC_RED_TRANSMIT_SLIDER )->GetValue() / 1000.0f; vColorTransmit.y = g_SampleUI.GetSlider( IDC_GREEN_TRANSMIT_SLIDER )->GetValue() / 1000.0f; vColorTransmit.z = g_SampleUI.GetSlider( IDC_BLUE_TRANSMIT_SLIDER )->GetValue() / 1000.0f; V( g_pEffect->SetFloatArray( "g_vColorTransmit", vColorTransmit, 3 ) ); // for Cubic degree rendering V( g_pEffect->SetFloat( "g_fLightIntensity", g_fLightIntensity ) ); V( g_pEffect->SetFloatArray( "g_vLightDirection", g_vLightDirection, 3 * sizeof( float ) ) ); V( g_pEffect->SetFloatArray( "g_vLightCoeffsR", m_fRLC, 4 * sizeof( float ) ) ); V( g_pEffect->SetFloatArray( "g_vLightCoeffsG", m_fGLC, 4 * sizeof( float ) ) ); V( g_pEffect->SetFloatArray( "g_vLightCoeffsB", m_fBLC, 4 * sizeof( float ) ) ); pd3dDevice->SetRenderState( D3DRS_FILLMODE, g_bWireFrame ? D3DFILL_WIREFRAME : D3DFILL_SOLID ); DrawFrame( pd3dDevice, g_pFrameRoot ); 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 ) ); V( g_LightControl.OnRender9( D3DXCOLOR( 1, 1, 1, 1 ), ( D3DXMATRIX* )g_Camera.GetViewMatrix(), ( D3DXMATRIX* )g_Camera.GetProjMatrix(), g_Camera.GetEyePt() ) ); DXUT_EndPerfEvent(); V( pd3dDevice->EndScene() ); } }
void drawHud(float elapsedTime) { HRESULT hr; D3DPERF_BeginEvent(D3DCOLOR_XRGB(0, 0, 0), L"HUD"); if (showHud) { V(hud.OnRender(elapsedTime)); txtHelper->Begin(); txtHelper->SetInsertionPos(2, 0); txtHelper->SetForegroundColor(D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f)); txtHelper->DrawTextLine(DXUTGetFrameStats(DXUTIsVsyncEnabled())); txtHelper->DrawTextLine(DXUTGetDeviceStats()); txtHelper->SetForegroundColor(D3DXCOLOR(1.0f, 0.5f, 0.0f, 1.0f)); if (timer->isEnabled()) { wstringstream s; s << setprecision(2) << std::fixed; s << *timer; txtHelper->DrawTextLine(s.str().c_str()); } txtHelper->End(); } D3DPERF_EndEvent(); }
//-------------------------------------------------------------------------------------- // Render the scene using the D3D9 device //-------------------------------------------------------------------------------------- void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) { // 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; } HRESULT hr; // Clear the render target and the zbuffer V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 45, 50, 70 ), 1.0f, 0 ) ); // Render the scene if( SUCCEEDED( pd3dDevice->BeginScene() ) ) { UINT iPass, cPasses; V( g_pEffect->Begin( &cPasses, 0 ) ); for( iPass = 0; iPass < cPasses; iPass++ ) { V( g_pEffect->BeginPass( iPass ) ); V( g_Mesh.Render( pd3dDevice ) ); g_pEffect->EndPass(); } g_pEffect->End(); RenderText(); V( g_HUD.OnRender( fElapsedTime ) ); V( pd3dDevice->EndScene() ); } }
//-------------------------------------------------------------------------------------- // Render the scene using the D3D9 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, 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_SettingsDlg.IsActive() ) { g_SettingsDlg.OnRender( fElapsedTime ); return; } // Clear the render target and the zbuffer V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 45, 50, 170 ), 1.0f, 0 ) ); // set active device SCEMAN->SetActiveDevice( pd3dDevice ); SCEMAN->SetProjectionMatrix( g_Camera.GetProjMatrix() ); SCEMAN->SetViewMatrix( g_Camera.GetViewMatrix() ); // call update SCEMAN->Update( (float) fElapsedTime ); // update auto-params SHAMAN->UpdateAutoShaderParameters( (float) fElapsedTime ); // Render the scene if( SUCCEEDED( pd3dDevice->BeginScene() ) ) { 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 ) ); SCEMAN->Render(); //PrintMatrix( &mWorld, L"World Mtx" ); //PrintMatrix( &mView, L"View Mtx" ); DXUT_EndPerfEvent(); V( pd3dDevice->EndScene() ); } }
//-------------------------------------------------------------------------------------- // Render the scene using the D3D9 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) { HRESULT hr; D3DXMATRIXA16 mWorld; D3DXMATRIXA16 mView; D3DXMATRIXA16 mProj; D3DXMATRIXA16 mWorldViewProjection; // 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; } // Clear the render target and the zbuffer V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 45, 50, 170 ), 1.0f, 0 ) ); // Render the scene if( SUCCEEDED( pd3dDevice->BeginScene() ) ) { // Get the projection & view matrix from the camera class mWorld = *g_Camera.GetWorldMatrix(); mProj = *g_Camera.GetProjMatrix(); mView = *g_Camera.GetViewMatrix(); mWorldViewProjection = mWorld * mView * mProj; // Update the effect's variables. Instead of using strings, it would // be more efficient to cache a handle to the parameter by calling // ID3DXEffect::GetParameterByName V( g_pEffect9->SetMatrix( g_hmWorldViewProjection, &mWorldViewProjection ) ); V( g_pEffect9->SetMatrix( g_hmWorld, &mWorld ) ); V( g_pEffect9->SetFloat( g_hfTime, ( float )fTime ) ); 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 ) { // 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; } auto pRTV = DXUTGetD3D11RenderTargetView(); pd3dImmediateContext->ClearRenderTargetView( pRTV, Colors::MidnightBlue ); // Clear the depth stencil 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 mView = g_Camera.GetViewMatrix(); XMMATRIX mProj = g_Camera.GetProjMatrix(); g_BatchEffect->SetWorld( mWorld ); g_BatchEffect->SetView( mView ); g_BatchEffect->SetProjection( mProj ); // Draw objects RenderObjects(); // Render HUD DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); g_HUD.OnRender( fElapsedTime ); g_SampleUI.OnRender( fElapsedTime ); RenderText(); DXUT_EndPerfEvent(); static ULONGLONG timefirst = GetTickCount64(); if ( GetTickCount64() - timefirst > 5000 ) { OutputDebugString( DXUTGetFrameStats( DXUTIsVsyncEnabled() ) ); OutputDebugString( L"\n" ); timefirst = GetTickCount64(); } }
//-------------------------------------------------------------------------------------- // 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 D3D9 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) { HRESULT hr; D3DXMATRIXA16 mWorld; D3DXMATRIXA16 mView; D3DXMATRIXA16 mProj; D3DXMATRIXA16 mWorldViewProjection; // Clear the render target and the zbuffer V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 120, 120, 120 ), 1.0f, 0 ) ); // Render the scene if( SUCCEEDED( pd3dDevice->BeginScene() ) ) { //world transformations pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE); pd3dDevice->SetTransform( D3DTS_PROJECTION, &camera->getProjMatrix() ); pd3dDevice->SetTransform( D3DTS_VIEW, &camera->getViewMatrix() ); //render manipulator manipulator->Render(pd3dDevice); //MENU AND HUD D3DRECT stripe = D3DRECT(clearRect); stripe.x1 = stripe.x1-2; V( pd3dDevice->Clear(1, &stripe, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 40, 40, 40), 1.0f, 0) ); V( pd3dDevice->Clear(1, &clearRect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 100, 100, 100), 1.0f, 0) ); V( g_HUD.OnRender( fElapsedTime ) ); V( g_SampleUI.OnRender( fElapsedTime ) ); V( pd3dDevice->EndScene() ); } }
void RenderWinner(float fElapsedTime) { if(g_Board.pRenjuGame->winner == Black) { WCHAR strMessage[MAX_PATH] = L"The Black have won!"; CDXUTStatic* pStatic = NULL; CDXUTElement* pElement = NULL; pStatic = g_TheBlackWinnerDialog.GetStatic(IDC_THE_BLACK_WINNER_DIALOG); if(pStatic != NULL) { pStatic->SetText(strMessage); } pElement = g_TheBlackWinnerDialog.GetDefaultElement(DXUT_CONTROL_STATIC, 0); pElement->FontColor.Init(D3DCOLOR_ARGB(255, 255, 255, 255)); g_TheBlackWinnerDialog.OnRender(fElapsedTime); } else { if(g_Board.pRenjuGame->winner == White) { WCHAR strMessage[MAX_PATH] = L"The White have won!"; CDXUTStatic* pStatic = NULL; CDXUTElement* pElement = NULL; pStatic = g_TheWhiteWinnerDialog.GetStatic(IDC_THE_WHITE_WINNER_DIALOG); if(pStatic != NULL) { pStatic->SetText(strMessage); } pElement = g_TheWhiteWinnerDialog.GetDefaultElement(DXUT_CONTROL_STATIC, 0); pElement->FontColor.Init(D3DCOLOR_ARGB(255, 0, 0, 0)); g_TheWhiteWinnerDialog.OnRender(fElapsedTime); } } }
//-------------------------------------------------------------------------------------- // Render the scene using the D3D11 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D11FrameRender(ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double /*fTime*/, float fElapsedTime, void* /*pUserContext*/) { // 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; } // Get the projection & view matrix from the camera class XMMATRIX mWorld; XMMATRIX mView; XMMATRIX mProj; XMMATRIX mWorldViewProjection; mWorld = g_Camera.GetWorldMatrix(); mView = g_Camera.GetViewMatrix(); mProj = g_Camera.GetProjMatrix(); mWorldViewProjection = mWorld * mView * mProj; // Store off original render target and depth/stencil ID3D11RenderTargetView* pOrigRTV = NULL; ID3D11DepthStencilView* pOrigDSV = NULL; pd3dImmediateContext->OMGetRenderTargets(1, &pOrigRTV, &pOrigDSV); g_OIT.Render(pd3dImmediateContext, pd3dDevice, &g_Scene, mWorldViewProjection, pOrigRTV, pOrigDSV); pd3dImmediateContext->OMSetRenderTargets(1, &pOrigRTV, pOrigDSV); // Restore original render targets, and then draw UI SAFE_RELEASE(pOrigRTV); SAFE_RELEASE(pOrigDSV); DXUT_BeginPerfEvent(DXUT_PERFEVENTCOLOR, L"HUD / Stats"); g_HUD.OnRender(fElapsedTime); g_SampleUI.OnRender(fElapsedTime); RenderText(); DXUT_EndPerfEvent(); }
//-------------------------------------------------------------------------------------- // 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() ); } }
void CALLBACK OnFrameRender(IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext) { HRESULT hr; V(pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 33, 64, 145), 1.0f, 0)); if(SUCCEEDED(pd3dDevice->BeginScene())) { g_BackgroundQuad.Render(); g_Board.Render(pd3dDevice); RenderArrows(fElapsedTime); RenderWinner(fElapsedTime); DXUT_BeginPerfEvent(DXUT_PERFEVENTCOLOR, L"HUD / Stats"); //RenderText(); V(g_HUD.OnRender(fElapsedTime)); V(g_SampleUI.OnRender(fElapsedTime)); DXUT_EndPerfEvent(); V(pd3dDevice->EndScene()); } }
//-------------------------------------------------------------------------------------- // Callback function that renders the frame. This function sets up the rendering // matrices and renders the scene and UI. //-------------------------------------------------------------------------------------- void CALLBACK OnD3D11FrameRender(ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime, float fElapsedTime, void* pUserContext) { // 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; } // Reallocate the render targets and depth buffer if the MSAA mode has been changed in the GUI. if (g_RenderTargetsDirty) { g_RenderTargetsDirty = false; ResizeScreenSizedBuffers(pd3dDevice); } SceneMesh *pMesh = g_Scenes[g_CurrentSceneId].pMesh; g_AOParams.UseDeinterleavedTexturing = g_UseDeinterleavedTexturing; g_AOParams.RandomizeSamples = g_RandomizeSamples; g_AOParams.Blur.Enable = g_BlurAO; ID3D11RenderTargetView* pBackBufferRTV = DXUTGetD3D11RenderTargetView(); // does not addref if (pMesh) { RenderAOFromMesh(pd3dDevice, pd3dImmediateContext, pBackBufferRTV, pMesh); } //-------------------------------------------------------------------------------------- // Render the GUI //-------------------------------------------------------------------------------------- if (g_DrawUI) { g_HUD.OnRender(fElapsedTime); g_TextRenderer.OnRender(fElapsedTime); } }
void CALLBACK on_render(ID3D11Device* device, ID3D11DeviceContext* context, double fTime, float fElapsedTime, void* pUserContext) { if (!enabled) return; // get FPS dune::tstringstream ss; ss << DXUTGetFPS() << L"(" << std::setprecision(2) << DXUTGetElapsedTime() * 1000 << L"ms)" << std::endl; hud.GetStatic(IDC_FPS_COUNTER)->SetText(ss.str().c_str()); for (size_t i = 0; i < dlg_manager.m_Dialogs.size(); ++i) { auto h = dlg_manager.m_Dialogs[i]; // make sure HUD is rendered last if (h != &hud) h->OnRender(fElapsedTime); } hud.OnRender(fElapsedTime); }
//-------------------------------------------------------------------------------------- // Render the scene using the D3D11 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime, float fElapsedTime, void* pUserContext ) { //float ms = getDeltaTimeMicroseconds(); btScalar dt = (btScalar)m_clock.getTimeMicroseconds(); m_clock.reset(); ///step the simulation if (m_dynamicsWorld && !paused) { m_dynamicsWorld->stepSimulation(dt / 1000000.f); updatePhysicsWorld(); } //paused = 1; /////////////////////////////////////////////////////// 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 float ClearColor[4] = { 0.0f, 0.25f, 0.25f, 0.55f }; ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView(); pd3dImmediateContext->ClearRenderTargetView( pRTV, ClearColor ); ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView(); pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 ); for( int flagIndex = 0; flagIndex < m_flags.size(); ++flagIndex ) { g_softBodyOutput->copySoftBodyToVertexBuffer( m_flags[flagIndex], cloths[flagIndex].m_vertexBufferDescriptor ); cloths[flagIndex].draw(); } my_capsule.draw(); DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); g_HUD.OnRender( fElapsedTime ); g_SampleUI.OnRender( fElapsedTime ); RenderText(); DXUT_EndPerfEvent(); /* SAFE_RELEASE(pRTV); SAFE_RELEASE(pDSV); */ }
//-------------------------------------------------------------------------------------- // 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 ) { // 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; } // WVP XMMATRIX mProj = g_Camera.GetProjMatrix(); XMMATRIX mView = g_Camera.GetViewMatrix(); XMMATRIX mViewProjection = mView * mProj; // Update per-frame variables D3D11_MAPPED_SUBRESOURCE MappedResource; pd3dImmediateContext->Map( g_pcbPerFrame, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ); auto pData = reinterpret_cast<CB_PER_FRAME_CONSTANTS*>( MappedResource.pData ); XMStoreFloat4x4( &pData->mViewProjection, XMMatrixTranspose( mViewProjection ) ); XMStoreFloat3( &pData->vCameraPosWorld, g_Camera.GetEyePt() ); pData->fTessellationFactor = (float)g_fSubdivs; pd3dImmediateContext->Unmap( g_pcbPerFrame, 0 ); // Clear the render target and depth stencil auto pRTV = DXUTGetD3D11RenderTargetView(); pd3dImmediateContext->ClearRenderTargetView( pRTV, Colors::Black ); auto pDSV = DXUTGetD3D11DepthStencilView(); pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 ); // Set state for solid rendering pd3dImmediateContext->RSSetState( g_pRasterizerStateSolid ); // Render the meshes // Bind all of the CBs pd3dImmediateContext->VSSetConstantBuffers( g_iBindPerFrame, 1, &g_pcbPerFrame ); pd3dImmediateContext->HSSetConstantBuffers( g_iBindPerFrame, 1, &g_pcbPerFrame ); pd3dImmediateContext->DSSetConstantBuffers( g_iBindPerFrame, 1, &g_pcbPerFrame ); pd3dImmediateContext->PSSetConstantBuffers( g_iBindPerFrame, 1, &g_pcbPerFrame ); // Set the shaders pd3dImmediateContext->VSSetShader( g_pVertexShader, nullptr, 0 ); // For this sample, choose either the "integer", "fractional_even", // or "fractional_odd" hull shader if (g_iPartitionMode == PARTITION_INTEGER) pd3dImmediateContext->HSSetShader( g_pHullShaderInteger, nullptr, 0 ); else if (g_iPartitionMode == PARTITION_FRACTIONAL_EVEN) pd3dImmediateContext->HSSetShader( g_pHullShaderFracEven, nullptr, 0 ); else if (g_iPartitionMode == PARTITION_FRACTIONAL_ODD) pd3dImmediateContext->HSSetShader( g_pHullShaderFracOdd, nullptr, 0 ); pd3dImmediateContext->DSSetShader( g_pDomainShader, nullptr, 0 ); pd3dImmediateContext->GSSetShader( nullptr, nullptr, 0 ); pd3dImmediateContext->PSSetShader( g_pPixelShader, nullptr, 0 ); // Optionally draw the wireframe if( g_bDrawWires ) { pd3dImmediateContext->PSSetShader( g_pSolidColorPS, nullptr, 0 ); pd3dImmediateContext->RSSetState( g_pRasterizerStateWireframe ); } // Set the input assembler // This sample uses patches with 16 control points each // Although the Mobius strip only needs to use a vertex buffer, // you can use an index buffer as well by calling IASetIndexBuffer(). pd3dImmediateContext->IASetInputLayout( g_pPatchLayout ); UINT Stride = sizeof( BEZIER_CONTROL_POINT ); UINT Offset = 0; pd3dImmediateContext->IASetVertexBuffers( 0, 1, &g_pControlPointVB, &Stride, &Offset ); pd3dImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_16_CONTROL_POINT_PATCHLIST ); // Draw the mesh pd3dImmediateContext->Draw( ARRAYSIZE(g_MobiusStrip), 0 ); pd3dImmediateContext->RSSetState( g_pRasterizerStateSolid ); // Render the HUD DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); g_HUD.OnRender( fElapsedTime ); g_SampleUI.OnRender( fElapsedTime ); RenderText(); DXUT_EndPerfEvent(); }
//-------------------------------------------------------------------------------------- // This callback function will be called at the end of every frame to perform all the // rendering calls for the scene, and it will also be called if the window needs to be // repainted. After this function has returned, DXUT will call // IDirect3DDevice9::Present to display the contents of the next buffer in the swap chain //-------------------------------------------------------------------------------------- void CALLBACK OnFrameRender(IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext) { PERF_NODE_FUNC(); HRESULT hr; float *pVertex = NULL; V(g_pVbFloor->Lock(0, 0, (void**)&pVertex, 0)); //移动地板纹理 for (int i = 0; i < 6; ++i) { g_aVertexFloor[i*5+4] += (g_fCurSpeed * fElapsedTime * g_fTimeScale / FLOOR_SIZE * 1.8f); } memcpy(pVertex, g_aVertexFloor, sizeof(g_aVertexFloor)); V(g_pVbFloor->Unlock()); D3DXMATRIXA16 mWorldViewProjection; D3DXMATRIXA16 mWorld; D3DXMATRIXA16 mView; D3DXMATRIXA16 mProj; UINT iPass, cPasses; // Clear the render target and the zbuffer V(pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DXCOLOR(0.3f,0.3f,0.6f,0.5f), 1.0f, 0)); // Render the scene if(SUCCEEDED(pd3dDevice->BeginScene())) { // Get the projection & view matrix from the camera class mProj = reinterpret_cast<const D3DXMATRIXA16&>(g_camera.getProjectionMatrix()); mView = reinterpret_cast<const D3DXMATRIXA16&>(g_camera.getViewMatrix()); pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); pd3dDevice->SetRenderState(D3DRS_ALPHAREF, (DWORD)0x00000080); pd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); if (g_SampleUI.GetCheckBox(IDC_CHECK_WIREFRAME)->GetChecked()) { pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); } else { pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); } //地板,采用不同变换 D3DXMATRIXA16 coordMatrix; memset(&coordMatrix, 0, sizeof(D3DXMATRIXA16)); coordMatrix._11 = 1.0f; coordMatrix._23 = 1.0f; coordMatrix._32 = 1.0f; coordMatrix._44 = 1.0f; V(g_pEffect->SetMatrix("g_mWorldViewProjection", &(coordMatrix*mView*mProj))); V(g_pEffect->SetMatrix("g_mWorld", &coordMatrix)); V(pd3dDevice->SetVertexDeclaration(g_pVdFloor)); V(pd3dDevice->SetStreamSource(0, g_pVbFloor, 0, 20)); V(g_pEffect->SetTexture("g_texDiffuse", g_pTexFloor)); V(g_pEffect->SetTechnique("NoLight")); V(g_pEffect->Begin(&cPasses, 0)); for (iPass = 0; iPass < cPasses; iPass++) { V(g_pEffect->BeginPass(iPass)); V(pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2)); V(g_pEffect->EndPass()); } V(g_pEffect->End()); //角色 if (g_character->isGpuSkinning()) { V(pd3dDevice->SetVertexDeclaration(g_pVdMeshGpuSkinning)); } else { V(pd3dDevice->SetVertexDeclaration(g_pVdMesh)); } V(g_pEffect->SetValue("g_vCameraPos", &g_camera.getEyePos(), sizeof(grp::Vector3))); //g_vLightDir = D3DXVECTOR3(cosf(fTime), sinf(fTime), 0.0f); V(g_pEffect->SetValue("g_vLightDir", &g_vLightDir, sizeof(D3DXVECTOR3))); V(g_pEffect->SetBool("g_bDiffuse", g_SampleUI.GetCheckBox(IDC_CHECK_DIFFUSEMAP)->GetChecked())); V(g_pEffect->SetBool("g_bGloss", g_SampleUI.GetCheckBox(IDC_CHECK_GLOSS)->GetChecked())); if (g_SampleUI.GetCheckBox(IDC_CHECK_NORMALMAP)->GetChecked()) { if (g_character->isGpuSkinning()) { V(g_pEffect->SetTechnique("Normalmap_Gpu_Skinning")); } else { V(g_pEffect->SetTechnique("Normalmap")); } } else { if (g_character->isGpuSkinning()) { V(g_pEffect->SetTechnique("VertexLight_Gpu_Skinning")); } else { V(g_pEffect->SetTechnique("VertexLight")); } } if (g_character != NULL) { bool drawNormal = g_SampleUI.GetCheckBox(IDC_CHECK_DRAW_NORMAL)->GetChecked(); bool drawSkeleton = g_SampleUI.GetCheckBox(IDC_CHECK_DRAW_SKELETON)->GetChecked(); bool drawBoundingBox = g_SampleUI.GetCheckBox(IDC_CHECK_DRAW_BOUNDINGBOX)->GetChecked(); if (!drawSkeleton || g_SampleUI.GetCheckBox(IDC_CHECK_WIREFRAME)->GetChecked()) { UINT cPasses; g_pEffect->Begin(&cPasses, 0); g_character->render(g_pEffect, mView, mProj); g_pEffect->End(); } if (drawNormal) { g_character->renderNormal(mView, mProj); } if (drawBoundingBox) { g_character->renderBoundingBox(mView, mProj); } if (drawSkeleton) { g_character->renderSkeleton(mView, mProj); } } if (g_bShowHelp) { g_SampleUI.OnRender(fElapsedTime); } RenderText(fTime); V(pd3dDevice->EndScene()); } }
//-------------------------------------------------------------------------------------- // Render the scene using the D3D10 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) { // 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 back buffer // float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; // red, green, blue, alpha ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView(); pd3dDevice->ClearRenderTargetView( pRTV, ClearColor ); // // Clear the depth stencil // ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView(); pd3dDevice->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0 ); // // Update variables that change once per frame // g_pProjectionVariable->SetMatrix( ( float* )g_Camera.GetProjMatrix() ); g_pViewVariable->SetMatrix( ( float* )g_Camera.GetViewMatrix() ); g_pWorldVariable->SetMatrix( ( float* )&g_World ); // // Set the Vertex Layout // pd3dDevice->IASetInputLayout( g_pVertexLayout ); // // Render the mesh // UINT Strides[1]; UINT Offsets[1]; ID3D10Buffer* pVB[1]; pVB[0] = g_Mesh.GetVB10( 0, 0 ); Strides[0] = ( UINT )g_Mesh.GetVertexStride( 0, 0 ); Offsets[0] = 0; pd3dDevice->IASetVertexBuffers( 0, 1, pVB, Strides, Offsets ); pd3dDevice->IASetIndexBuffer( g_Mesh.GetIB10( 0 ), g_Mesh.GetIBFormat10( 0 ), 0 ); D3D10_TECHNIQUE_DESC techDesc; g_pTechnique->GetDesc( &techDesc ); SDKMESH_SUBSET* pSubset = NULL; ID3D10ShaderResourceView* pDiffuseRV = NULL; D3D10_PRIMITIVE_TOPOLOGY PrimType; for( UINT p = 0; p < techDesc.Passes; ++p ) { for( UINT subset = 0; subset < g_Mesh.GetNumSubsets( 0 ); ++subset ) { pSubset = g_Mesh.GetSubset( 0, subset ); PrimType = g_Mesh.GetPrimitiveType10( ( SDKMESH_PRIMITIVE_TYPE )pSubset->PrimitiveType ); pd3dDevice->IASetPrimitiveTopology( PrimType ); pDiffuseRV = g_Mesh.GetMaterial( pSubset->MaterialID )->pDiffuseRV10; g_ptxDiffuseVariable->SetResource( pDiffuseRV ); g_pTechnique->GetPassByIndex( p )->Apply( 0 ); pd3dDevice->DrawIndexed( ( UINT )pSubset->IndexCount, 0, ( UINT )pSubset->VertexStart ); } } //the mesh class also had a render method that allows rendering the mesh with the most common options //g_Mesh.Render( pd3dDevice, g_pTechnique, g_ptxDiffuseVariable ); // // Render the UI // g_HUD.OnRender( fElapsedTime ); g_SampleUI.OnRender( fElapsedTime ); RenderText(); }
//-------------------------------------------------------------------------------------- // Render the scene using the D3D9 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) { HRESULT hr; D3DXMATRIXA16 mWorld; D3DXMATRIXA16 mView; D3DXMATRIXA16 mProj; D3DXMATRIXA16 mWorldViewProjection; // 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; } // Clear the render target and the zbuffer V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 0, 0, 0 ), 1.0f, 0 ) ); //V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE( 0.0f, 0.0f, 0.0f, 1.0f ), 1.0f, 0 ) ); // Render the scene if( SUCCEEDED( pd3dDevice->BeginScene() ) ) { // Get the projection & view matrix from the camera class //mWorld = *g_Camera.GetWorldMatrix(); mProj = *g_Camera.GetProjMatrix(); mView = *g_Camera.GetViewMatrix(); D3DXMatrixIdentity(&mWorld); //mWorldViewProjection = mWorld * mView * mProj; //* pd3dDevice->SetTransform(D3DTS_WORLD, &mWorld); pd3dDevice->SetTransform(D3DTS_VIEW, &mView); pd3dDevice->SetTransform(D3DTS_PROJECTION, &mProj); //*/ /* pd3dDevice->SetTransform(D3DTS_PROJECTION, &g_pCamera->m_mProj); pd3dDevice->SetTransform(D3DTS_VIEW, &g_pCamera->m_mView); pd3dDevice->SetTransform(D3DTS_WORLD, &mWorld); //*/ // Update the effect's variables. Instead of using strings, it would // be more efficient to cache a handle to the parameter by calling // ID3DXEffect::GetParameterByName /* V( g_pEffect9->SetMatrix( "g_mWorldViewProjection", &mWorldViewProjection ) ); V( g_pEffect9->SetMatrix( "g_mWorld", &mWorld ) ); V( g_pEffect9->SetFloat( "g_fTime", ( float )fTime ) ); */ pd3dDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_COLORVALUE( 0.8f, 0.8f, 0.8f, 1.0f )); pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, false ); pd3dDevice->SetRenderState( D3DRS_COLORVERTEX, true ); DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"Draw scene" ); particleSystem.render(); DXUT_EndPerfEvent(); 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 D3D10 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D10FrameRender(ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext) { HRESULT hr; g_device->ClearRenderTargetView(g_vsObj->m_TextureTV, D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f)); g_device->ClearRenderTargetView(g_vsObj->m_diffuseTextureTV[0], D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f)); g_device->ClearRenderTargetView(g_vsObj->m_diffuseTextureTV[1], D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f)); g_device->ClearRenderTargetView(g_vsObj->m_otherTextureTV, D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f)); g_device->ClearRenderTargetView(g_vsObj->m_distDirTextureTV, D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f)); // 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_Camera.m_nMouseWheelDelta && g_Camera.m_nZoomButtonMask == MOUSE_WHEEL) { g_vsObj->m_pan /= g_vsObj->m_scale; g_vsObj->m_scale += g_vsObj->m_scale * g_Camera.m_nMouseWheelDelta * 0.2; g_vsObj->m_pan *= g_vsObj->m_scale; g_Camera.m_nMouseWheelDelta = 0; g_vsObj->m_scale = max(0.01, g_vsObj->m_scale); } if ((!g_Camera.IsMouseRButtonDown()) && (g_mouseLButtonDown == true)) { g_mouseLButtonDown = false; } else if (g_Camera.IsMouseRButtonDown()) { g_mouseLButtonDown = true; } else { g_mouseLButtonDown = false; } if (g_Camera.IsBeingDragged()) { float ff = 1.0f; if (g_Camera.IsMouseRButtonDown()) { ff = 0.127f; } float xFac = ff * 4.0f / g_vsObj->m_sizeX; float yFac = ff * 4.0f / g_vsObj->m_sizeY; g_vsObj->m_pan += D3DXVECTOR2(xFac * g_Camera.m_vMouseDelta.x, -yFac * g_Camera.m_vMouseDelta.y); g_Camera.m_vMouseDelta.x = 0; g_Camera.m_vMouseDelta.y = 0; } //g_vsObj->m_polySize = 0.1; //render each polygon in full screen size g_vsObj->RenderDiffusion(pd3dDevice); g_vsObj->Render(pd3dDevice); if (g_showMenue) { 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 ) { 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(); }
//-------------------------------------------------------------------------------------- void CALLBACK OnD3D10FrameRender(ID3D10Device* pDev10, double fTime, float fElapsedTime, void* pUserContext) { HRESULT hr; g_pCamManager->SyncToCameraUI(g_CameraUI); //dont delete, used no only here const DXGI_SURFACE_DESC *pBackBufferSurfaceDesc = DXUTGetDXGIBackBufferSurfaceDesc(); if( ShadowAlgorithm != OldShadowAlgorithm ) { OldShadowAlgorithm = ShadowAlgorithm; switch( ShadowAlgorithm ) { case STANDARD_BP: g_ABP.OnD3D10DestroyDevice(); break; case BP_MSSM_KERNEL: g_BPMSSMKernel.OnD3D10DestroyDevice(); break; case STD_VSM: g_StdVSM.OnD3D10DestroyDevice(); break; case MIP_VSM: g_MipVSM.OnD3D10DestroyDevice(); break; case HIR_BP: g_HBP.OnD3D10DestroyDevice(); break; case BP_GI: g_BPGI.OnD3D10DestroyDevice(); break; case STD_PCSS: g_PCSS.OnD3D10DestroyDevice(); break; default: break; }; switch( ShadowAlgorithm ) { case STANDARD_BP: g_ABP.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext); g_ABP.OnD3D10SwapChainResized(pDev10,NULL,pBackBufferSurfaceDesc,pUserContext ); break; case BP_MSSM_KERNEL: g_BPMSSMKernel.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext); g_BPMSSMKernel.OnD3D10SwapChainResized(pDev10,NULL,pBackBufferSurfaceDesc,pUserContext ); break; case STD_VSM: g_StdVSM.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext); g_StdVSM.OnD3D10SwapChainResized(pDev10,NULL,pBackBufferSurfaceDesc,pUserContext ); break; case MIP_VSM: g_MipVSM.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext); g_MipVSM.OnD3D10SwapChainResized(pDev10,NULL,pBackBufferSurfaceDesc,pUserContext ); break; case HIR_BP: g_HBP.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext); g_HBP.OnD3D10SwapChainResized(pDev10,NULL,pBackBufferSurfaceDesc,pUserContext ); break; case BP_GI: g_BPGI.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext); g_BPGI.OnD3D10SwapChainResized(pDev10,NULL,pBackBufferSurfaceDesc,pUserContext ); break; case STD_PCSS: g_PCSS.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext); g_PCSS.OnD3D10SwapChainResized(pDev10,NULL,pBackBufferSurfaceDesc,pUserContext ); break; default: break; }; } //begin light and view pos management { static double old_fTime = 0.001; fTime = old_fTime; old_fTime += 0.02; static double oldTime = 0; static unsigned old_iSta = 0; static double stop_time = 0; static double total_stop_time = 0; double tmp = fTime; unsigned iSta = g_SampleUI.GetCheckBox(IDC_STATIC)->GetChecked(); if( 0 == old_iSta && 1 == iSta )//turn to be static { stop_time = fTime - total_stop_time; } if( 1 == iSta ) { total_stop_time += ( fTime - oldTime ); fTime = stop_time; } if( 0 == iSta ) { fTime -= total_stop_time; } old_iSta = iSta; oldTime = tmp; }//end light and view pos management S3UTCamera& g_CameraRef = *(g_pCamManager->ActiveEye()); // compute view matrix D3DXMATRIX mTmp, mWorldView, mWorldViewProj, mWorldViewInv; D3DXMatrixInverse(&mTmp, NULL, g_CameraRef.GetWorldMatrix()); D3DXMatrixMultiply(&mWorldView, &mTmp, g_CameraRef.GetViewMatrix()); // correct near/far clip planes according to camera location D3DXVECTOR3 vBox[2]; float fAspectRatio = pBackBufferSurfaceDesc->Width / (FLOAT)pBackBufferSurfaceDesc->Height; // clear depth and color ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView(); pDev10->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0); ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView(); if( g_D3DSettingsDlg.IsActive() ) { g_D3DSettingsDlg.OnRender( fElapsedTime ); return; } Parameters para; para.fLightZn = g_fCtrledLightZn; float biases[15]; biases[0] = g_fDepthBiasObject0; biases[1] = g_fDefaultDepthBias; biases[2] = g_fDepthBiasHammer; biases[3] = g_fDepthBiasLeftForearm; biases[4] = g_fDepthBiasRightForearm; biases[5] = g_fDepthBiasLeftShoulder; biases[6] = g_fDepthBiasRightShoulder; biases[7] = g_fDepthBiasBlackPlate; biases[8] = g_fDepthBiasHelmet; biases[9] = g_fDepthBiasEyes; biases[10] = g_fDepthBiasBelt; biases[11] = g_fDepthBiasLeftThigh; biases[12] = g_fDepthBiasRightThigh; biases[13] = g_fDepthBiasLeftShin; biases[14] = g_fDepthBiasRightShin; g_MeshScene.set_biases(biases,15); float light_size[NUM_LIGHT] = LIGHT_SIZE; float light_ZNS[NUM_LIGHT] = LIGHT_ZNS; float light_view_angle[NUM_LIGHT] = LIGHT_VIEW_ANGLES; D3DXVECTOR4 light_color[NUM_LIGHT] = LIGHT_COLOR; bool render_ogre = g_SampleUI.GetCheckBox( IDC_ANIMATE )->GetChecked(); bool render_scene = g_SampleUI.GetCheckBox( IDC_SCENE )->GetChecked(); bool render_fan = g_SampleUI.GetCheckBox( IDC_FAN )->GetChecked(); float ClearColor[4] = { 0, 0, 0, 1 }; pDev10->ClearRenderTargetView(g_pBlendBuffer->m_pRTView, ClearColor); //use alpha val 1 to represent untouched pixels pDev10->ClearRenderTargetView(g_pWidgetBuffer->m_pRTView, ClearColor); //light management ID3D10RenderTargetView *p_RTV; ID3D10ShaderResourceView *p_SRV; static float light_scale_factor = 0.2; static float ls_incre = 0.04; if( g_LightVary == true || g_fFilterSize < g_fFilterSizeCtrl ) { g_fFilterSize -= ls_incre; if( g_fFilterSize < 0.1 || g_fFilterSize > g_fFilterSizeCtrl ) ls_incre = -ls_incre; } else { g_fFilterSize = g_fFilterSizeCtrl; } g_fFilterSize = g_fFilterSizeCtrl; //light pos is not modified here. this light pos stored in 3DWidget is only synced with light camera after rendering of the light //if you try to modify light pos here, light would be freezed, of course, this is a bug introduced by bad design D3DXVECTOR3 vTmp; // render GBuffer pDev10->OMSetDepthStencilState(g_pDSState,0); g_GBuffer.OnD3D10FrameRender( true, true, g_SampleUI, g_MeshScene, g_CameraRef, pDev10, fTime, fElapsedTime, pUserContext ); g_Blender.OriginalSampleMask = 0; pDev10->OMGetBlendState( &g_Blender.pOriginalBlendState, g_Blender.OriginalBlendFactor, &g_Blender.OriginalSampleMask ); float BlendBufferClearColor[4] = { 1, 1, 0, 1 }; bool isFirstPass = true; for( int cam_idx = 0; cam_idx < g_pCamManager->CameraCount(); ++cam_idx ) { // rendering a subdivided light if( g_pCamManager->Camera(cam_idx)->GetCamType() == S3UTCamera::eLight&& g_pCamManager->Camera(cam_idx)->IsActive() ) { float scaled_half_light_size = (g_pCamManager->Camera(cam_idx)->GetLightSize()*LIGHT_SCALE_FACTOR); float fStartPt = -scaled_half_light_size; float fInterval = 2 * scaled_half_light_size / g_nNumLightSample; float fSubLightSize = g_pCamManager->Camera(cam_idx)->GetLightSize(); if( g_nNumLightSample > 0 ) { fSubLightSize = fSubLightSize / g_nNumLightSample; } if( g_nNumLightSample == 0 ) { g_nNumLightSample = 1; } static float total_light_x_incre = 0; static int light_mov_dir = 0; float shadow_factor = 0.8/(g_nNumLightSample * g_nNumLightSample); for( int ix = 0; ix < g_nNumLightSample; ++ix ) { for( int iy = 0; iy < g_nNumLightSample; ++iy ) { D3DXVECTOR3 vLight = *g_pCamManager->Camera(cam_idx)->GetEyePt(); S3UTCamera local_cam = *g_pCamManager->Camera(cam_idx); D3DXVECTOR3 vTrans( fStartPt+(ix+0.5)*fInterval,fStartPt+(iy+0.5)*fInterval,0 ); if( g_nNumLightSample == 1 ) { vTrans = D3DXVECTOR3(0,0,0); } D3DXMATRIX mInvLightView; D3DXVECTOR4 tmp_light_pos; D3DXMatrixInverse(&mInvLightView, NULL, local_cam.GetViewMatrix()); D3DXVec3Transform(&tmp_light_pos, &vTrans, &mInvLightView ); D3DXVECTOR3 tmp_light_pos_3(tmp_light_pos.x,tmp_light_pos.y,tmp_light_pos.z); D3DXVECTOR3 vLookAt = *local_cam.GetLookAtPt(); local_cam.SetViewParams( &tmp_light_pos_3, &vLookAt ); g_MeshScene.set_parameters( render_ogre, render_scene, render_fan, false ); D3DXMATRIX mLightView; // here we compute light viewprojection so that light oversees the whole scene D3DXMATRIX mTranslate; D3DXMatrixInverse(&mTranslate, NULL, local_cam.GetWorldMatrix()); D3DXMatrixMultiply(&mLightView, &mTranslate, local_cam.GetViewMatrix()); unsigned iTmp = g_SampleUI.GetCheckBox(IDC_BDUMP_SHADOWMAP)->GetChecked(); ssmap.Render(pDev10, &g_MeshScene, local_cam,fTime,fElapsedTime,iTmp); pDev10->RSSetState(g_pRenderState); p_RTV = g_pBlendBuffer->m_pRTView; float NewBlendFactor[4] = {0,0,0,0}; //alpha blending initial; if( isFirstPass ) { isFirstPass = false; pDev10->OMSetBlendState( g_Blender.m_pSceneBlendStateInitial, NewBlendFactor, 0xffffffff ); } else { pDev10->OMSetBlendState( g_Blender.m_pSceneBlendStateOn, NewBlendFactor, 0xffffffff ); } if( ShadowAlgorithm == BP_GI ) { V(g_BPGI.m_pEffect->GetVariableByName("g_fLumiFactor")->AsScalar()->SetFloat( shadow_factor )); g_BPGI.set_parameters( para,p_RTV,&light_color[0] ); g_BPGI.set_input_buffer( &g_GBuffer ); g_BPGI.OnD3D10FrameRender(render_ogre,render_scene,g_SampleUI,g_MeshScene,fSubLightSize,ssmap,g_CameraRef,local_cam,pDev10,fTime,fElapsedTime,pUserContext); } else if( ShadowAlgorithm == STANDARD_BP ) { V(g_ABP.m_pEffect->GetVariableByName("fLumiFactor")->AsScalar()->SetFloat( shadow_factor )); g_ABP.set_parameters( para,p_RTV,&light_color[0] ); g_ABP.set_input_buffer( &g_GBuffer ); g_ABP.OnD3D10FrameRender(render_ogre,render_scene,g_SampleUI,g_MeshScene,fSubLightSize,ssmap,g_CameraRef,local_cam,pDev10,fTime,fElapsedTime,pUserContext); } else if( ShadowAlgorithm == BP_MSSM_KERNEL ) { V(g_BPMSSMKernel.m_pEffect->GetVariableByName("fLumiFactor")->AsScalar()->SetFloat( shadow_factor )); g_BPMSSMKernel.set_parameters( para,p_RTV,&light_color[0] ); g_BPMSSMKernel.set_input_buffer( &g_GBuffer ); g_BPMSSMKernel.OnD3D10FrameRender(render_ogre,render_scene,g_SampleUI,g_MeshScene,fSubLightSize,ssmap,g_CameraRef,local_cam,pDev10,fTime,fElapsedTime,pUserContext); } else if( ShadowAlgorithm == STD_VSM ) { V(g_StdVSM.m_pEffect->GetVariableByName("fLumiFactor")->AsScalar()->SetFloat( shadow_factor )); g_StdVSM.set_bias( g_fDefaultDepthBias,g_f3rdDepthDelta, g_f1stDepthDelta ); g_StdVSM.set_parameters( para,p_RTV,&light_color[0] ); g_StdVSM.set_input_buffer( &g_GBuffer ); g_StdVSM.OnD3D10FrameRender(render_ogre,render_scene,g_SampleUI,g_MeshScene,fSubLightSize,ssmap,g_CameraRef,local_cam,pDev10,fTime,fElapsedTime,pUserContext); } else if( ShadowAlgorithm == MIP_VSM ) { V(g_MipVSM.m_pEffect->GetVariableByName("fLumiFactor")->AsScalar()->SetFloat( shadow_factor )); g_MipVSM.set_parameters( para,p_RTV,&light_color[0] ); g_MipVSM.set_input_buffer( &g_GBuffer ); g_MipVSM.OnD3D10FrameRender(render_ogre,render_scene,g_SampleUI,g_MeshScene,fSubLightSize,ssmap,g_CameraRef,local_cam,pDev10,fTime,fElapsedTime,pUserContext); } else if( ShadowAlgorithm == STD_PCSS ) { V(g_PCSS.m_pEffect->GetVariableByName("fLumiFactor")->AsScalar()->SetFloat( shadow_factor )); g_PCSS.set_parameters( para,p_RTV,&light_color[0] ); g_PCSS.set_input_buffer( &g_GBuffer ); g_PCSS.OnD3D10FrameRender(render_ogre,render_scene,g_SampleUI,g_MeshScene,fSubLightSize,ssmap,g_CameraRef,local_cam,pDev10,fTime,fElapsedTime,pUserContext); } //alpha blending restore pDev10->OMSetBlendState( g_Blender.pOriginalBlendState, g_Blender.OriginalBlendFactor, g_Blender.OriginalSampleMask ); if( g_SampleUI.GetCheckBox( IDC_SHOW_3DWIDGET )->GetChecked() ) { if( g_pCamManager->Camera(cam_idx)->GetCamType() == S3UTCamera::eLight&& g_pCamManager->Camera(cam_idx)->IsActive() ) { pDev10->OMSetRenderTargets(1, &(g_pWidgetBuffer->m_pRTView), g_GBuffer.m_pDepthBuffer->m_pDSView); g_Widget.m_pSsmap = &ssmap; g_Widget.OnD3D10FrameRender(pDev10,g_CameraRef,local_cam); } } } } } } //----------------------------------------------------------------------------------- D3DXMATRIX mMatrixScale; D3DXMATRIX mMatrixScaleWVP; D3DXMatrixScaling( &mMatrixScale,(FLOAT)5,(FLOAT)5,(FLOAT)5 ); D3DXMatrixMultiply( &mMatrixScaleWVP, &mMatrixScale, &mWorldViewProj ); ID3D10RenderTargetView* pOrigRTV = DXUTGetD3D10RenderTargetView(); pDev10->OMSetRenderTargets(1,&pOrigRTV,NULL); float FinalClearColor[4] = { 1, 0, 0, 1 }; pDev10->ClearRenderTargetView(pOrigRTV, FinalClearColor); g_MeshScene.set_parameters( render_ogre,render_scene, render_fan ); g_Final.set_parameters( para, pOrigRTV, NULL, g_pBlendBuffer->m_pSRView, g_pWidgetBuffer->m_pSRView ); S3UTCamera& g_LCameraRef = g_LCamera[0]; g_Final.set_input_buffer( &g_GBuffer ); g_pSkyBox->OnFrameRender( mMatrixScaleWVP ); g_Final.OnD3D10FrameRender(g_SampleUI,g_MeshScene,g_fFilterSize,ssmap,g_CameraRef,g_LCameraRef,pDev10,fTime,fElapsedTime,pUserContext); g_LCameraRef.SetProjParams(g_fCtrledLightFov, 1.0, g_fCtrledLightZn, g_fCtrledLightZf); //if( g_SampleUI.GetCheckBox( IDC_SHOW_3DWIDGET )->GetChecked() ) //{ // for( int cam_idx = 0; cam_idx < g_pCamManager->CameraCount(); ++cam_idx ) // { // // rendering a subdivided light // if( g_pCamManager->Camera(cam_idx)->GetCamType() == S3UTCamera::eLight&& // g_pCamManager->Camera(cam_idx)->IsActive() ) // { // g_Widget.m_pSsmap = &ssmap; // g_Widget.OnD3D10FrameRender(pDev10,g_CameraRef,*(g_pCamManager->Camera(cam_idx))); // } // } //} // render UI if (g_bShowUI) { RenderText(); g_SampleUI.OnRender(fElapsedTime); //g_HUD.OnRender(fElapsedTime); } if( g_bShowLightUI ) { g_CameraUI.OnRender(fElapsedTime); } if( g_SampleUI.GetCheckBox( IDC_FRAME_DUMP )->GetChecked() ) { static int g_Frame = 0; IDXGISwapChain* pSwapChain = DXUTGetDXGISwapChain(); ID3D10Texture2D* pRT; pSwapChain->GetBuffer(0, __uuidof(pRT), reinterpret_cast<void**>(&pRT)); WCHAR filename[32]; StringCchPrintf(filename, 100, L"DumpedImages\\screenshot%.3d.jpg", g_Frame); D3DX10SaveTextureToFile(pRT, D3DX10_IFF_JPG, filename); SAFE_RELEASE(pRT); ++g_Frame; } }
//-------------------------------------------------------------------------------------- // Render the scene using the D3D9 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) { // 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; } HRESULT hr; D3DXMATRIXA16 mWorldViewProjection; D3DXVECTOR3 vLightDir; D3DXCOLOR vLightDiffuse; UINT iPass, cPasses; D3DXMATRIXA16 mWorld; D3DXMATRIXA16 mView; D3DXMATRIXA16 mProj; // Clear the render target and the zbuffer V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DXCOLOR( 0.0f, 0.25f, 0.25f, 0.55f ), 1.0f, 0 ) ); //pd3dDevice->SetSamplerState(0, D3DSAMP_SRGBTEXTURE, TRUE); //pd3dDevice->SetRenderState( D3DRS_SRGBWRITEENABLE, TRUE ); // Render the scene if( SUCCEEDED( pd3dDevice->BeginScene() ) ) { // Get the projection & view matrix from the camera class mWorld = g_mCenterMesh * *g_Camera.GetWorldMatrix(); mProj = *g_Camera.GetProjMatrix(); mView = *g_Camera.GetViewMatrix(); mWorldViewProjection = mWorld * mView * mProj; g_fLightScale = 1.0; vLightDir = g_LightControl.GetLightDirection(); vLightDiffuse = g_fLightScale * D3DXCOLOR( 1, 1, 1, 1 ); V( g_pEffect9->SetValue( g_hLightDir, &vLightDir, sizeof( D3DXVECTOR3 ) * 1 ) ); V( g_pEffect9->SetValue( g_hLightDiffuse, &vLightDiffuse, sizeof( D3DXVECTOR4 ) * 1 ) ); // Update the effect's variables. Instead of using strings, it would // be more efficient to cache a handle to the parameter by calling // ID3DXEffect::GetParameterByName V( g_pEffect9->SetMatrix( g_hmWorldViewProjection, &mWorldViewProjection ) ); V( g_pEffect9->SetMatrix( g_hmWorld, &mWorld ) ); D3DXCOLOR vWhite = D3DXCOLOR( 1, 1, 1, 1 ); V( g_pEffect9->SetValue( g_hMaterialDiffuseColor, &vWhite, sizeof( D3DXCOLOR ) ) ); V( g_pEffect9->SetFloat( g_hfTime, ( float )fTime ) ); V( g_pEffect9->SetInt( g_hnNumLights, g_nNumActiveLights ) ); // Render the scene with this technique as defined in the .fx file switch( g_nNumActiveLights ) { case 1: V( g_pEffect9->SetTechnique( g_hRenderSceneWithTexture1Light ) ); break; case 2: V( g_pEffect9->SetTechnique( g_hRenderSceneWithTexture2Light ) ); break; case 3: V( g_pEffect9->SetTechnique( g_hRenderSceneWithTexture3Light ) ); break; } // Apply the technique contained in the effect and render the mesh V( g_pEffect9->Begin( &cPasses, 0 ) ); for( iPass = 0; iPass < cPasses; iPass++ ) { V( g_pEffect9->BeginPass( iPass ) ); V( g_pMesh9->DrawSubset( 0 ) ); V( g_pEffect9->EndPass() ); } V( g_pEffect9->End() ); g_HUD.OnRender( fElapsedTime ); g_SampleUI.OnRender( fElapsedTime ); RenderText(); V( pd3dDevice->EndScene() ); } }