Пример #1
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();
    }
}
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 RenderPreFrame( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, CXMMATRIX matView, CXMMATRIX matProj, FLOAT fElapsedTime )
{
    DXUT_BeginPerfEvent( 0, L"Pre Frame Render" );

    g_pd3dDeviceEx->PreFrameRender();

    if( !g_bPauseStreaming )
    {
        if( g_bDrawTerrain )
        {
            g_pTerrainView->PreFrameRender( pd3dImmediateContext, fElapsedTime );
        }
        else
        {
            g_LastResidencySampleViewID = ResidencySampleRender::Render( pd3dDevice, pd3dImmediateContext, g_pTitleResidencyManager, g_SceneObjects, matView, matProj );

            const UINT SceneObjectCount = (UINT)g_SceneObjects.size();
            for( UINT i = 0; i < SceneObjectCount; ++i )
            {
                SamplingQualityManager* pSQM = g_SceneObjects[i]->Textures[0].pSamplingQualityManager;
                pSQM->Render( pd3dImmediateContext, g_pd3dDeviceEx, fElapsedTime );
            }
        }
    }

    DXUT_EndPerfEvent();
}
Пример #4
0
//--------------------------------------------------------------------------------------
// 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() );
    }
}
Пример #5
0
//--------------------------------------------------------------------------------------
// 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() );

    }
}
Пример #6
0
//--------------------------------------------------------------------------------------
// 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() );
    }
}
Пример #7
0
//--------------------------------------------------------------------------------------
// Render the scene using the D3D9 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
	HRESULT hr;

	// 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 );

	D3DXMATRIX mtxTemp_Projection;
	D3DXMATRIX mtxTemp_View;

	D3DXMatrixPerspectiveFovRH( &mtxTemp_Projection, 60.f, 1.f, 1.f, 1000.f );
	D3DXMatrixLookAtRH( &mtxTemp_View, &D3DXVECTOR3( 20.f, 20.f, 20.f ), 
		&D3DXVECTOR3( 0.f, 0.f, 0.f ),
		&D3DXVECTOR3( 0.f, 1.f, 0.f ) );
	
	SCEMAN->SetProjectionMatrix( &mtxTemp_Projection );
	SCEMAN->SetViewMatrix( &mtxTemp_View );

	// 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

		SCEMAN->Render();

		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 (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();
}
Пример #9
0
//--------------------------------------------------------------------------------------
// 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();
}
Пример #10
0
//--------------------------------------------------------------------------------------
// 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() );
    }
}
Пример #11
0
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());
    }
}
//--------------------------------------------------------------------------------------
// 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();
}
VOID RenderTestObjects( ID3D11DeviceContext* pd3dImmediateContext, CXMMATRIX matVP )
{
    DXUT_BeginPerfEvent( 0, L"Frame Render" );

    DXUTSetupD3D11Views( pd3dImmediateContext );

    ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView();
    ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView();

    float ClearColor[4] = { 0, 0, 0, 1 };
    pd3dImmediateContext->ClearRenderTargetView( pRTV, ClearColor );
    pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 );

    HRESULT hr;

    pd3dImmediateContext->IASetInputLayout( g_pDefaultInputLayout );
    pd3dImmediateContext->VSSetShader( g_pVSTransform, NULL, 0 );
    pd3dImmediateContext->PSSetSamplers( 0, 1, &g_pSamLinear );
    FLOAT BlendFactor[4] = { 1, 1, 1, 1 };
    pd3dImmediateContext->OMSetBlendState( g_pBlendState, BlendFactor, 0xFFFFFFFF );
    pd3dImmediateContext->OMSetDepthStencilState( g_pDepthStencilState, 0 );
    pd3dImmediateContext->RSSetState( g_pRasterizerState );

    const UINT SceneObjectCount = (UINT)g_SceneObjects.size();
    for( UINT i = 0; i < SceneObjectCount; ++i )
    {
        DXUT_BeginPerfEvent( 0, L"Scene Object Render" );

        SceneObject* pSO = g_SceneObjects[i];

        pd3dImmediateContext->PSSetShader( pSO->pPixelShader, NULL, 0 );

        D3D11_MAPPED_SUBRESOURCE MappedResource;
        V( pd3dImmediateContext->Map( g_pcbVSPerObject11, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ) );
        CB_VS_PER_OBJECT* pVSPerObject = ( CB_VS_PER_OBJECT* )MappedResource.pData;
        XMMATRIX matWorld = XMLoadFloat4x4( &pSO->matWorld );
        XMMATRIX matWVP = XMMatrixTranspose( matWorld * matVP );
        XMStoreFloat4x4( (XMFLOAT4X4*)&pVSPerObject->m_mWorldViewProjection, matWVP );
        pd3dImmediateContext->Unmap( g_pcbVSPerObject11, 0 );
        pd3dImmediateContext->VSSetConstantBuffers( 0, 1, &g_pcbVSPerObject11 );

        UINT Strides = { pSO->VertexStrideBytes };
        UINT Offsets = { 0 };
        pd3dImmediateContext->IASetVertexBuffers( 0, 1, &pSO->pVertexBuffer, &Strides, &Offsets );
        pd3dImmediateContext->IASetPrimitiveTopology( pSO->PrimitiveType );

        g_pd3dDeviceEx->PSSetShaderResources( 0, 1, &pSO->Textures[0].pTextureSRV );

        UINT QualityShaderResourceSlot = 1;
        if( pSO->pPixelShader != g_pPSSceneRender )
        {
            QualityShaderResourceSlot = 2;
        }
        ID3D11ShaderResourceView* pQualitySRV = pSO->Textures[0].pSamplingQualityManager->GetLODQualityTextureSRV();
        pd3dImmediateContext->PSSetShaderResources( QualityShaderResourceSlot, 1, &pQualitySRV );
        ID3D11SamplerState* pQualitySS = pSO->Textures[0].pSamplingQualityManager->GetSamplerState();
        pd3dImmediateContext->PSSetSamplers( 1, 1, &pQualitySS );

        if( pSO->pIndexBuffer != NULL )
        {
            pd3dImmediateContext->IASetIndexBuffer( pSO->pIndexBuffer, DXGI_FORMAT_R16_UINT, 0 );
            pd3dImmediateContext->DrawIndexed( pSO->IndexCount, 0, 0 );
        }
        else
        {
            pd3dImmediateContext->Draw( pSO->VertexCount, 0 );
        }

        DXUT_EndPerfEvent();
    }

    DXUT_EndPerfEvent();
}
//--------------------------------------------------------------------------------------
// 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();
}
Пример #15
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)
{
	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();
	}
}
Пример #17
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();


}
Пример #18
0
//--------------------------------------------------------------------------------------
// render callback
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, 
                                  ID3D11DeviceContext* pd3dImmediateContext, 
                                  double fTime,
                                  float fElapsedTime, void* pUserContext )
{
    static int s_iCounter = 0;

    // If the settings dialog is being shown, then render it instead of rendering the app's scene
    if( g_D3DSettingsDlg.IsActive() )
    {
        g_D3DSettingsDlg.OnRender( fElapsedTime );
        return;
    }

    if( g_pScenePS == NULL && s_iCounter == 0 )
    {
        s_iCounter = 4;
    }

    if( s_iCounter > 0 )
        s_iCounter --;

    if( s_iCounter == 1 && g_pScenePS == NULL )
    {
        HRESULT hr = S_OK;

        // Create the shaders
        ID3DBlob* pBlob = NULL;

        // VS
        hr = CompileShaderFromFile( L"ContactHardeningShadows11.hlsl", "VS_RenderScene", "vs_5_0", &pBlob ); 
        hr = pd3dDevice->CreateVertexShader( pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &g_pSceneVS );
        DXUT_SetDebugName( g_pSceneVS, "VS_RenderScene" );
        // Define our scene vertex data layout
        const D3D11_INPUT_ELEMENT_DESC SceneLayout[] =
        {
            { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
            { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
            { "TEXTURE", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
        };
        hr = pd3dDevice->CreateInputLayout( SceneLayout, ARRAYSIZE( SceneLayout ), pBlob->GetBufferPointer(),
                                                    pBlob->GetBufferSize(), &g_pSceneVertexLayout );
        SAFE_RELEASE( pBlob );
        DXUT_SetDebugName( g_pSceneVertexLayout, "SceneLayout" );

        hr = CompileShaderFromFile( L"ContactHardeningShadows11.hlsl", "VS_RenderSceneSM", "vs_5_0", &pBlob ); 
        hr = pd3dDevice->CreateVertexShader( pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &g_pSM_VS );
        SAFE_RELEASE( pBlob );
        DXUT_SetDebugName( g_pSM_VS, "VS_RenderSceneSM" );

        // PS
        hr = CompileShaderFromFile( L"ContactHardeningShadows11.hlsl", "PS_RenderScene", "ps_5_0", &pBlob ); 
        hr = pd3dDevice->CreatePixelShader( pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &g_pScenePS );
        SAFE_RELEASE( pBlob );
        DXUT_SetDebugName( g_pScenePS, "PS_RenderScene" );

        s_iCounter = 0;
    }
    else if( g_pScenePS != NULL )
    {
        ID3D11RenderTargetView*      pRTV[2] = { NULL,NULL };
        ID3D11ShaderResourceView*    pSRV[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };

        // Array of our samplers
        ID3D11SamplerState* ppSamplerStates[3] = { g_pSamplePoint, g_pSampleLinear, g_pSamplePointCmp };

        pd3dImmediateContext->PSSetSamplers( 0, 3, ppSamplerStates );
                
            // Store off original render target, this is the back buffer of the swap chain
        ID3D11RenderTargetView* pOrigRTV = DXUTGetD3D11RenderTargetView();
        ID3D11DepthStencilView* pOrigDSV = DXUTGetD3D11DepthStencilView();
            
        // Clear the render target
        float ClearColor[4] = { 0.0f, 0.25f, 0.25f, 0.55f };
        pd3dImmediateContext->ClearRenderTargetView( DXUTGetD3D11RenderTargetView(), 
                                                     ClearColor );
        pd3dImmediateContext->ClearDepthStencilView( DXUTGetD3D11DepthStencilView(), 
                                                     D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 
                                                     1.0, 0 );

            // Get the projection & view matrix from the camera class
        D3DXMATRIXA16 mWorld;
        D3DXMATRIXA16 mView;
        D3DXMATRIXA16 mProj;
        D3DXMATRIXA16 mViewProjLight;
        D3DXMATRIXA16 mWorldViewProjection;
        D3DXVECTOR3   vLightDir;

        // disable color writes
        pd3dImmediateContext->OMSetBlendState(g_pBlendStateColorWritesOff, 0, 0xffffffff);

        RenderShadowMap( pd3dDevice, pd3dImmediateContext, mViewProjLight, vLightDir );

        // enable color writes
        pd3dImmediateContext->OMSetBlendState(g_pBlendStateNoBlend, 0, 0xffffffff);

        mView  = *g_Camera.GetViewMatrix();
        mProj  = *g_Camera.GetProjMatrix();
        mWorldViewProjection = mView * mProj;

        // Setup the constant buffer for the scene vertex shader
        D3D11_MAPPED_SUBRESOURCE MappedResource;
        pd3dImmediateContext->Map( g_pcbConstants, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource );
        CB_CONSTANTS* pConstants = ( CB_CONSTANTS* )MappedResource.pData;
        D3DXMatrixTranspose( &pConstants->f4x4WorldViewProjection, &mWorldViewProjection );
        D3DXMatrixTranspose( &pConstants->f4x4WorldViewProjLight,  &mViewProjLight );
        pConstants->vShadowMapDimensions =    D3DXVECTOR4(g_fShadowMapWidth, g_fShadowMapHeight, 
                                                          1.0f/g_fShadowMapWidth, 
                                                          1.0f/g_fShadowMapHeight);
        pConstants->vLightDir            =    D3DXVECTOR4( vLightDir.x, vLightDir.y,
                                                           vLightDir.z, 0.0f );
        pConstants->fSunWidth            =    g_fSunWidth;
        pd3dImmediateContext->Unmap( g_pcbConstants, 0 );
        pd3dImmediateContext->VSSetConstantBuffers( g_iCONSTANTSCBBind, 1, &g_pcbConstants );
        pd3dImmediateContext->PSSetConstantBuffers( g_iCONSTANTSCBBind, 1, &g_pcbConstants );

        // Set the shaders
        pd3dImmediateContext->VSSetShader( g_pSceneVS, NULL, 0 );
        pd3dImmediateContext->PSSetShader( g_pScenePS, NULL, 0 );

        // Set the vertex buffer format
        pd3dImmediateContext->IASetInputLayout( g_pSceneVertexLayout );
        
        // Rebind to original back buffer and depth buffer
        pRTV[0] = pOrigRTV;
        pd3dImmediateContext->OMSetRenderTargets(1, pRTV, pOrigDSV );

        // set the shadow map
        pd3dImmediateContext->PSSetShaderResources( 1, 1, &g_pDepthTextureSRV );

        // Render the scene
        g_SceneMesh.Render( pd3dImmediateContext, 0 );
        g_Poles.Render( pd3dImmediateContext, 0 );

        // restore resources
        pd3dImmediateContext->PSSetShaderResources( 0, 8, pSRV );
    }

    // Render GUI
    DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
    if( g_bGuiVisible )
    {
        g_HUD.OnRender( fElapsedTime );
        g_SampleUI.OnRender( fElapsedTime );
    }
    RenderText();
    DXUT_EndPerfEvent();
}
Пример #19
0
// Render the scene using the D3D11 device
void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime,
                                  float fElapsedTime, void* pUserContext )
{
	// Recompress the texture gFrameDelay frames after the app has started.  This produces more accurate timing of the
	// compression algorithm.
	if(gFrameNum == gFrameDelay)
	{
		RecompressTexture();
		gSampleUI.SendEvent(IDC_TEXT, true, gSampleUI.GetStatic(IDC_TEXT));
		gFrameNum++;
	}
	else if(gFrameNum < gFrameDelay)
	{
		gFrameNum++;
	}

    // If the settings dialog is being shown, then render it instead of rendering the app's scene
    if( gD3DSettingsDlg.IsActive() )
    {
        gD3DSettingsDlg.OnRender( fElapsedTime );
        return;
    }

    // Clear the render target and depth stencil
    float ClearColor[4] = { 0.02f, 0.02f, 0.02f, 1.0f };
    ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView();
    pd3dImmediateContext->ClearRenderTargetView( pRTV, ClearColor );
    ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView();
    pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 );

    // Set the input layout.
    pd3dImmediateContext->IASetInputLayout( gVertexLayout );

    // Set the vertex buffer.
    UINT stride = sizeof( Vertex );
    UINT offset = 0;
	if (gImageView == eImageView_All)
	{
		pd3dImmediateContext->IASetVertexBuffers( 0, 1, &gVertexBuffer, &stride, &offset );
	}
	else
	{
		pd3dImmediateContext->IASetVertexBuffers( 0, 1, &gQuadVB, &stride, &offset );
	}
	
    // Set the primitive topology
    pd3dImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

	// Update the Constant Buffer
	D3D11_MAPPED_SUBRESOURCE MappedResource;
    pd3dImmediateContext->Map( gConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource );
    VS_CONSTANT_BUFFER* pConstData = ( VS_CONSTANT_BUFFER* )MappedResource.pData;
	ZeroMemory(pConstData, sizeof(VS_CONSTANT_BUFFER));
	SetView(&pConstData->mView);
    pConstData->exposure = powf(2.0, gLog2Exposure);
	pd3dImmediateContext->Unmap( gConstantBuffer, 0 );

    // Set the shaders
	ID3D11Buffer* pBuffers[1] = { gConstantBuffer };
	pd3dImmediateContext->VSSetConstantBuffers( 0, 1, pBuffers );
    pd3dImmediateContext->VSSetShader( gVertexShader, NULL, 0 );

	if (gSampleUI.GetCheckBox(IDC_ALPHA)->GetChecked())
	{
		pd3dImmediateContext->PSSetShader( gRenderAlphaPS, NULL, 0 );
	}
	else
	{
		pd3dImmediateContext->PSSetShader( gRenderFramePS, NULL, 0 );
	}
    
    pd3dImmediateContext->PSSetConstantBuffers(0, 1, pBuffers );

	// Set the texture sampler.
    pd3dImmediateContext->PSSetSamplers( 0, 1, &gSamPoint );

	// Render the textures.

	if (gImageView == eImageView_Uncompressed || gImageView == eImageView_All )
	{
		pd3dImmediateContext->PSSetShaderResources( 0, 1, &gUncompressedSRV );
	}
	else if (gImageView == eImageView_Compressed)
	{
		pd3dImmediateContext->PSSetShaderResources( 0, 1, &gCompressedSRV );
	}
	else if (gImageView == eImageView_Error)
	{
		pd3dImmediateContext->PSSetShaderResources( 0, 1, &gErrorSRV );
    }

    pd3dImmediateContext->Draw( 6, 0 );

	if (gImageView == eImageView_All)
	{
		pd3dImmediateContext->PSSetShaderResources( 0, 1, &gCompressedSRV );
		pd3dImmediateContext->Draw( 6, 6 );

		pd3dImmediateContext->PSSetShaderResources( 0, 1, &gErrorSRV );
		pd3dImmediateContext->Draw( 6, 12 );
	}	

    DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
    HRESULT hr;
    V(gHUD.OnRender( fElapsedTime ));
    V(gSampleUI.OnRender( fElapsedTime ));
    RenderText();
    DXUT_EndPerfEvent();
}