//-------------------------------------------------------------------------------------- // When the user changes scene, recreate these components as they are scene // dependent. //-------------------------------------------------------------------------------------- HRESULT CreateD3DComponents( ID3D11Device* pd3dDevice) { HRESULT hr; auto pd3dImmediateContext = DXUTGetD3D11DeviceContext(); V_RETURN( g_DialogResourceManager.OnD3D11CreateDevice( pd3dDevice, pd3dImmediateContext ) ); V_RETURN( g_D3DSettingsDlg.OnD3D11CreateDevice( pd3dDevice ) ); g_pTxtHelper = new CDXUTTextHelper( pd3dDevice, pd3dImmediateContext, &g_DialogResourceManager, 15 ); static const XMVECTORF32 s_vecEye = { 105.0f, 14.0f, -3.0f, 0.f }; static const XMVECTORF32 s_vecLookAt = { 0.0f, -7.5f, 0.0f, 0.f }; XMFLOAT3 vMin = XMFLOAT3( -1000.0f, -1000.0f, -1000.0f ); XMFLOAT3 vMax = XMFLOAT3( 1000.0f, 1000.0f, 1000.0f ); g_ViewerCamera.SetViewParams( s_vecEye, s_vecLookAt ); g_ViewerCamera.SetRotateButtons( true, false, false); g_ViewerCamera.SetScalers( 0.01f, 10.0f ); g_ViewerCamera.SetDrag( true ); g_ViewerCamera.SetEnableYAxisMovement( true ); g_ViewerCamera.SetClipToBoundary( true, &vMin, &vMax ); g_ViewerCamera.FrameMove( 0 ); static const XMVECTORF32 s_lightEye = { -320.0f, 300.0f, -220.3f, 0.f }; g_LightCamera.SetViewParams( s_lightEye, g_XMZero ); g_LightCamera.SetRotateButtons( true, false, false ); g_LightCamera.SetScalers( 0.01f, 50.0f ); g_LightCamera.SetDrag( true ); g_LightCamera.SetEnableYAxisMovement( true ); g_LightCamera.SetClipToBoundary( true, &vMin, &vMax ); g_LightCamera.SetProjParams( XM_PI / 4, 1.0f, 0.1f , 1000.0f); g_LightCamera.FrameMove( 0 ); // Get the final sizes uint32_t width = DXUTGetDXGIBackBufferSurfaceDesc()->Width; uint32_t height = DXUTGetDXGIBackBufferSurfaceDesc()->Height; g_Scene.Init( pd3dDevice, pd3dImmediateContext, &g_MeshPowerPlant, width, height); return S_OK; }
//-------------------------------------------------------------------------------------- // When the user changes scene, recreate these components as they are scene // dependent. //-------------------------------------------------------------------------------------- HRESULT CreateD3DComponents(ID3D11Device* pd3dDevice) { HRESULT hr; ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext(); V_RETURN(g_DialogResourceManager.OnD3D11CreateDevice(pd3dDevice, pd3dImmediateContext)); V_RETURN(g_D3DSettingsDlg.OnD3D11CreateDevice(pd3dDevice)); g_pTxtHelper = new CDXUTTextHelper(pd3dDevice, pd3dImmediateContext, &g_DialogResourceManager, 15); XMVECTOR vecEye = XMVectorSet(100.0f, 5.0f, 5.0f, 0); XMVECTOR vecAt = XMVectorSet(0.0f, 0.0f, 0.0f, 0); XMFLOAT3 vMin = XMFLOAT3(-1000.0f, -1000.0f, -1000.0f); XMFLOAT3 vMax = XMFLOAT3(1000.0f, 1000.0f, 1000.0f); g_ViewerCamera.SetViewParams(vecEye, vecAt); g_ViewerCamera.SetRotateButtons(TRUE, FALSE, FALSE); g_ViewerCamera.SetScalers(0.01f, 10.0f); g_ViewerCamera.SetDrag(true); g_ViewerCamera.SetEnableYAxisMovement(true); g_ViewerCamera.SetClipToBoundary(TRUE, &vMin, &vMax); g_ViewerCamera.FrameMove(0); vecEye = XMVectorSet(-320.0f, 300.0f, -220.3f, 0); vecAt = XMVectorSet(0.0f, 0.0f, 0.0f, 0); g_LightCamera.SetViewParams(vecEye, vecAt); g_LightCamera.SetRotateButtons(TRUE, FALSE, FALSE); g_LightCamera.SetScalers(0.01f, 50.0f); g_LightCamera.SetDrag(true); g_LightCamera.SetEnableYAxisMovement(true); g_LightCamera.SetClipToBoundary(TRUE, &vMin, &vMax); g_LightCamera.SetProjParams(XM_PI / 4, 1.0f, 0.1f, 1000.0f); g_LightCamera.FrameMove(0); g_CascadedShadow.Init(pd3dDevice, pd3dImmediateContext, g_pSelectedMesh, &g_ViewerCamera, &g_LightCamera, &g_CascadeConfig); return S_OK; }
//-------------------------------------------------------------------------------------- // Create any D3D9 resources that will live through a device reset (D3DPOOL_MANAGED) // and aren't tied to the back buffer size //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D9CreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { #ifdef CONSOLE std::cout << "OnD3D9CreateDevice" << std::endl; #endif HRESULT hr; V_RETURN( g_DialogResourceManager.OnD3D9CreateDevice( pd3dDevice ) ); V_RETURN( g_SettingsDlg.OnD3D9CreateDevice( pd3dDevice ) ); V_RETURN( D3DXCreateFont( pd3dDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Arial", &g_pFont9 ) ); // Read the D3DX effect file // WCHAR str[MAX_PATH]; DWORD dwShaderFlags = D3DXFX_NOT_CLONEABLE; #ifdef DEBUG_VS dwShaderFlags |= D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT; #endif #ifdef DEBUG_PS dwShaderFlags |= D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT; #endif //V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"SimpleSample.fx" ) ); //V_RETURN( D3DXCreateEffectFromFile( pd3dDevice, L"e:/SimpleSample.fx", NULL, NULL, dwShaderFlags, NULL, &g_pEffect9, NULL ) ); // Setup the camera's view parameters D3DXVECTOR3 vecEye( 0.0f, 0.0f, -5.0f ); D3DXVECTOR3 vecAt ( 0.0f, 0.0f, -0.0f ); g_Camera.SetViewParams( &vecEye, &vecAt ); //------------------------------------------------------------------------- //* // SPARK init DX9Info::setDevice( pd3dDevice ); hr = D3DXCreateTextureFromFile(pd3dDevice, L"res/point.bmp", &g_pTextureParticle); if( FAILED(hr) ) cout << "erreur chargement texture" << endl; return S_OK; }
//-------------------------------------------------------------------------------------- // Create any D3D11 resources that aren't dependant on the back buffer //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D11CreateDevice(ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext) { HRESULT hr; DXUTTRACE(L"OnD3D11CreateDevice called\n"); SetCursor(LoadCursor(0, IDC_ARROW)); ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext(); // does not addref V_RETURN( g_DialogResourceManager.OnD3D11CreateDevice(pd3dDevice, pd3dImmediateContext) ); V_RETURN( g_SettingsDlg.OnD3D11CreateDevice(pd3dDevice) ); g_pTxtHelper = new CDXUTTextHelper(pd3dDevice, pd3dImmediateContext, &g_DialogResourceManager, g_TextLineHeight); // Setup orbital camera D3DXVECTOR3 vecEye(0.0f, 2.0f, 0.0f); D3DXVECTOR3 vecAt (0.0f, 0.0f, 0.0f); g_OrbitalCamera.SetViewParams(&vecEye, &vecAt); g_OrbitalCamera.SetRadius(1.5f, 0.01f); // Setup first-person camera D3DXVECTOR3 sibenikVecEye(0.0960150138f, 0.0273544509f, -0.0185411610f); D3DXVECTOR3 sibenikVecAt (-0.623801112f, -0.649074197f, -0.174454257f); g_FirstPersonCamera.SetViewParams(&sibenikVecEye, &sibenikVecAt); g_FirstPersonCamera.SetEnablePositionMovement(1); g_FirstPersonCamera.SetScalers(0.001f, 0.05f); // Load Scene3D.fx g_pSceneRenderer.OnCreateDevice(pd3dDevice); // Load meshes and bin files LoadScenes(pd3dDevice); GFSDK_SSAO_Status status; status = g_AORenderer.Create(pd3dDevice); assert(status == GFSDK_SSAO_OK); return S_OK; }
//-------------------------------------------------------------------------------------- // Initialize the app //-------------------------------------------------------------------------------------- void InitApp() { // Initialize dialogs g_D3DSettingsDlg.Init( &g_DialogResourceManager ); g_HUD.Init( &g_DialogResourceManager ); g_SampleUI.Init( &g_DialogResourceManager ); g_HUD.SetCallback( OnGUIEvent ); int iY = 20; g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", 0, iY, 170, 22 ); g_HUD.AddButton( IDC_TOGGLEREF, L"Toggle REF (F3)", 0, iY += 26, 170, 22, VK_F3 ); g_HUD.AddButton( IDC_CHANGEDEVICE, L"Change device (F2)", 0, iY += 26, 170, 22, VK_F2 ); g_SampleUI.SetCallback( OnGUIEvent ); iY = 10; WCHAR sz[100]; iY += 24; swprintf_s( sz, L"Patch Divisions: %2.1f", g_fSubdivs ); g_SampleUI.AddStatic( IDC_PATCH_SUBDIVS_STATIC, sz, 10, iY += 26, 150, 22 ); g_SampleUI.AddSlider( IDC_PATCH_SUBDIVS, 10, iY += 24, 150, 22, 10 * MIN_DIVS, 10 * MAX_DIVS, (int)(g_fSubdivs * 10) ); iY += 24; g_SampleUI.AddCheckBox( IDC_TOGGLE_LINES, L"Toggle Wires", 20, iY += 26, 150, 22, g_bDrawWires ); iY += 24; g_SampleUI.AddRadioButton( IDC_PARTITION_INTEGER, IDC_PARTITION_MODE, L"Integer", 20, iY += 26, 170, 22 ); g_SampleUI.AddRadioButton( IDC_PARTITION_FRAC_EVEN, IDC_PARTITION_MODE, L"Fractional Even", 20, iY += 26, 170, 22 ); g_SampleUI.AddRadioButton( IDC_PARTITION_FRAC_ODD, IDC_PARTITION_MODE, L"Fractional Odd", 20, iY += 26, 170, 22 ); g_SampleUI.GetRadioButton( IDC_PARTITION_INTEGER )->SetChecked( true ); // Setup the camera's view parameters static const XMVECTORF32 s_vecEye = { 5.0f, 3.0f, -10.0f, 0.f }; static const XMVECTORF32 s_vecAt = { 5.0f, 0.0f, 0.0f, 0.f }; g_Camera.SetViewParams( s_vecEye, s_vecAt ); g_Camera.SetEnablePositionMovement(true); g_Camera.SetEnableYAxisMovement(true); }
//-------------------------------------------------------------------------------------- // Create any D3D11 resources that aren't dependant on the back buffer //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { g_pd3dDevice = pd3dDevice; HRESULT hr; ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext(); V_RETURN( g_DialogResourceManager.OnD3D11CreateDevice( pd3dDevice, pd3dImmediateContext ) ); V_RETURN( g_D3DSettingsDlg.OnD3D11CreateDevice( pd3dDevice ) ); g_pTxtHelper = new CDXUTTextHelper( pd3dDevice, pd3dImmediateContext, &g_DialogResourceManager, 15 ); D3DXVECTOR3 vCenter( 0.25767413f, -28.503521f, 111.00689f); FLOAT fObjectRadius = 378.15607f; D3DXMatrixTranslation( &g_mCenterMesh, -vCenter.x, -vCenter.y, -vCenter.z ); D3DXMATRIXA16 m; D3DXMatrixRotationY( &m, D3DX_PI ); g_mCenterMesh *= m; D3DXMatrixRotationX( &m, D3DX_PI / 2.0f ); g_mCenterMesh *= m; // Compile the shaders to a model based on the feature level we acquired ID3DBlob* pVertexShaderBuffer = NULL; ID3DBlob* pGeometryShaderBuffer = NULL; ID3DBlob* pPixelShaderBuffer = NULL; switch( DXUTGetD3D11DeviceFeatureLevel() ) { case D3D_FEATURE_LEVEL_11_0: V_RETURN( CompileShaderFromFile( L"cloth_renderer_VS.hlsl", "VSMain", "vs_5_0" , &pVertexShaderBuffer ) ); V_RETURN( CompileShaderFromFile( L"cloth_renderer_PS.hlsl", "GSMain", "gs_5_0" , &pGeometryShaderBuffer ) ); V_RETURN( CompileShaderFromFile( L"cloth_renderer_PS.hlsl", "PSMain", "ps_5_0" , &pPixelShaderBuffer ) ); break; } // Create the shaders V_RETURN( pd3dDevice->CreateVertexShader( pVertexShaderBuffer->GetBufferPointer(), pVertexShaderBuffer->GetBufferSize(), NULL, &g_pVertexShader ) ); V_RETURN( pd3dDevice->CreateGeometryShader( pGeometryShaderBuffer->GetBufferPointer(), pGeometryShaderBuffer->GetBufferSize(), NULL, &g_pGeometryShader ) ); V_RETURN( pd3dDevice->CreatePixelShader( pPixelShaderBuffer->GetBufferPointer(), pPixelShaderBuffer->GetBufferSize(), NULL, &g_pPixelShader ) ); V_RETURN( pd3dDevice->CreateInputLayout( layout, ARRAYSIZE( layout ), pVertexShaderBuffer->GetBufferPointer(), pVertexShaderBuffer->GetBufferSize(), &g_pVertexLayout11 ) ); SAFE_RELEASE( pVertexShaderBuffer ); SAFE_RELEASE( pPixelShaderBuffer ); SAFE_RELEASE( pGeometryShaderBuffer ); // Load the mesh V_RETURN( g_Mesh11.Create( pd3dDevice, L"tiny\\tiny.sdkmesh", true ) ); // Create a sampler state D3D11_SAMPLER_DESC SamDesc; SamDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; SamDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; SamDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; SamDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; SamDesc.MipLODBias = 0.0f; SamDesc.MaxAnisotropy = 1; SamDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; SamDesc.BorderColor[0] = SamDesc.BorderColor[1] = SamDesc.BorderColor[2] = SamDesc.BorderColor[3] = 0; SamDesc.MinLOD = 0; SamDesc.MaxLOD = D3D11_FLOAT32_MAX; V_RETURN( pd3dDevice->CreateSamplerState( &SamDesc, &g_pSamLinear ) ); // Setup constant buffers D3D11_BUFFER_DESC Desc; Desc.Usage = D3D11_USAGE_DYNAMIC; Desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; Desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; Desc.MiscFlags = 0; Desc.ByteWidth = sizeof( CB_VS_PER_OBJECT ); V_RETURN( pd3dDevice->CreateBuffer( &Desc, NULL, &g_pcbVSPerObject ) ); Desc.ByteWidth = sizeof( CB_PS_PER_OBJECT ); V_RETURN( pd3dDevice->CreateBuffer( &Desc, NULL, &g_pcbPSPerObject ) ); Desc.ByteWidth = sizeof( CB_PS_PER_FRAME ); V_RETURN( pd3dDevice->CreateBuffer( &Desc, NULL, &g_pcbPSPerFrame ) ); // Setup the camera's view parameters D3DXVECTOR3 vecEye( 30.0f, 30.0f, -80.0f ); D3DXVECTOR3 vecAt ( 10.0f, 20.0f, -0.0f ); g_Camera.SetViewParams( &vecEye, &vecAt ); cloths.resize(numFlags); for( int flagIndex = 0; flagIndex < numFlags; ++flagIndex ) { cloths[flagIndex].create_buffers(clothWidth, clothHeight); } initBullet(); std::wstring flagTexsName[] = { L"atiFlag.bmp", L"amdFlag.bmp", }; int numFlagTexs = 2; WCHAR flagTexs[2][MAX_PATH]; HRESULT res = DXUTFindDXSDKMediaFileCch(flagTexs[0],MAX_PATH, flagTexsName[0].c_str()); res = DXUTFindDXSDKMediaFileCch(flagTexs[1],MAX_PATH, flagTexsName[1].c_str()); for( int flagIndex = 0; flagIndex < numFlags; ++flagIndex ) { cloths[flagIndex].create_texture(flagTexs[flagIndex % numFlagTexs]); cloths[flagIndex].x_offset = 0; cloths[flagIndex].y_offset = 0; cloths[flagIndex].z_offset = 0; } my_capsule.create_buffers(50,40); my_capsule.create_texture(); //Turn off backface culling D3D11_RASTERIZER_DESC rsDesc; ZeroMemory(&rsDesc,sizeof(D3D11_RASTERIZER_DESC) ); rsDesc.CullMode = D3D11_CULL_NONE; rsDesc.FillMode = D3D11_FILL_SOLID; hr = pd3dDevice->CreateRasterizerState(&rsDesc, &g_pRasterizerState); rsDesc.FillMode = D3D11_FILL_WIREFRAME; hr = pd3dDevice->CreateRasterizerState(&rsDesc, &g_pRasterizerStateWF); SAFE_RELEASE(pd3dImmediateContext); return S_OK; }
//-------------------------------------------------------------------------------------- // Create any D3D11 resources that aren't dependant on the back buffer //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { HRESULT hr; ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext(); V_RETURN( g_DialogResourceManager.OnD3D11CreateDevice( pd3dDevice, pd3dImmediateContext ) ); V_RETURN( g_D3DSettingsDlg.OnD3D11CreateDevice( pd3dDevice ) ); g_pTxtHelper = new CDXUTTextHelper( pd3dDevice, pd3dImmediateContext, &g_DialogResourceManager, 15 ); // D3DXVECTOR3 vCenter( 0.25767413f, -28.503521f, 111.00689f ); FLOAT fObjectRadius = 378.15607f; lightpos = D3DXVECTOR3(300,300,-200); //test = new testing(); hr = test.setup(pd3dDevice,pBackBufferSurfaceDesc,pUserContext); hr = tessplane.setup(pd3dDevice,pBackBufferSurfaceDesc,pUserContext); hr = tesscube.setup(pd3dDevice,pBackBufferSurfaceDesc,pUserContext,80,D3DXVECTOR3(300,50,-200));//D3DXVECTOR3(300,50,-200 hr = lightsphere.setup(pd3dDevice,pBackBufferSurfaceDesc,pUserContext,10,lightpos); hr = fuse.setup(pd3dDevice,pBackBufferSurfaceDesc,pUserContext); hr = board1.setup(pd3dDevice,pBackBufferSurfaceDesc,pUserContext,D3DXVECTOR3(300,-300,-1000)); hr = deboard.setup(pd3dDevice,pBackBufferSurfaceDesc,pUserContext,D3DXVECTOR3(-300,-300,-1000)); hr = geo_alien.setup(pd3dDevice,pBackBufferSurfaceDesc,pUserContext); hr = FirePart.setup(pd3dDevice,pBackBufferSurfaceDesc,pUserContext,80,0); //0 = fire hr = sky.setup(pd3dDevice,pBackBufferSurfaceDesc,pUserContext,D3DXVECTOR3(0,0,0)); hr = buildings.setup(pd3dDevice,pBackBufferSurfaceDesc,pUserContext); hr = MissilePart.setup(pd3dDevice,pBackBufferSurfaceDesc,pUserContext,20,1); g_LightControl.SetRadius( 2000 ); // Setup the camera's view parameters D3DXVECTOR3 vecEye( 0.0f, 50.0f, -1000.0f ); D3DXVECTOR3 vecAt ( 0.0f, 0.0f, -0.0f ); g_Camera.SetRotateButtons(true,false,false); g_Camera.SetViewParams( &vecEye, &vecAt ); g_Camera.SetEnablePositionMovement( true ); g_Camera.SetScalers( 0.005f, 500.0f ); D3D11_DEPTH_STENCIL_DESC descDS; ZeroMemory(&descDS, sizeof(descDS)); descDS.DepthEnable = false; descDS.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; descDS.DepthFunc = D3D11_COMPARISON_LESS; descDS.StencilEnable = FALSE; hr = pd3dDevice->CreateDepthStencilState( &descDS, &g_DepthState); //setup stuff for post process ID3DBlob* pVertexShaderBuffer = NULL; V_RETURN( CompileShaderFromFile( L"PP1.hlsl", "VS", "vs_4_0", &pVertexShaderBuffer ) ); ID3DBlob* pPixelShaderBuffer = NULL; V_RETURN( CompileShaderFromFile( L"PP1.hlsl", "PS", "ps_4_0", &pPixelShaderBuffer ) ); V_RETURN( pd3dDevice->CreateVertexShader( pVertexShaderBuffer->GetBufferPointer(), pVertexShaderBuffer->GetBufferSize(), NULL, &VSPPFirstPass ) ); DXUT_SetDebugName( VSPPFirstPass, "VSPost1" ); V_RETURN( pd3dDevice->CreatePixelShader( pPixelShaderBuffer->GetBufferPointer(), pPixelShaderBuffer->GetBufferSize(), NULL, &PSPPFirstPass ) ); DXUT_SetDebugName( PSPPFirstPass, "PSPost1" ); pVertexShaderBuffer = NULL; V_RETURN( CompileShaderFromFile( L"Gaussblur.hlsl", "VS", "vs_4_0", &pVertexShaderBuffer ) ); pPixelShaderBuffer = NULL; V_RETURN( CompileShaderFromFile( L"Gaussblur.hlsl", "PS", "ps_4_0", &pPixelShaderBuffer ) ); V_RETURN( pd3dDevice->CreateVertexShader( pVertexShaderBuffer->GetBufferPointer(), pVertexShaderBuffer->GetBufferSize(), NULL, &VSPPBlur ) ); DXUT_SetDebugName( VSPPBlur, "VSBlur" ); V_RETURN( pd3dDevice->CreatePixelShader( pPixelShaderBuffer->GetBufferPointer(), pPixelShaderBuffer->GetBufferSize(), NULL, &PSPPBlur ) ); DXUT_SetDebugName( PSPPBlur, "PSBlur" ); pVertexShaderBuffer = NULL; V_RETURN( CompileShaderFromFile( L"bloom_combine.hlsl", "VS", "vs_4_0", &pVertexShaderBuffer ) ); pPixelShaderBuffer = NULL; V_RETURN( CompileShaderFromFile( L"bloom_combine.hlsl", "PS", "ps_4_0", &pPixelShaderBuffer ) ); V_RETURN( pd3dDevice->CreateVertexShader( pVertexShaderBuffer->GetBufferPointer(), pVertexShaderBuffer->GetBufferSize(), NULL, &VSPPComb ) ); DXUT_SetDebugName( VSPPComb, "VSComb" ); V_RETURN( pd3dDevice->CreatePixelShader( pPixelShaderBuffer->GetBufferPointer(), pPixelShaderBuffer->GetBufferSize(), NULL, &PSPPComb ) ); DXUT_SetDebugName( PSPPComb, "PSComb" ); D3D11_BUFFER_DESC Desc; Desc.Usage = D3D11_USAGE_DYNAMIC; Desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; Desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; Desc.MiscFlags = 0; Desc.ByteWidth = sizeof( blur_cbuffer ); V_RETURN( pd3dDevice->CreateBuffer( &Desc, NULL, &blur_cb_buffer ) ); DXUT_SetDebugName( blur_cb_buffer, "blur_cb" ); //g_Camera.SetRadius( fObjectRadius * 3.0f, fObjectRadius * 0.5f, fObjectRadius * 10.0f ); return S_OK; }
//-------------------------------------------------------------------------------------- // Create any D3D9 resources that won't live through a device reset (D3DPOOL_DEFAULT) // or that are tied to the back buffer size //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D9ResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { #ifdef CONSOLE std::cout << "OnD3D9ResetDevice" << std::endl; #endif HRESULT hr; V_RETURN( g_DialogResourceManager.OnD3D9ResetDevice() ); V_RETURN( g_SettingsDlg.OnD3D9ResetDevice() ); if( g_pFont9 ) V_RETURN( g_pFont9->OnResetDevice() ); if( g_pEffect9 ) V_RETURN( g_pEffect9->OnResetDevice() ); V_RETURN( D3DXCreateSprite( pd3dDevice, &g_pSprite9 ) ); g_pTxtHelper = new CDXUTTextHelper( g_pFont9, g_pSprite9, NULL, NULL, 15 ); g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 ); g_HUD.SetSize( 170, 170 ); g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 350 ); g_SampleUI.SetSize( 170, 300 ); pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE ); //pd3dDevice->SetRenderState( D3DRS_DITHERENABLE, TRUE ); pd3dDevice->SetRenderState( D3DRS_SPECULARENABLE, TRUE ); pd3dDevice->SetRenderState( D3DRS_LIGHTING, false ); pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x80808080 ); D3DLIGHT9 light; D3DXVECTOR3 vecLightDirUnnormalized( 10.0f, -10.0f, 10.0f ); ZeroMemory( &light, sizeof( D3DLIGHT9 ) ); light.Type = D3DLIGHT_DIRECTIONAL; light.Diffuse.r = 1.0f; light.Diffuse.g = 1.0f; light.Diffuse.b = 1.0f; D3DXVec3Normalize( ( D3DXVECTOR3* )&light.Direction, &vecLightDirUnnormalized ); light.Position.x = 10.0f; light.Position.y = -10.0f; light.Position.z = 10.0f; light.Range = 1000.0f; pd3dDevice->SetLight( 0, &light ); pd3dDevice->LightEnable( 0, TRUE ); // Set the transform matrices D3DXMATRIXA16 matWorld; D3DXMatrixIdentity( &matWorld ); pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld ); // Setup the camera with view & projection matrix D3DXVECTOR3 vecEye( 0.0f, 0.0f, -5.0f ); D3DXVECTOR3 vecAt ( 0.0f, 0.0f, 0.0f ); g_Camera.SetViewParams( &vecEye, &vecAt ); float fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height; g_Camera.SetProjParams( D3DX_PI / 4, fAspectRatio, 1.0f, 1000.0f ); return S_OK; }
//-------------------------------------------------------------------------------------- // Create any D3D11 resources that aren't dependant on the back buffer //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { HRESULT hr; ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext(); V_RETURN( g_DialogResourceManager.OnD3D11CreateDevice( pd3dDevice, pd3dImmediateContext ) ); V_RETURN( g_D3DSettingsDlg.OnD3D11CreateDevice( pd3dDevice ) ); g_pTxtHelper = new CDXUTTextHelper( pd3dDevice, pd3dImmediateContext, &g_DialogResourceManager, 15 ); g_pTxtHelper1 = new CDXUTTextHelper( pd3dDevice, pd3dImmediateContext, &g_DialogResourceManager, 35 ); // textures / rts D3D11_TEXTURE2D_DESC TDesc; TDesc.Width = UINT(g_fShadowMapWidth); TDesc.Height = UINT(g_fShadowMapHeight); TDesc.MipLevels = 1; TDesc.ArraySize = 1; TDesc.Format = DXGI_FORMAT_R16_TYPELESS; TDesc.SampleDesc.Count = 1; TDesc.SampleDesc.Quality = 0; TDesc.Usage = D3D11_USAGE_DEFAULT; TDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE; TDesc.CPUAccessFlags = 0; TDesc.MiscFlags = 0; pd3dDevice->CreateTexture2D( &TDesc, 0, &g_pRSMDepthStencilTexture); DXUT_SetDebugName( g_pRSMDepthStencilTexture, "RSM" ); D3D11_DEPTH_STENCIL_VIEW_DESC DSVDesc; DSVDesc.Format = DXGI_FORMAT_D16_UNORM; DSVDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; DSVDesc.Flags = 0; DSVDesc.Texture2D.MipSlice = 0; pd3dDevice->CreateDepthStencilView( g_pRSMDepthStencilTexture, &DSVDesc, & g_pDepthStencilTextureDSV ); DXUT_SetDebugName( g_pDepthStencilTextureDSV, "RSM DSV" ); D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc; SRVDesc.Format = DXGI_FORMAT_R16_UNORM; SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; SRVDesc.Texture2D.MipLevels = 1; SRVDesc.Texture2D.MostDetailedMip = 0; pd3dDevice->CreateShaderResourceView( g_pRSMDepthStencilTexture, &SRVDesc, &g_pDepthTextureSRV ); DXUT_SetDebugName( g_pDepthTextureSRV, "RSM SRV" ); // Setup constant buffers D3D11_BUFFER_DESC Desc; // Utility Desc.Usage = D3D11_USAGE_DYNAMIC; Desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; Desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; Desc.MiscFlags = 0; Desc.ByteWidth = sizeof( CB_CONSTANTS ); V_RETURN( pd3dDevice->CreateBuffer( &Desc, NULL, &g_pcbConstants ) ); DXUT_SetDebugName( g_pcbConstants, "CB_CONSTANTS" ); // Load the scene mesh WCHAR str[256]; V_RETURN( DXUTFindDXSDKMediaFileCch( str, 256, L"ColumnScene\\scene.sdkmesh" ) ); g_SceneMesh.Create( pd3dDevice, str, false ); V_RETURN( DXUTFindDXSDKMediaFileCch( str, 256, L"ColumnScene\\poles.sdkmesh" ) ); g_Poles.Create( pd3dDevice, str, false ); // Setup the camera D3DXVECTOR3 vecEye( 0.95f, 5.83f, -14.48f ); D3DXVECTOR3 vecAt ( 0.90f, 5.44f, -13.56f ); g_Camera.SetViewParams( &vecEye, &vecAt ); D3DXVECTOR3 vecEyeL = D3DXVECTOR3( 0,0,0 ); D3DXVECTOR3 vecAtL ( 0, -0.5, 1 ); g_LCamera.SetViewParams( &vecEyeL, &vecAtL ); // Create sampler states for point and linear // PointCmp D3D11_SAMPLER_DESC SamDesc; SamDesc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT; SamDesc.AddressU = D3D11_TEXTURE_ADDRESS_BORDER; SamDesc.AddressV = D3D11_TEXTURE_ADDRESS_BORDER; SamDesc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER; SamDesc.MipLODBias = 0.0f; SamDesc.MaxAnisotropy = 1; SamDesc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL; SamDesc.BorderColor[0] = SamDesc.BorderColor[1] = SamDesc.BorderColor[2] = SamDesc.BorderColor[3] = 1.0; SamDesc.MinLOD = 0; SamDesc.MaxLOD = D3D11_FLOAT32_MAX; V_RETURN( pd3dDevice->CreateSamplerState( &SamDesc, &g_pSamplePointCmp ) ); DXUT_SetDebugName( g_pSamplePointCmp, "PointCmp" ); // Point SamDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; SamDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; V_RETURN( pd3dDevice->CreateSamplerState( &SamDesc, &g_pSamplePoint ) ); DXUT_SetDebugName( g_pSamplePoint, "Point" ); // Linear SamDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; SamDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; SamDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; SamDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; V_RETURN( pd3dDevice->CreateSamplerState( &SamDesc, &g_pSampleLinear ) ); DXUT_SetDebugName( g_pSampleLinear, "Linear" ); // Create a blend state to disable alpha blending D3D11_BLEND_DESC BlendState; ZeroMemory(&BlendState, sizeof(D3D11_BLEND_DESC)); BlendState.IndependentBlendEnable = FALSE; BlendState.RenderTarget[0].BlendEnable = FALSE; BlendState.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; hr = pd3dDevice->CreateBlendState(&BlendState, &g_pBlendStateNoBlend); DXUT_SetDebugName( g_pBlendStateNoBlend, "No Blend" ); BlendState.RenderTarget[0].RenderTargetWriteMask = 0; hr = pd3dDevice->CreateBlendState(&BlendState, &g_pBlendStateColorWritesOff); DXUT_SetDebugName( g_pBlendStateColorWritesOff, "Color Writes Off"); return S_OK; }