Exemplo n.º 1
0
//--------------------------------------------------------------------------------------
// Render the scene using the D3D10 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    //
    // 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_pWorldVariable->SetMatrix( ( float* )&g_World );
    g_pMeshColorVariable->SetFloatVector( ( float* )g_vMeshColor );

    //
    // Render the cube
    //
    D3D10_TECHNIQUE_DESC techDesc;
    g_pTechnique->GetDesc( &techDesc );
    for( UINT p = 0; p < techDesc.Passes; ++p )
    {
        g_pTechnique->GetPassByIndex( p )->Apply( 0 );
        pd3dDevice->DrawIndexed( 36, 0, 0 );
    }
}
Exemplo n.º 2
0
//--------------------------------------------------------------------------------------
// 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();
    }
}
Exemplo n.º 3
0
//--------------------------------------------------------------------------------------
// Render the scene using the D3D10 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    // Clear the render target
    float ClearColor[4] = { 0.9569f, 0.9569f, 1.0f, 0.0f };
    ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView();
    pd3dDevice->ClearRenderTargetView( pRTV, ClearColor );
    ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView();
    pd3dDevice->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0 );

    // Render the result
    D3DXMATRIX mWorld;
    D3DXMATRIX mView;
    D3DXMATRIX mProj;
    D3DXMATRIX mWorldView;
    D3DXMATRIX mWorldViewProj;
    mWorld = *g_Camera.GetWorldMatrix();
    mProj = *g_Camera.GetProjMatrix();
    mView = *g_Camera.GetViewMatrix();
    mWorldView = mWorld * mView;
    mWorldViewProj = mWorldView * mProj;

    // Set variables
    g_pmWorldViewProj->SetMatrix( ( float* )&mWorldViewProj );
    g_pmWorldView->SetMatrix( ( float* )&mWorldView );
    g_pmWorld->SetMatrix( ( float* )&mWorld );
    g_pmView->SetMatrix( ( float* )&mView );
    g_pmProj->SetMatrix( ( float* )&mProj );
    g_pDiffuseTex->SetResource( g_pMeshTexRV );
    D3DXVECTOR3 lightDir( -1,1,-1 );
    D3DXVECTOR3 viewLightDir;
    D3DXVec3TransformNormal( &viewLightDir, &lightDir, &mView );
    D3DXVec3Normalize( &viewLightDir, &viewLightDir );
    g_pViewSpaceLightDir->SetFloatVector( ( float* )&viewLightDir );

    // Set Input Assembler params
    UINT stride = g_VertStride;
    UINT offset = 0;
    pd3dDevice->IASetInputLayout( g_pVertexLayout );
    pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
    pd3dDevice->IASetIndexBuffer( g_pIB, DXGI_FORMAT_R32_UINT, 0 );
    pd3dDevice->IASetVertexBuffers( 0, 1, &g_pVB, &stride, &offset );

    // Render using the technique g_pRenderTextured
    D3D10_TECHNIQUE_DESC techDesc;
    g_pRenderTextured->GetDesc( &techDesc );
    for( UINT p = 0; p < techDesc.Passes; p++ )
    {
        g_pRenderTextured->GetPassByIndex( p )->Apply( 0 );
        pd3dDevice->DrawIndexed( g_NumIndices, 0, 0 );
    }
}
Exemplo n.º 4
0
void D3DEngine::OnFrameRender(ID3D10Device* d3d_device, float elapsed_time) {
	//
	// Clear the back buffer
	//
	float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; // red, green, blue, alpha
	ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView();
	d3d_device->ClearRenderTargetView( pRTV, ClearColor );

	//
	// Clear the depth stencil
	//
	ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView();
	d3d_device->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0 );

	//
	// Update variables that change once per frame
	//
	world_variable_->SetMatrix( ( float* )&world_ );

	//
	// Set the Vertex Layout
	//
	d3d_device->IASetInputLayout( vertex_layout_ );

	//
	// Render the mesh
	//
	UINT Strides[1];
	UINT Offsets[1];
	ID3D10Buffer* pVB[1];
	pVB[0] = mesh_.GetVB10( 0, 0 );
	Strides[0] = ( UINT )mesh_.GetVertexStride( 0, 0 );
	Offsets[0] = 0;
	d3d_device->IASetVertexBuffers( 0, 1, pVB, Strides, Offsets );
	d3d_device->IASetIndexBuffer( mesh_.GetIB10( 0 ), mesh_.GetIBFormat10( 0 ), 0 );

	D3D10_TECHNIQUE_DESC techDesc;
	technique_->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 < mesh_.GetNumSubsets( 0 ); ++subset )
		{
			pSubset = mesh_.GetSubset( 0, subset );

			PrimType = mesh_.GetPrimitiveType10( ( SDKMESH_PRIMITIVE_TYPE )pSubset->PrimitiveType );
			d3d_device->IASetPrimitiveTopology( PrimType );

			pDiffuseRV = mesh_.GetMaterial( pSubset->MaterialID )->pDiffuseRV10;
			diffuse_variable_->SetResource( pDiffuseRV );

			technique_->GetPassByIndex( p )->Apply( 0 );
			d3d_device->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
	mesh_.Render(d3d_device, technique_, diffuse_variable_);
}
Exemplo n.º 5
0
//--------------------------------------------------------------------------------------
// Render the scene using the D3D10 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    // Clear the render target
    float ClearColor[4] = { 0.9569f, 0.9569f, 1.0f, 0.0f };
    ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView();
    pd3dDevice->ClearRenderTargetView( pRTV, ClearColor );
    ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView();
    pd3dDevice->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0 );

    D3DXMATRIX mWorld;
    D3DXMATRIX mView;
    D3DXMATRIX mProj;
    D3DXMATRIX mWorldView;
    D3DXMATRIX mWorldViewProj;
    mWorld = *g_Camera.GetWorldMatrix();
    mProj = *g_Camera.GetProjMatrix();
    mView = *g_Camera.GetViewMatrix();
    mWorldView = mWorld * mView;
    mWorldViewProj = mWorldView * mProj;

    // Set variables
    g_pmWorldViewProj->SetMatrix( ( float* )&mWorldViewProj );
    g_pmWorldView->SetMatrix( ( float* )&mWorldView );
    g_pmWorld->SetMatrix( ( float* )&mWorld );
    g_pmProj->SetMatrix( ( float* )&mProj );
    g_pDiffuseTex->SetResource( g_pMeshTexRV );
    D3DXVECTOR3 lightDir( -1,1,-1 );
    D3DXVECTOR3 viewLightDir;
    D3DXVec3TransformNormal( &viewLightDir, &lightDir, &mView );
    D3DXVec3Normalize( &viewLightDir, &viewLightDir );
    g_pViewSpaceLightDir->SetFloatVector( ( float* )&viewLightDir );

    // Get VB and IB
    UINT offset = 0;
    UINT stride = g_Mesh.GetVertexStride( 0, 0 );
    ID3D10Buffer* pVB = g_Mesh.GetVB10( 0, 0 );
    ID3D10Buffer* pIB = g_Mesh.GetAdjIB10( 0 );

    // Set Input Assembler params
    pd3dDevice->IASetInputLayout( g_pVertexLayout );

    pd3dDevice->IASetIndexBuffer( pIB, g_Mesh.GetIBFormat10( 0 ), 0 );
    pd3dDevice->IASetVertexBuffers( 0, 1, &pVB, &stride, &offset );
    pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ );

    // Render using the technique g_pRenderTextured
    SDKMESH_SUBSET* pSubset = NULL;

    D3D10_TECHNIQUE_DESC techDesc;
    g_pRenderTextured->GetDesc( &techDesc );
    for( UINT p = 0; p < techDesc.Passes; p++ )
    {
        g_pRenderTextured->GetPassByIndex( p )->Apply( 0 );
        for( UINT subset = 0; subset < g_Mesh.GetNumSubsets( 0 ); subset++ )
        {
            pSubset = g_Mesh.GetSubset( 0, subset );

            pd3dDevice->DrawIndexed( ( UINT )pSubset->IndexCount * 2, ( UINT )pSubset->IndexStart,
                                     ( UINT )pSubset->VertexStart );
        }
    }

    // Render the chess piece just for show
    // Render using the technique g_pRenderPiece
    g_pRenderPiece->GetDesc( &techDesc );
    for( UINT p = 0; p < techDesc.Passes; p++ )
    {
        g_pRenderPiece->GetPassByIndex( p )->Apply( 0 );
        for( UINT subset = 0; subset < g_Mesh.GetNumSubsets( 0 ); subset++ )
        {
            pSubset = g_Mesh.GetSubset( 0, subset );

            pd3dDevice->DrawIndexed( ( UINT )pSubset->IndexCount * 2, ( UINT )pSubset->IndexStart,
                                     ( UINT )pSubset->VertexStart );
        }
    }
}
Exemplo n.º 6
0
//--------------------------------------------------------------------------------------
// Render the scene using the D3D10 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    // Clear the render target
    float ClearColor[4] = { 0.9569f, 0.9569f, 1.0f, 0.0f };
    ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView();
    pd3dDevice->ClearRenderTargetView( pRTV, ClearColor );
    ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView();
    pd3dDevice->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0 );

    // Make sure we only grow the tree the first time we go to render.
    // If we recreated the same tree every frame, we would definitely waste time.
    static bool bFirst = true;
    if( bFirst )
    {
        //-----------------------------------------------------------------------------------------
        // o/__   <-- BreakdancinBob NOTE: Give the grow algorithm access to the random buffer
        // |  (\    
        //-----------------------------------------------------------------------------------------
        g_pRandomBuf->SetResource( g_pRandomBufferRV );

        // Grow the branches one step at a time
        for( UINT i = 0; i < g_NumGrowthSpurts; i++ )
        {
            GrowBranches( pd3dDevice );
        }
        bFirst = false;
    }

    // Render the result
    D3DXMATRIX mWorld;
    D3DXMATRIX mView;
    D3DXMATRIX mProj;
    D3DXMATRIX mWorldViewProj;
    D3DXMATRIX mWorldView;
    mWorld = *g_Camera.GetWorldMatrix();
    mProj = *g_Camera.GetProjMatrix();
    mView = *g_Camera.GetViewMatrix();
    mWorldView = mWorld * mView;
    mWorldViewProj = mWorldView * mProj;

    // Set variables
    g_pmWorldViewProj->SetMatrix( ( float* )&mWorldViewProj );
    g_pmWorld->SetMatrix( ( float* )&mWorld );
    g_pmWorldView->SetMatrix( ( float* )&mWorldView );
    g_pDiffuseTex->SetResource( g_pMeshTexRV );
    D3DXVECTOR3 lightDir( -1,1,-1 );
    D3DXVECTOR3 viewLightDir;
    D3DXVec3TransformNormal( &viewLightDir, &lightDir, &mView );
    D3DXVec3Normalize( &viewLightDir, &viewLightDir );
    g_pViewSpaceLightDir->SetFloatVector( ( float* )&viewLightDir );

    // Set Input Assembler params
    ID3D10Buffer* pBuffers[1];
    pBuffers[0] = g_pDrawFrom;
    UINT stride = g_VertStride;
    UINT offset = 0;
    pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
    pd3dDevice->IASetVertexBuffers( 0, 1, pBuffers, &stride, &offset );

    // Render using the technique g_pRenderTextured
    D3D10_TECHNIQUE_DESC techDesc;
    g_pRenderTextured->GetDesc( &techDesc );
    for( UINT p = 0; p < techDesc.Passes; p++ )
    {
        g_pRenderTextured->GetPassByIndex( p )->Apply( 0 );
        pd3dDevice->DrawAuto();
    }
}
Exemplo n.º 7
0
//--------------------------------------------------------------------------------------
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;
	}
}
Exemplo n.º 8
0
//--------------------------------------------------------------------------------------
// 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();
}
Exemplo n.º 9
0
//--------------------------------------------------------------------------------------
// 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_SettingsDlg.IsActive() )
    {
        g_SettingsDlg.OnRender( fElapsedTime );
        return;
    }
    
    //
    // Clear the back buffer
    //
    float ClearColor[4] = { .0f, 0.0f, 0.0f, 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 the Cull Mode (non-FX method)  setup the render state
    //
    pd3dDevice->RSSetState( g_pRasterStates[ 0 ] );

    HRESULT hr;
    D3DXMATRIXA16 mWorld;
    D3DXMATRIXA16 mView;
    D3DXMATRIXA16 mProj;
    D3DXMATRIXA16 mWorldViewProjection;

    // 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_pWorldViewProjection->SetMatrix( (float*)&mWorldViewProjection ) );
    V( g_pWorld->SetMatrix( (float*)&mWorld ) );
    V( g_pTime->SetFloat( (float)fTime ) );
    V( g_pCameraPosition->SetFloatVector( (float*)g_Camera.GetEyePt() ) );   


	// Blend
	pd3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};
	pd3dDevice->OMSetBlendState(0, blendFactor, 0xffffffff);


    //
    // Set the Vertex Layout
    //
    pd3dDevice->IASetInputLayout( g_pVertexLayout );

    UINT iCurSubset = ( UINT )( INT_PTR )g_SampleUI.GetComboBox( IDC_SUBSET )->GetSelectedData();

    //
    // Render the mesh
    //
	// Stop render the loader mesh
	bool drawLoaderMesh = true;
	if (drawLoaderMesh) {
		if ( iCurSubset == -1 )
		{
			for ( UINT iSubset = 0; iSubset < g_MeshLoader.GetNumSubsets(); ++iSubset )
			{
				RenderSubset( iSubset );
			}
		} else
		{
			RenderSubset( iCurSubset );
		}
	}

	// 
	// Render the Cube
	//
	//UINT cubeAttributCount;
	// This is not efficiency this procedure will always call to the GPU
	// To get the number of suset.
	//g_TrialCube->GetAttributeTable(NULL, &cubeAttributCount);
	//for (UINT iSubset = 0; iSubset < cubeAttributCount; iSubset++)
	//{
	//	g_TrialCube->DrawSubset(iSubset);
	//}
	//g_TrialCube->DrawSubset(0);

	pd3dDevice->RSSetState( g_pRasterStates[ g_eSceneRasterizerMode ] );

	pd3dDevice->OMSetBlendState(g_TransparentBS, blendFactor, 0xffffffff);
	//g_pBox->draw();
	bool drawAABBLevel=false;
	if (drawAABBLevel){
		g_AABBConstructor->DrawLevel(g_CurrentAABBLevel);
	}

	// g_FunctionDraw->DrawFunction();
	 g_ParabolaDis->Draw();
	//g_UVFileDisp->Draw();
	//g_AABBConstructor->DrawAllAABBDetial();

	//
    // Reset our Cull Mode (non-FX method)
    //
    pd3dDevice->RSSetState( g_pRasterStates[ 0 ] );

    DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
    RenderText();
    g_HUD.OnRender( fElapsedTime );
    g_SampleUI.OnRender( fElapsedTime );    
    DXUT_EndPerfEvent();


}
Exemplo n.º 10
0
//--------------------------------------------------------------------------------------
// 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_SettingsDlg.IsActive() )
    {
        g_SettingsDlg.OnRender( fElapsedTime );
        return;
    }
    
    //
    // Clear the back buffer
    //
    float ClearColor[4] = { 0.3f, 0.3f, 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 );

    HRESULT hr;
    D3DXMATRIXA16 mWorld;
    D3DXMATRIXA16 mView;
    D3DXMATRIXA16 mProj;
    D3DXMATRIXA16 mWorldViewProjection;

    // 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_pWorldViewProjection->SetMatrix( (float*)&mWorldViewProjection ) );
    V( g_pWorld->SetMatrix( (float*)&mWorld ) );
    V( g_pTime->SetFloat( (float)fTime ) );
    V( g_pCameraPosition->SetFloatVector( (float*)g_Camera.GetEyePt() ) );   

    //
    // Set the Vertex Layout
    //
    pd3dDevice->IASetInputLayout( g_pVertexLayout );

    UINT iCurSubset = ( UINT )( INT_PTR )g_SampleUI.GetComboBox( IDC_SUBSET )->GetSelectedData();

    //
    // Render the mesh
    //
    if ( iCurSubset == -1 )
    {
        for ( UINT iSubset = 0; iSubset < g_MeshLoader.GetNumSubsets(); ++iSubset )
        {
            RenderSubset( iSubset );
        }
    } else
    {
        RenderSubset( iCurSubset );
    }

    DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
    RenderText();
    g_HUD.OnRender( fElapsedTime );
    g_SampleUI.OnRender( fElapsedTime );    
    DXUT_EndPerfEvent();
}
//--------------------------------------------------------------------------------------
// Render the scene using the D3D10 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    float ClearColor[4] = { 1.0f, 1.0f, 1.0f, 0.0f }; // R, G, B, A
    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_D3DSettingsDlg.IsActive() )
    {
        g_D3DSettingsDlg.OnRender( fElapsedTime );
        return;
    }

    // Set our render target since we can't present multisampled ref
    ID3D10RenderTargetView* pOrigRT;
    ID3D10DepthStencilView* pOrigDS;
    pd3dDevice->OMGetRenderTargets( 1, &pOrigRT, &pOrigDS );
    ID3D10RenderTargetView* aRTViews[ 1 ] = { g_pRTRV };
    pd3dDevice->OMSetRenderTargets( 1, aRTViews, g_pDSRV );

    pd3dDevice->ClearRenderTargetView( g_pRTRV, ClearColor );
    pd3dDevice->ClearDepthStencilView( g_pDSRV, D3D10_CLEAR_DEPTH, 1.0, 0 );

    // Set Matrices
    D3DXMATRIX mWorldViewProj;
    D3DXMATRIX mWorldView;
    D3DXMATRIX mViewProj;
    D3DXMATRIX mWorld;
    D3DXMATRIX mView;
    D3DXMATRIX mProj;

    // Fix the camera motion for now
    D3DXMATRIX mBlurViewProj[MAX_TIME_STEPS];
    for( int i = 0; i < MAX_TIME_STEPS; i++ )
    {
        mView = *g_Camera.GetViewMatrix();
        mProj = *g_Camera.GetProjMatrix();
        mBlurViewProj[i] = mView * mProj;
    }
    g_pmBlurViewProj->SetMatrixArray( ( float* )mBlurViewProj, 0, MAX_TIME_STEPS );

    D3DXMatrixIdentity( &mWorld );
    mView = *g_Camera.GetViewMatrix();
    mProj = *g_Camera.GetProjMatrix();
    mViewProj = mView * mProj;
    mWorldViewProj = mWorld * mViewProj;
    mWorldView = mWorld * mView;

    g_pmWorldViewProj->SetMatrix( ( float* )&mWorldViewProj );
    g_pmViewProj->SetMatrix( ( float* )&mViewProj );
    g_pmWorldView->SetMatrix( ( float* )&mWorldView );

    RenderSceneMesh( pd3dDevice, &g_SceneMesh, false );
    RenderFanMesh( pd3dDevice, &g_FanMesh, fTime, false );
    if( g_bRenderOgre )
        RenderSkinnedMesh( pd3dDevice, &g_AnimMesh, fTime, false );

    for( UINT iMesh = 0; iMesh < g_NumLinkedMeshes; iMesh++ )
        RenderLinkedMesh( pd3dDevice, &g_pLinkedMeshes[iMesh], &g_AnimMesh, g_MeshLinkages[iMesh].iBone, fTime,
                          false );

    if( g_bUseMotionBlur )
    {
        RenderFanMesh( pd3dDevice, &g_FanMesh, fTime, true );
        if( g_bRenderOgre )
            RenderSkinnedMesh( pd3dDevice, &g_AnimMesh, fTime, true );

        for( UINT iMesh = 0; iMesh < g_NumLinkedMeshes; iMesh++ )
            RenderLinkedMesh( pd3dDevice, &g_pLinkedMeshes[iMesh], &g_AnimMesh, g_MeshLinkages[iMesh].iBone, fTime,
                              true );
    }

    //MSAA resolve
    ID3D10Resource* pRT;
    pOrigRT->GetResource( &pRT );
    D3D10_RENDER_TARGET_VIEW_DESC rtDesc;
    pOrigRT->GetDesc( &rtDesc );
    pd3dDevice->ResolveSubresource( pRT, D3D10CalcSubresource( 0, 0, 1 ), g_pRenderTarget, D3D10CalcSubresource( 0, 0,
                                                                                                                 1 ),
                                    rtDesc.Format );
    SAFE_RELEASE( pRT );

    // Use our Old RT again
    aRTViews[0] = pOrigRT;
    pd3dDevice->OMSetRenderTargets( 1, aRTViews, pOrigDS );
    SAFE_RELEASE( pOrigRT );
    SAFE_RELEASE( pOrigDS );

    DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
    RenderText();
    g_HUD.OnRender( fElapsedTime );
    g_SampleUI.OnRender( fElapsedTime );
    DXUT_EndPerfEvent();
}