Ejemplo n.º 1
0
HRESULT D3DGrid11::Render(Scene* pScene)
{
	HRESULT hr;

	GridRenderComponent* grid = static_cast<GridRenderComponent*>(m_RenderComponent);
	m_PixelShader.SetTexture(grid->GetTextureResource());

	V_RETURN(m_VertexShader.SetupRender(pScene, this));
	V_RETURN(m_PixelShader.SetupRender(pScene, this));

	// set vertex buffer
	UINT stride = sizeof(D3D11Vertex_UnlitTextured);
	UINT offset = 0;
	DXUTGetD3D11DeviceContext()->IASetVertexBuffers(0, 1, &m_pVertexBuffer, &stride, &offset);

	// set index buffer
	DXUTGetD3D11DeviceContext()->IASetIndexBuffer(m_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0);

	// set primitive topology
	DXUTGetD3D11DeviceContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	// draw the polygon
	DXUTGetD3D11DeviceContext()->DrawIndexed(m_NumPolys * 3, 0, 0);

	return S_OK;
}
void D3DLineDrawer11::DrawLine(const Vec3& from, const Vec3& to, const Color& color)
{
	HRESULT hr;
	shared_ptr<Scene> pScene = g_pApp->GetHumanView()->m_pScene;
	shared_ptr<IRenderer> pRenderer = pScene->GetRenderer();

	if (FAILED(m_LineDrawerShader.SetupRender(&(*pScene))))
		return;

	m_LineDrawerShader.SetDiffuse("art\\grid.dds", color);

	UINT stride = sizeof(Vec3);
	UINT offset = 0;

	// map the vertex buffer into a D3D11 mapped resource
	D3D11_MAPPED_SUBRESOURCE mappedResource;
	V(DXUTGetD3D11DeviceContext()->Map(m_pVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource));

	// fill in the vertex buffer with the from and to params
	Vec3* pVertices = (Vec3*)mappedResource.pData;
	pVertices[0] = from;
	pVertices[1] = to;

	// store the vertices
	m_Verts[0] = from;
	m_Verts[1] = to;

	DXUTGetD3D11DeviceContext()->Unmap(m_pVertexBuffer, 0);

	// send the vertices to the GPU and draw
	DXUTGetD3D11DeviceContext()->IASetVertexBuffers(0, 1, &m_pVertexBuffer, &stride, &offset);
	DXUTGetD3D11DeviceContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST);
	DXUTGetD3D11DeviceContext()->Draw(2, 0);
}
Ejemplo n.º 3
0
void GlobalAppState::WaitForGPU()
{
	DXUTGetD3D11DeviceContext()->Flush();
	DXUTGetD3D11DeviceContext()->End(m_pQuery);
	DXUTGetD3D11DeviceContext()->Flush();

	while (S_OK != DXUTGetD3D11DeviceContext()->GetData(m_pQuery, NULL, 0, 0));
}
Ejemplo n.º 4
0
void HumanView::VOnRender(double fTime, float fElapsedTime )
{
	m_currTick = timeGetTime();
	if (m_currTick == m_lastDraw)
		return;

	// It is time to draw ?
	if( (m_currTick - m_lastDraw) > SCREEN_REFRESH_RATE )
	{
		ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext();
		float ClearColor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
		ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView();
		pd3dImmediateContext->ClearRenderTargetView( pRTV, ClearColor );
		ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView();
		pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 );

		m_ScreenElements.sort(SortBy_SharedPtr_Content<IScreenElement>());

		for(ScreenElementList::iterator i=m_ScreenElements.begin(); i!=m_ScreenElements.end(); ++i)
		{
			(*i)->VOnRender(fTime, fElapsedTime);
		}


		// record the last successful paint
		m_lastDraw = m_currTick;

	}
}
    void RSMRenderer::RenderSpotRSMs( int NumSpotLights, const GuiState& CurrentGuiState, const Scene& Scene, const CommonUtil& CommonUtil )
    {
        AMDProfileEvent( AMD_PROFILE_RED, L"SpotRSM" ); 

        ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext();

        D3D11_VIEWPORT oldVp[ 8 ];
        UINT numVPs = 1;
        pd3dImmediateContext->RSGetViewports( &numVPs, oldVp );

        ID3D11RenderTargetView* pRTVs[] = { m_SpotAtlas.m_pNormalRTV, m_SpotAtlas.m_pDiffuseRTV };
        const int NumTargets = ARRAYSIZE( pRTVs );

        float clearColor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };

        pd3dImmediateContext->ClearDepthStencilView( m_SpotAtlas.m_pDepthDSV, D3D11_CLEAR_DEPTH, 1.0f, 0 );
        pd3dImmediateContext->ClearRenderTargetView( m_SpotAtlas.m_pNormalRTV, clearColor );
        pd3dImmediateContext->ClearRenderTargetView( m_SpotAtlas.m_pDiffuseRTV, clearColor );

        pd3dImmediateContext->OMSetRenderTargets( NumTargets, pRTVs, m_SpotAtlas.m_pDepthDSV );

        D3D11_VIEWPORT vps[ 8 ];
        for ( int i = 0; i < NumTargets; i++ )
        {
            vps[ i ].Width = gRSMSpotResolution;
            vps[ i ].Height = gRSMSpotResolution;
            vps[ i ].MinDepth = 0.0f;
            vps[ i ].MaxDepth = 1.0f;
            vps[ i ].TopLeftY = 0.0f;
            vps[ i ].TopLeftX = 0.0f;
        }

        HRESULT hr;
        D3D11_MAPPED_SUBRESOURCE MappedSubresource;
        V( pd3dImmediateContext->Map( m_pSpotInvViewProjBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedSubresource ) );
        memcpy(MappedSubresource.pData, LightUtil::GetShadowCastingSpotLightViewProjInvTransposedArray(), sizeof(XMMATRIX)*MAX_NUM_SHADOWCASTING_SPOTS);
        pd3dImmediateContext->Unmap( m_pSpotInvViewProjBuffer, 0 );

        const XMMATRIX* SpotLightViewProjArray = LightUtil::GetShadowCastingSpotLightViewProjTransposedArray();

        for ( int i = 0; i < NumSpotLights; i++ )
        {
            for ( int j = 0; j < NumTargets; j++ )
            {
                vps[ j ].TopLeftX = (float)i * gRSMSpotResolution;
            }

            pd3dImmediateContext->RSSetViewports( NumTargets, vps );
            m_CameraCallback( SpotLightViewProjArray[i] );

            RenderRSMScene( CurrentGuiState, Scene, CommonUtil );
        }

        pd3dImmediateContext->RSSetViewports( 1, oldVp );

        ID3D11RenderTargetView* pNullRTVs[] = { 0, 0, 0 };

        pd3dImmediateContext->OMSetRenderTargets( ARRAYSIZE( pNullRTVs ), pNullRTVs, 0 );
    }
Ejemplo n.º 6
0
HRESULT DebugText::OnD3D11CreateDevice( ID3D11Device* pd3dDevice, CDXUTDialogResourceManager* dxutResourceManager )
{
	ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext();

	dxutTextHelper = new CDXUTTextHelper( pd3dDevice, pd3dImmediateContext, dxutResourceManager, DXUTLINEHEIGHT );

	return S_OK;
}
Ejemplo n.º 7
0
HRESULT CALLBACK GameApp::OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc,
	void* pUserContext )
{
	HRESULT hr;
	ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext();
	V_RETURN(g_pApp->g_DialogResourceManager.OnD3D11CreateDevice(pd3dDevice, pd3dImmediateContext));
	return S_OK;
}
Ejemplo n.º 8
0
//--------------------------------------------------------------------------------------
// Create any D3D11 resources that aren't dependant on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK DXUTHelper::AppD3D11CreateDevice(ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc,
	void* pUserContext)
{

	auto pD3D11DeviceContext = DXUTGetD3D11DeviceContext();
	g_RenderSystem.Init(pd3dDevice, pD3D11DeviceContext);

	return S_OK;
}
Ejemplo n.º 9
0
//
// D3DShaderMeshNode11::VRender								- Chapter 16, page 564
//
HRESULT D3DShaderMeshNode11::VRender(Scene *pScene)
{
	HRESULT hr;

	V_RETURN (m_VertexShader.SetupRender(pScene, this) );
	V_RETURN (m_PixelShader.SetupRender(pScene, this) );

    //Get the Mesh
	Resource resource(m_sdkMeshFileName);
    shared_ptr<ResHandle> pResourceHandle = g_pApp->m_ResCache->GetHandle(&resource);  	
	shared_ptr<D3DSdkMeshResourceExtraData11> extra = static_pointer_cast<D3DSdkMeshResourceExtraData11>(pResourceHandle->GetExtra());

	// FUTURE WORK - this code WON'T be able to find texture resources referred to by the sdkmesh file 
    // in the Resource cache.

    //IA setup
    UINT Strides[1];
    UINT Offsets[1];
    ID3D11Buffer* pVB[1];
    pVB[0] = extra->m_Mesh11.GetVB11( 0, 0 );
    Strides[0] = ( UINT )extra->m_Mesh11.GetVertexStride( 0, 0 );
    Offsets[0] = 0;
    DXUTGetD3D11DeviceContext()->IASetVertexBuffers( 0, 1, pVB, Strides, Offsets );
    DXUTGetD3D11DeviceContext()->IASetIndexBuffer( extra->m_Mesh11.GetIB11( 0 ), extra->m_Mesh11.GetIBFormat11( 0 ), 0 );

    //Render
    D3D11_PRIMITIVE_TOPOLOGY PrimType;
    for( UINT subset = 0; subset < extra->m_Mesh11.GetNumSubsets( 0 ); ++subset )
    {
        // Get the subset
        SDKMESH_SUBSET *pSubset = extra->m_Mesh11.GetSubset( 0, subset );

        PrimType = CDXUTSDKMesh::GetPrimitiveType11( ( SDKMESH_PRIMITIVE_TYPE )pSubset->PrimitiveType );
        DXUTGetD3D11DeviceContext()->IASetPrimitiveTopology( PrimType );
 
        ID3D11ShaderResourceView* pDiffuseRV = extra->m_Mesh11.GetMaterial( pSubset->MaterialID )->pDiffuseRV11;
        DXUTGetD3D11DeviceContext()->PSSetShaderResources( 0, 1, &pDiffuseRV );

        DXUTGetD3D11DeviceContext()->DrawIndexed( ( UINT )pSubset->IndexCount, 0, ( UINT )pSubset->VertexStart );
    }
	return S_OK;
}
Ejemplo n.º 10
0
Renderer::Renderer( ID3D11Device *pd3dDevice )
{
	pd3dDevice_ = pd3dDevice;
	pd3dImmediateContext_ = DXUTGetD3D11DeviceContext();

	TR_ = new RenderTargets(pd3dDevice);
	RS_ = new RasterStates(pd3dDevice);
	SAMP_ = new SamplerStates(pd3dDevice);
	DSS_ = new DepthStencilStates(pd3dDevice);
	Shader_ = new Shader(pd3dDevice, pd3dImmediateContext_);
}
Ejemplo n.º 11
0
//
// D3DSkyNode11::VRender						- Chapter 16, page 559
//
HRESULT D3DSkyNode11::VRender(Scene *pScene)
{
	HRESULT hr;

	V_RETURN (m_VertexShader.SetupRender(pScene, this) );
	V_RETURN (m_PixelShader.SetupRender(pScene, this) );

    // Set vertex buffer
    UINT stride = sizeof( D3D11Vertex_UnlitTextured );
    UINT offset = 0;
    DXUTGetD3D11DeviceContext()->IASetVertexBuffers( 0, 1, &m_pVertexBuffer, &stride, &offset );

	// Set index buffer
    DXUTGetD3D11DeviceContext()->IASetIndexBuffer( m_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0 );

    // Set primitive topology
    DXUTGetD3D11DeviceContext()->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

	for (DWORD side = 0; side < m_sides; side++)
	{
		// FUTURTE WORK: A good optimization would be to transform the camera's
		// world look vector into local space, and do a dot product. If the
		// result is positive, we shouldn't draw the side since it has to be
		// behind the camera!

		// Sky boxes aren't culled by the normal mechanism

		/***
		// [mrmike] - This was slightly changed post press, look at the lines below this commented out code
		const char *suffix[] = { "_n.jpg", "_e.jpg",  "_s.jpg",  "_w.jpg",  "_u.jpg" };
		name += suffix[side];
		****/

		std::string name = GetTextureName(side);
		m_PixelShader.SetTexture(name.c_str());

		DXUTGetD3D11DeviceContext()->DrawIndexed( 6, side * 6, 0 );
	}
	return S_OK;
}
HRESULT D3DShaderMeshNode11::Render(Scene* pScene)
{
	HRESULT hr;

	V_RETURN(m_VertexShader.SetupRender(pScene, this));
	V_RETURN(m_PixelShader.SetupRender(pScene, this));

	// get the mesh from cache
	Resource resource(m_sdkMeshFileName);
	shared_ptr<ResHandle> pResourceHandle = g_pApp->m_ResCache->GetHandle(&resource);
	shared_ptr<D3DSdkMeshResourceExtraData11> extra = static_pointer_cast<D3DSdkMeshResourceExtraData11>(pResourceHandle->GetExtra());

	// set up buffers
	UINT strides[1];
	UINT offsets[1];
	ID3D11Buffer* pVertexBuffer[1];
	pVertexBuffer[0] = extra->m_Mesh11.GetVB11(0, 0);
	strides[0] = (UINT)extra->m_Mesh11.GetVertexStride(0, 0);
	offsets[0] = 0;
	DXUTGetD3D11DeviceContext()->IASetVertexBuffers(0, 1, pVertexBuffer, strides, offsets);
	DXUTGetD3D11DeviceContext()->IASetIndexBuffer(extra->m_Mesh11.GetIB11(0), extra->m_Mesh11.GetIBFormat11(0), 0);

	// render
	D3D11_PRIMITIVE_TOPOLOGY primType;
	for (UINT subset = 0; subset < extra->m_Mesh11.GetNumSubsets(0); ++subset)
	{
		SDKMESH_SUBSET* pSubset = extra->m_Mesh11.GetSubset(0, subset);

		primType = CDXUTSDKMesh::GetPrimitiveType11((SDKMESH_PRIMITIVE_TYPE)pSubset->PrimitiveType);
		DXUTGetD3D11DeviceContext()->IASetPrimitiveTopology(primType);

		ID3D11ShaderResourceView* pDiffuseRV = extra->m_Mesh11.GetMaterial(pSubset->MaterialID)->pDiffuseRV11;
		DXUTGetD3D11DeviceContext()->PSSetShaderResources(0, 1, &pDiffuseRV);

		DXUTGetD3D11DeviceContext()->DrawIndexed((UINT)pSubset->IndexCount, 0, (UINT)pSubset->VertexStart);
	}

	return S_OK;
}
Ejemplo n.º 13
0
static HRESULT CALLBACK on_device_create( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc,
    void* pUserContext )
{
    g_render_context.reset(new c_render_system_context(DXUTGetD3D11Device(), 
        DXUTGetD3D11DeviceContext(), 
        DXUTGetDXGIBackBufferSurfaceDesc(), 
        DXUTGetDXGISwapChain())); 

    g_scene->on_create_resource(g_render_context); 
    g_resolver->on_create_resource(g_render_context);

    return S_OK;
}
Ejemplo n.º 14
0
HRESULT CALLBACK OnD3D11CreateDevice(ID3D11Device* d3dDevice, const DXGI_SURFACE_DESC* backBufferSurfaceDesc,
                                     void* userContext)
{    
    ID3D11DeviceContext* d3dDeviceContext = DXUTGetD3D11DeviceContext();
    gDialogResourceManager.OnD3D11CreateDevice(d3dDevice, d3dDeviceContext);
    gD3DSettingsDlg.OnD3D11CreateDevice(d3dDevice);
    gTextHelper = new CDXUTTextHelper(d3dDevice, d3dDeviceContext, &gDialogResourceManager, 15);
    
    gViewerCamera.SetRotateButtons(true, false, false);
    gViewerCamera.SetDrag(true);
    gViewerCamera.SetEnableYAxisMovement(true);

    return S_OK;
}
Ejemplo n.º 15
0
//--------------------------------------------------------------------------------------
// Create any D3D11 resources that depend on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK DXUTHelper::AppD3D11ResizedSwapChain(ID3D11Device* pd3dDevice, IDXGISwapChain* pSwapChain,
	const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext)
{
	// Setup the projection parameters
	float fWidth = static_cast<float>(pBackBufferSurfaceDesc->Width);
	float fHeight = static_cast<float>(pBackBufferSurfaceDesc->Height);

	auto pD3D11DeviceContext = DXUTGetD3D11DeviceContext();

	g_RenderSystem.init_camera(fWidth, fHeight, pD3D11DeviceContext);


	return S_OK;
}
Ejemplo n.º 16
0
void MeshSkeletal::Render( CompileShader* pshader )
{
	if (pshader == nullptr)
		return;

	DXUTGetD3D11DeviceContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	UINT stride = sizeof(VERTEXSKELETAL);
	UINT offset = 0;
	for (int i = 0; i < m_model.numSubsets; i++)
	{
		//인덱스 버퍼
		DXUTGetD3D11DeviceContext()->IASetIndexBuffer(m_model.subsets[i].indexBuff, DXGI_FORMAT_R32_UINT, 0);
		//버텍스 버퍼
		DXUTGetD3D11DeviceContext()->IASetVertexBuffers(0, 1, &m_model.subsets[i].vertBuff, &stride, &offset);

		//텍스쳐 설정
		DXUTGetD3D11DeviceContext()->PSSetShaderResources(0, 1, &m_textures[m_model.subsets[i].texArrayIndex]);
		
		//그리기
		DXUTGetD3D11DeviceContext()->DrawIndexed(m_model.subsets[i].indices.size(), 0, 0);
	}
}
Ejemplo n.º 17
0
//--------------------------------------------------------------------------------------
// Create any D3D11 resources that aren't dependant on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc,
									  void* pUserContext )
{
	vegetationRendering = new VegetationRendering();

	Window::setHandle(DXUTGetHWND());

	ID3D11DeviceContext* deviceContext = DXUTGetD3D11DeviceContext();
	dialogResourceManager.OnD3D11CreateDevice(pd3dDevice, deviceContext);
	textHelper = CDXUTTextHelper(pd3dDevice, deviceContext, &dialogResourceManager, 30);

	vegetationRendering->init(pd3dDevice);

	return S_OK;
}
Ejemplo n.º 18
0
void CUDARayCastSDF::rayIntervalSplatting(const HashData& hashData, const HashParams& hashParams, const DepthCameraData& cameraData, const mat4f& lastRigidTransform)
{
	if (hashParams.m_numOccupiedBlocks == 0)	return;

	if (m_params.m_maxNumVertices <= 6*hashParams.m_numOccupiedBlocks) { // 6 verts (2 triangles) per block
		MLIB_EXCEPTION("not enough space for vertex buffer for ray interval splatting");
	}

	m_params.m_numOccupiedSDFBlocks = hashParams.m_numOccupiedBlocks;
	m_params.m_viewMatrix = MatrixConversion::toCUDA(lastRigidTransform.getInverse());
	m_params.m_viewMatrixInverse = MatrixConversion::toCUDA(lastRigidTransform);

	//m_data.updateParams(m_params); // !!! debugging

	m_rayIntervalSplatting.rayIntervalSplatting(DXUTGetD3D11DeviceContext(), hashData, cameraData, m_data, m_params, m_params.m_numOccupiedSDFBlocks*6);
}
    int RSMRenderer::ReadbackNumVPLs()
    {
        ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext();
        int NumVPLs = 0;

        pd3dImmediateContext->CopyStructureCount( m_pCPUReadbackConstantBuffer, 0, m_pVPLBufferCenterAndRadiusUAV );

        D3D11_MAPPED_SUBRESOURCE resource;
        if ( pd3dImmediateContext->Map( m_pCPUReadbackConstantBuffer, 0, D3D11_MAP_READ, 0, &resource ) == S_OK )
        {
            NumVPLs = *( (int*)resource.pData );

            pd3dImmediateContext->Unmap( m_pCPUReadbackConstantBuffer, 0 );
        }

        return NumVPLs;
    }
Ejemplo n.º 20
0
//--------------------------------------------------------------------------------------
// Create any D3D11 resources that aren't dependent 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);

    V_RETURN(g_Scene.OnD3D11CreateDevice(pd3dDevice));

    // Setup the camera   
    XMVECTOR vecEye = XMVectorSet(0.0f, 0.5f, -3.0f, 0);
    XMVECTOR vecAt = XMVectorSet(0.0f, 0.0f, 0.0f, 0);
    g_Camera.SetViewParams(vecEye, vecAt);

    g_OIT.OnD3D11CreateDevice(pd3dDevice);
    return S_OK;
}
    void RSMRenderer::RenderRSMScene( const GuiState& CurrentGuiState, const Scene& Scene, const CommonUtil& CommonUtil )
    {
        ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext();

        pd3dImmediateContext->OMSetDepthStencilState( CommonUtil.GetDepthStencilState(DEPTH_STENCIL_STATE_DEPTH_LESS), 0x00 ); 
        pd3dImmediateContext->IASetInputLayout( m_pRSMLayout );
        pd3dImmediateContext->VSSetShader( m_pRSMVS, NULL, 0 );
        pd3dImmediateContext->PSSetShader( m_pRSMPS, NULL, 0 );
        pd3dImmediateContext->PSSetSamplers( 0, 1, CommonUtil.GetSamplerStateParam(SAMPLER_STATE_POINT) );

        // Draw the main scene
        Scene.m_pSceneMesh->Render( pd3dImmediateContext, 0, 1 );

        // Draw the grid objects (i.e. the "lots of triangles" system)
        for( int i = 0; i < CurrentGuiState.m_nNumGridObjects; i++ )
        {
            CommonUtil.DrawGrid(i, CurrentGuiState.m_nGridObjectTriangleDensity);
        }

        // Skip the alpha-test geometry
    }
void ShadowRenderer::RenderPointMap( int numShadowCastingPointLights )
{
    AMDProfileEvent( AMD_PROFILE_RED, L"PointShadows" );

    ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext();

    D3D11_VIEWPORT oldVp[ 8 ];
    UINT numVPs = 1;
    pd3dImmediateContext->RSGetViewports( &numVPs, oldVp );

    D3D11_VIEWPORT vp;
    vp.Width = gPointShadowResolution;
    vp.Height = gPointShadowResolution;
    vp.MinDepth = 0.0f;
    vp.MaxDepth = 1.0f;

    pd3dImmediateContext->ClearDepthStencilView( m_pPointAtlasView, D3D11_CLEAR_DEPTH, 1.0f, 0 );

    ID3D11RenderTargetView* pNULLRTV = NULL;
    pd3dImmediateContext->OMSetRenderTargets( 1, &pNULLRTV, m_pPointAtlasView );

    const XMMATRIX (*PointLightViewProjArray)[6] = LightUtil::GetShadowCastingPointLightViewProjTransposedArray();

    for ( int p = 0; p < numShadowCastingPointLights; p++ )
    {
        vp.TopLeftY = (float)p * gPointShadowResolution;

        for ( int i = 0; i < 6; i++ )
        {
            m_CameraCallback( PointLightViewProjArray[p][i] );

            vp.TopLeftX = (float)i * gPointShadowResolution;
            pd3dImmediateContext->RSSetViewports( 1, &vp );

            m_RenderCallback();
        }
    }

    pd3dImmediateContext->RSSetViewports( 1, oldVp );
}
Ejemplo n.º 23
0
//--------------------------------------------------------------------------------------
// Initialization
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnCreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
	HRESULT hr;
	ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext();

	V_RETURN( g_pDialogResourceManager->OnD3D11CreateDevice( pd3dDevice, pd3dImmediateContext ) );
	
	g_pTxtHelper = new CDXUTTextHelper( pd3dDevice, pd3dImmediateContext, g_pDialogResourceManager, 15 );

	V_RETURN( pd3dDevice->CreateVertexShader( g_ParticleVS, sizeof(g_ParticleVS), NULL, &g_pVertexShader ) );

	V_RETURN( pd3dDevice->CreateGeometryShader( g_ParticleGS, sizeof(g_ParticleGS), NULL, &g_pGeometryShader ) );

	V_RETURN( pd3dDevice->CreatePixelShader( g_ParticlePS, sizeof(g_ParticlePS), NULL, &g_pPixelShader ) );
	
	// Create VB
	D3D11_BUFFER_DESC bufferDesc;
	ZeroMemory( &bufferDesc, sizeof(bufferDesc) );
	bufferDesc.ByteWidth = sizeof(ParticleVertex) * FluidVertexBufferSize;
	bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
	bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;

	V_RETURN( pd3dDevice->CreateBuffer( &bufferDesc, NULL, &g_pVertexBuffer ) );

	bufferDesc.ByteWidth = sizeof(ConstantBuffer);
	bufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	V_RETURN( pd3dDevice->CreateBuffer( &bufferDesc, NULL, &g_pConstantBuffer ) );
	
	// Create the IA layout
	D3D11_INPUT_ELEMENT_DESC layout[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};

	V_RETURN( pd3dDevice->CreateInputLayout( layout, _countof(layout), g_ParticleVS, sizeof(g_ParticleVS), &g_pVertexLayout ) );
	
	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;
}
Ejemplo n.º 25
0
//--------------------------------------------------------------------------------------
// 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;
}
    void RSMRenderer::GenerateVPLs( int NumSpotLights, int NumPointLights, const LightUtil& LightUtil )
    {
        ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext();

        ID3D11UnorderedAccessView* pUAVs[] = { m_pVPLBufferCenterAndRadiusUAV, m_pVPLBufferDataUAV };

        // Clear the VPL counter
        UINT InitialCounts[ 2 ] = { 0, 0 };
        pd3dImmediateContext->CSSetUnorderedAccessViews( 0, ARRAYSIZE( pUAVs ), pUAVs, InitialCounts );

        const int numThreadsX = 16;
        const int numThreadsY = 16;

        const int sampleKernel = 2;

        if ( NumSpotLights > 0 )
        {
            ID3D11ShaderResourceView* pSRVs[] = 
			{ 
				m_SpotAtlas.m_pDepthSRV, 
				m_SpotAtlas.m_pNormalSRV, 
				m_SpotAtlas.m_pDiffuseSRV, 
				m_pSpotInvViewProjBufferSRV, 
				*LightUtil.GetSpotLightBufferCenterAndRadiusSRVParam(LIGHTING_SHADOWS),  
				*LightUtil.GetSpotLightBufferColorSRVParam(LIGHTING_SHADOWS),
				*LightUtil.GetSpotLightBufferSpotParamsSRVParam(LIGHTING_SHADOWS)
			};
            pd3dImmediateContext->CSSetShaderResources( 0, ARRAYSIZE( pSRVs ), pSRVs );
            pd3dImmediateContext->CSSetShader( m_pGenerateSpotVPLsCS, 0, 0 );

            int dispatchCountX = (NumSpotLights * gRSMSpotResolution/sampleKernel) / numThreadsX;
            int dispatchCountY = (gRSMSpotResolution/sampleKernel) / numThreadsY;

            pd3dImmediateContext->Dispatch( dispatchCountX, dispatchCountY, 1 );

            ZeroMemory( pSRVs, sizeof( pSRVs ) );
            pd3dImmediateContext->CSSetShaderResources( 0, ARRAYSIZE( pSRVs ), pSRVs );
        }

        if ( NumPointLights > 0  )
        {
            ID3D11ShaderResourceView* pSRVs[] = 
			{ 
				m_PointAtlas.m_pDepthSRV, 
				m_PointAtlas.m_pNormalSRV, 
				m_PointAtlas.m_pDiffuseSRV, 
				m_pPointInvViewProjBufferSRV, 
				*LightUtil.GetPointLightBufferCenterAndRadiusSRVParam(LIGHTING_SHADOWS),
				*LightUtil.GetPointLightBufferColorSRVParam(LIGHTING_SHADOWS)
			};
            pd3dImmediateContext->CSSetShaderResources( 0, ARRAYSIZE( pSRVs ), pSRVs );
            pd3dImmediateContext->CSSetShader( m_pGeneratePointVPLsCS, 0, 0 );

            int dispatchCountX = (6 * gRSMPointResolution/sampleKernel) / numThreadsX;
            int dispatchCountY = (NumPointLights * gRSMPointResolution/sampleKernel) / numThreadsY;

            pd3dImmediateContext->Dispatch( dispatchCountX, dispatchCountY, 1 );

			ZeroMemory( pSRVs, sizeof( pSRVs ) );
            pd3dImmediateContext->CSSetShaderResources( 0, ARRAYSIZE( pSRVs ), pSRVs );
        }

        ID3D11UnorderedAccessView* pNullUAVs[] = { NULL, NULL };
        pd3dImmediateContext->CSSetUnorderedAccessViews( 0, ARRAYSIZE( pNullUAVs ), pNullUAVs, NULL );

        // Copy the number of items counter from the UAV into a constant buffer for reading in the forward pass
        pd3dImmediateContext->CopyStructureCount( m_pNumVPLsConstantBuffer, 0, m_pVPLBufferCenterAndRadiusUAV );

        pd3dImmediateContext->CSSetConstantBuffers( 4, 1, &m_pNumVPLsConstantBuffer );
        pd3dImmediateContext->PSSetConstantBuffers( 4, 1, &m_pNumVPLsConstantBuffer );
    }
Ejemplo n.º 27
0
HRESULT DX11SceneRepHashSDF::CreateBuffers( ID3D11Device* pd3dDevice )
{
	HRESULT hr = S_OK;

	m_LastRigidTransform.setIdentity();


	D3D11_BUFFER_DESC bDesc;
	ZeroMemory(&bDesc, sizeof(D3D11_BUFFER_DESC));
	bDesc.BindFlags	= D3D11_BIND_CONSTANT_BUFFER;
	bDesc.Usage	= D3D11_USAGE_DYNAMIC;
	bDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	bDesc.MiscFlags	= 0;
	bDesc.ByteWidth	= sizeof(CB_VOXEL_HASH_SDF);
	V_RETURN(pd3dDevice->CreateBuffer(&bDesc, NULL, &m_SDFVoxelHashCB));


	D3D11_BUFFER_DESC descBUF;
	D3D11_SHADER_RESOURCE_VIEW_DESC descSRV;
	D3D11_UNORDERED_ACCESS_VIEW_DESC descUAV;

	//create hash buffers/uav/srv (each element is a int3 -> (short3, short, int))
	ZeroMemory(&descBUF, sizeof(D3D11_BUFFER_DESC));
	descBUF.BindFlags	= D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE;
	descBUF.Usage	= D3D11_USAGE_DEFAULT;
	descBUF.CPUAccessFlags = 0;
	descBUF.MiscFlags	= 0;
	descBUF.ByteWidth	= sizeof(int) * 3 * m_HashBucketSize * m_HashNumBuckets;
	descBUF.StructureByteStride = sizeof(int);

	ZeroMemory( &descSRV, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC) );
	descSRV.Format = DXGI_FORMAT_R32_SINT;
	descSRV.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
	descSRV.Buffer.FirstElement = 0;
	descSRV.Buffer.NumElements = 3 * m_HashBucketSize * m_HashNumBuckets;

	ZeroMemory( &descUAV, sizeof(D3D11_UNORDERED_ACCESS_VIEW_DESC) );
	descUAV.Format = DXGI_FORMAT_R32_SINT;
	descUAV.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
	descUAV.Buffer.FirstElement = 0;
	descUAV.Buffer.NumElements =  3 * m_HashBucketSize * m_HashNumBuckets;

	D3D11_SUBRESOURCE_DATA InitData;
	ZeroMemory( &InitData, sizeof(D3D11_SUBRESOURCE_DATA) );
	int* cpuNull = new int[3 * m_HashBucketSize * m_HashNumBuckets];
	for (unsigned int i = 0; i < m_HashBucketSize * m_HashNumBuckets; i++) {
		cpuNull[3*i+0] = 0;
		cpuNull[3*i+1] = 0;
		cpuNull[3*i+2] = -2;	//marks free memory
	}
	InitData.pSysMem = cpuNull;
	V_RETURN(pd3dDevice->CreateBuffer(&descBUF, &InitData, &m_Hash));
	V_RETURN(pd3dDevice->CreateBuffer(&descBUF, &InitData, &m_HashCompactified));
	SAFE_DELETE_ARRAY(cpuNull);

	V_RETURN(pd3dDevice->CreateShaderResourceView(m_Hash, &descSRV, &m_HashSRV));
	V_RETURN(pd3dDevice->CreateShaderResourceView(m_HashCompactified, &descSRV, &m_HashCompactifiedSRV));
	V_RETURN(pd3dDevice->CreateUnorderedAccessView(m_Hash, &descUAV, &m_HashUAV));
	V_RETURN(pd3dDevice->CreateUnorderedAccessView(m_HashCompactified, &descUAV, &m_HashCompactifiedUAV));

	if (!m_JustHashAndNoSDFBlocks)	{

		//create hash mutex
		ZeroMemory(&descBUF, sizeof(D3D11_BUFFER_DESC));
		descBUF.BindFlags	= D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE;
		descBUF.Usage	= D3D11_USAGE_DEFAULT;
		descBUF.CPUAccessFlags = 0;
		descBUF.MiscFlags	= 0;
		descBUF.ByteWidth	= sizeof(unsigned int) * m_HashNumBuckets;
		descBUF.StructureByteStride = sizeof(unsigned int);

		ZeroMemory( &descSRV, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC) );
		descSRV.Format = DXGI_FORMAT_R32_UINT;
		descSRV.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
		descSRV.Buffer.FirstElement = 0;
		descSRV.Buffer.NumElements = m_HashNumBuckets;

		ZeroMemory( &descUAV, sizeof(D3D11_UNORDERED_ACCESS_VIEW_DESC) );
		descUAV.Format = DXGI_FORMAT_R32_UINT;
		descUAV.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
		descUAV.Buffer.FirstElement = 0;
		descUAV.Buffer.NumElements = m_HashNumBuckets;

		ZeroMemory( &InitData, sizeof(D3D11_SUBRESOURCE_DATA) );
		cpuNull = new int[m_HashNumBuckets];
		for (unsigned int i = 0; i < m_HashNumBuckets; i++) {
			cpuNull[i] = 0;
		}
		InitData.pSysMem = cpuNull;
		V_RETURN(pd3dDevice->CreateBuffer(&descBUF, &InitData, &m_HashBucketMutex));
		SAFE_DELETE_ARRAY(cpuNull);

		V_RETURN(pd3dDevice->CreateShaderResourceView(m_HashBucketMutex, &descSRV, &m_HashBucketMutexSRV));
		V_RETURN(pd3dDevice->CreateUnorderedAccessView(m_HashBucketMutex, &descUAV, &m_HashBucketMutexUAV));



		//create heap (unsigned int -> ptr to data blocks)
		ZeroMemory(&descBUF, sizeof(D3D11_BUFFER_DESC));
		descBUF.BindFlags	= D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE;
		descBUF.Usage	= D3D11_USAGE_DEFAULT;
		descBUF.CPUAccessFlags = 0;
		descBUF.MiscFlags	= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
		descBUF.ByteWidth	= sizeof(unsigned int) * m_SDFNumBlocks;
		descBUF.StructureByteStride = sizeof(unsigned int);

		ZeroMemory (&descSRV, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC));
		descSRV.Format = DXGI_FORMAT_UNKNOWN;
		descSRV.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
		descSRV.Buffer.FirstElement = 0;
		descSRV.Buffer.NumElements = m_SDFNumBlocks;

		ZeroMemory( &descUAV, sizeof(D3D11_UNORDERED_ACCESS_VIEW_DESC) );
		descUAV.Format = DXGI_FORMAT_UNKNOWN;
		descUAV.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
		descUAV.Buffer.FirstElement = 0;
		descUAV.Buffer.Flags = D3D11_BUFFER_UAV_FLAG_APPEND;
		descUAV.Buffer.NumElements =  m_SDFNumBlocks;

		cpuNull = new int[m_SDFNumBlocks];
		for (unsigned int i = 0; i < m_SDFNumBlocks; i++) {
			cpuNull[i] = m_SDFNumBlocks - i - 1;
		}
		InitData.pSysMem = cpuNull;
		V_RETURN(pd3dDevice->CreateBuffer(&descBUF, &InitData, &m_Heap));
		SAFE_DELETE_ARRAY(cpuNull);
		V_RETURN(pd3dDevice->CreateShaderResourceView(m_Heap, &descSRV, &m_HeapSRV));
		V_RETURN(pd3dDevice->CreateUnorderedAccessView(m_Heap, &descUAV, &m_HeapUAV));

		ZeroMemory( &descUAV, sizeof(D3D11_UNORDERED_ACCESS_VIEW_DESC) );
		descUAV.Format = DXGI_FORMAT_UNKNOWN;
		descUAV.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
		descUAV.Buffer.FirstElement = 0;
		descUAV.Buffer.Flags = 0;
		descUAV.Buffer.NumElements = m_SDFNumBlocks;
		V_RETURN(pd3dDevice->CreateUnorderedAccessView(m_Heap, &descUAV, &m_HeapStaticUAV))


		ZeroMemory(&descBUF, sizeof(D3D11_BUFFER_DESC));
		descBUF.BindFlags	= 0;
		descBUF.Usage	= D3D11_USAGE_STAGING;
		descBUF.CPUAccessFlags =  D3D11_CPU_ACCESS_READ;
		descBUF.MiscFlags	= 0;
		descBUF.ByteWidth	= sizeof(int);
		V_RETURN(pd3dDevice->CreateBuffer(&descBUF, NULL, &m_HeapFreeCount));

		unsigned int initalCount = m_SDFNumBlocks;
		DXUTGetD3D11DeviceContext()->CSSetUnorderedAccessViews(0, 1, &m_HeapUAV, &initalCount);
		ID3D11UnorderedAccessView* nullUAV[] = {NULL};
		DXUTGetD3D11DeviceContext()->CSSetUnorderedAccessViews(0, 1, nullUAV, NULL);


		//create sdf blocks (8x8x8 -> 8 byte per voxel: SDF part)
		ZeroMemory(&descBUF, sizeof(D3D11_BUFFER_DESC));
		descBUF.BindFlags	= D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE;
		descBUF.Usage	= D3D11_USAGE_DEFAULT;
		descBUF.CPUAccessFlags = 0;
		descBUF.MiscFlags	= 0;
		descBUF.ByteWidth	= (sizeof(float)) * m_SDFBlockSize * m_SDFBlockSize * m_SDFBlockSize * m_SDFNumBlocks;
		descBUF.StructureByteStride = sizeof(int);

		ZeroMemory( &descSRV, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC) );
		descSRV.Format = DXGI_FORMAT_R32_FLOAT;
		descSRV.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
		descSRV.Buffer.FirstElement = 0;
		descSRV.Buffer.NumElements = m_SDFBlockSize * m_SDFBlockSize * m_SDFBlockSize * m_SDFNumBlocks;

		ZeroMemory( &descUAV, sizeof(D3D11_UNORDERED_ACCESS_VIEW_DESC) );
		descUAV.Format = DXGI_FORMAT_R32_FLOAT;
		descUAV.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
		descUAV.Buffer.FirstElement = 0;
		descUAV.Buffer.NumElements =  m_SDFBlockSize * m_SDFBlockSize * m_SDFBlockSize * m_SDFNumBlocks;


		ZeroMemory( &InitData, sizeof(D3D11_SUBRESOURCE_DATA) );
		cpuNull = new int[m_SDFBlockSize * m_SDFBlockSize * m_SDFBlockSize * m_SDFNumBlocks];
		ZeroMemory(cpuNull, sizeof(int) * m_SDFBlockSize * m_SDFBlockSize * m_SDFBlockSize * m_SDFNumBlocks);
		InitData.pSysMem = cpuNull;
		V_RETURN(pd3dDevice->CreateBuffer(&descBUF, &InitData, &m_SDFBlocksSDF));
		SAFE_DELETE_ARRAY(cpuNull);

		V_RETURN(pd3dDevice->CreateShaderResourceView(m_SDFBlocksSDF, &descSRV, &m_SDFBlocksSDFSRV));
		V_RETURN(pd3dDevice->CreateUnorderedAccessView(m_SDFBlocksSDF, &descUAV, &m_SDFBlocksSDFUAV));


		//create sdf blocks (8x8x8 -> 8 byte per voxel: RGBW part)
		ZeroMemory(&descBUF, sizeof(D3D11_BUFFER_DESC));
		descBUF.BindFlags	= D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE;
		descBUF.Usage	= D3D11_USAGE_DEFAULT;
		descBUF.CPUAccessFlags = 0;
		descBUF.MiscFlags	= 0;
		descBUF.ByteWidth	= sizeof(int) * m_SDFBlockSize * m_SDFBlockSize * m_SDFBlockSize * m_SDFNumBlocks;
		descBUF.StructureByteStride = sizeof(int);

		ZeroMemory( &descSRV, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC) );
		descSRV.Format = DXGI_FORMAT_R32_SINT;
		descSRV.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
		descSRV.Buffer.FirstElement = 0;
		descSRV.Buffer.NumElements = m_SDFBlockSize * m_SDFBlockSize * m_SDFBlockSize * m_SDFNumBlocks;

		ZeroMemory( &descUAV, sizeof(D3D11_UNORDERED_ACCESS_VIEW_DESC) );
		descUAV.Format = DXGI_FORMAT_R32_SINT;;
		descUAV.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
		descUAV.Buffer.FirstElement = 0;
		descUAV.Buffer.NumElements =  m_SDFBlockSize * m_SDFBlockSize * m_SDFBlockSize * m_SDFNumBlocks;


		ZeroMemory( &InitData, sizeof(D3D11_SUBRESOURCE_DATA) );
		cpuNull = new int[m_SDFBlockSize * m_SDFBlockSize * m_SDFBlockSize * m_SDFNumBlocks];
		ZeroMemory(cpuNull, sizeof(int) * m_SDFBlockSize * m_SDFBlockSize * m_SDFBlockSize * m_SDFNumBlocks);
		InitData.pSysMem = cpuNull;
		V_RETURN(pd3dDevice->CreateBuffer(&descBUF, &InitData, &m_SDFBlocksRGBW));
		SAFE_DELETE_ARRAY(cpuNull);

		V_RETURN(pd3dDevice->CreateShaderResourceView(m_SDFBlocksRGBW, &descSRV, &m_SDFBlocksRGBWSRV));
		V_RETURN(pd3dDevice->CreateUnorderedAccessView(m_SDFBlocksRGBW, &descUAV, &m_SDFBlocksRGBWUAV));

	}

	////////////////
	// Compactify //
	////////////////

	//create hash buffers/uav/srv (each element is a int3 -> (short3, short, int))
	ZeroMemory(&descBUF, sizeof(D3D11_BUFFER_DESC));
	descBUF.BindFlags	= D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE;
	descBUF.Usage	= D3D11_USAGE_DEFAULT;
	descBUF.CPUAccessFlags = 0;
	descBUF.MiscFlags	= 0;
	descBUF.ByteWidth	= sizeof(int) * m_HashBucketSize * m_HashNumBuckets;
	descBUF.StructureByteStride = sizeof(int);

	ZeroMemory( &descSRV, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC) );
	descSRV.Format = DXGI_FORMAT_R32_SINT;
	descSRV.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
	descSRV.Buffer.FirstElement = 0;
	descSRV.Buffer.NumElements = m_HashBucketSize * m_HashNumBuckets;

	ZeroMemory( &descUAV, sizeof(D3D11_UNORDERED_ACCESS_VIEW_DESC) );
	descUAV.Format = DXGI_FORMAT_R32_SINT;
	descUAV.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
	descUAV.Buffer.FirstElement = 0;
	descUAV.Buffer.NumElements =  m_HashBucketSize * m_HashNumBuckets;


	ZeroMemory( &InitData, sizeof(D3D11_SUBRESOURCE_DATA) );
	cpuNull = new int[m_HashBucketSize * m_HashNumBuckets];
	for (unsigned int i = 0; i < m_HashBucketSize * m_HashNumBuckets; i++) {
		cpuNull[i] = 0;
	}
	InitData.pSysMem = cpuNull;
	V_RETURN(pd3dDevice->CreateBuffer(&descBUF, &InitData, &m_HashIntegrateDecision));
	V_RETURN(pd3dDevice->CreateBuffer(&descBUF, &InitData, &m_HashIntegrateDecisionPrefix));
	SAFE_DELETE_ARRAY(cpuNull);

	V_RETURN(pd3dDevice->CreateShaderResourceView(m_HashIntegrateDecision, &descSRV, &m_HashIntegrateDecisionSRV));
	V_RETURN(pd3dDevice->CreateUnorderedAccessView(m_HashIntegrateDecision, &descUAV, &m_HashIntegrateDecisionUAV));

	V_RETURN(pd3dDevice->CreateShaderResourceView(m_HashIntegrateDecisionPrefix, &descSRV, &m_HashIntegrateDecisionPrefixSRV));
	V_RETURN(pd3dDevice->CreateUnorderedAccessView(m_HashIntegrateDecisionPrefix, &descUAV, &m_HashIntegrateDecisionPrefixUAV));



	return hr;
}
Ejemplo n.º 28
0
void HUD::init(ID3D11Device* graphicsDevice, Game* game)
{
	dialog.Init(&dialogResourceManager);
	dialog.SetCallback(HUD::onGuiEvent, game);

	ID3D11DeviceContext* deviceContext = DXUTGetD3D11DeviceContext();

	Terrain* terrain = game->terrain;
	Camera* camera = game->camera;

	textVisible = true;

	textHelper = CDXUTTextHelper(graphicsDevice, deviceContext, &dialogResourceManager, 15);

	unsigned width = 200;
	unsigned height = 20;
	unsigned delta = height * 2;
	unsigned i = 1;
	unsigned y = 0;

	WCHAR sz[200];

	float movementSpeed = camera->getMovementSpeed();
	StringCchPrintf(sz, 200, L"Camera Movement: %.1f", movementSpeed);
	dialog.AddStatic(CameraMovementStatic, sz, 0, y, width, height);
	dialog.AddSlider(CameraMovementSlider, 0, y + height, width, height, 1, 500, (int)movementSpeed);
	y += delta;

	float bumpiness = terrain->getBumpiness();
	StringCchPrintf(sz, 200, L"Bumpiness: %.1f", bumpiness);
	dialog.AddStatic(BumpinessStatic, sz, 0, y, width, height);
	dialog.AddSlider(BumpinessSlider, 0, y + height, width, height, 0, 2000, (int)bumpiness);
	y += delta;

	float minPixelPerTriangle = terrain->getMinPixelPerTriangle();
	StringCchPrintf(sz, 200, L"Triangle Size: %.1f", minPixelPerTriangle);
	dialog.AddStatic(MinPixelPerTriangleStatic, sz, 0, y, width, height);
	dialog.AddSlider(MinPixelPerTriangleSlider, 0, y + height, width, height, 0, 20000, (int)(minPixelPerTriangle * 100.0f));
	y += delta;

	float roughnessModificator = terrain->getRoughnessModificator();
	StringCchPrintf(sz, 200, L"Roughness Modificator: %.2f", roughnessModificator);
	dialog.AddStatic(RoughnessModificatorStatic, sz, 0, y, width, height);
	dialog.AddSlider(RoughnessModificatorSlider, 0, y + height, width, height, 0, 1000, (int)(roughnessModificator * 100.0f));
	y += delta;
	
	float textureRepeat = terrain->getColormapRepeat();
	StringCchPrintf(sz, 200, L"Texture Repeat: %.1f", textureRepeat);
	dialog.AddStatic(TextureRepeatStatic, sz, 0, y, width, height);
	dialog.AddSlider(TextureRepeatSlider, 0, y + height, width, height, 1, 1024, (int)textureRepeat);
	y += delta;

	delta = (unsigned)(height * 1.2f);

	dialog.AddCheckBox(WireframeCheckbox, L"Wireframe (TAB)", 0, y + delta * i++, width, height, game->isWireframe(), VK_TAB); 
	dialog.AddCheckBox(UpdateLODCheckbox, L"Update LOD", 0, y + delta * i++, width, height, !camera->isLocked()); 
	dialog.AddCheckBox(CPUFrustumCullingCheckbox, L"CPU Frustum Culling", 0, y + delta * i++, width, height, terrain->getCPUFrustumCullingEnabled()); 
	dialog.AddCheckBox(GPUFrustumCullingCheckbox, L"GPU Frustum Culling", 0, y + delta * i++, width, height, terrain->getGPUFrustumCullingEnabled()); 
	dialog.AddCheckBox(SnapToTerrainCheckbox, L"Snap to Terrain", 0, y + delta * i++, width, height, !game->isFreeCamera()); 
	dialog.AddCheckBox(ColormapCheckbox, L"Colormap", 0, y + delta * i++, width, height, terrain->getColormapEnabled());
	dialog.AddCheckBox(LightingCheckbox, L"Lighting", 0, y + delta * i++, width, height, terrain->getLightingEnabled()); 
	dialog.AddCheckBox(HeightTextureCheckbox, L"Height-based Texturing", 0, y + delta * i++, width, height, terrain->getHeightTextureEnabled());
	dialog.AddCheckBox(SlopeTextureCheckbox, L"Slope-based Texturing", 0, y + delta * i++, width, height, terrain->getSlopeTextureEnabled());
	dialog.AddCheckBox(RoughnessCheckbox, L"Enable Roughness", 0, y + delta * i++, width, height, terrain->getRoughnessEnabled());
	dialog.AddCheckBox(AntiShimmeringCheckbox, L"Anti Shimmering", 0, y + delta * i++, width, height, terrain->getAntiShimmeringEnabled());
	dialog.AddCheckBox(ShowNodesCheckbox, L"Show Nodes", 0, y + delta * i++, width, height, terrain->getShowNodesEnabled());
	dialog.AddCheckBox(UniformPatchSizeCheckbox, L"Uniform Patch Size", 0, y + delta * i++, width, height, terrain->getUniformPatchSizeEnabled());
	dialog.AddCheckBox(BruteForceCheckbox, L"Brute Force", 0, y + delta * i++, width, height, terrain->getBruteForceEnabled());

	dialogResourceManager.OnD3D11CreateDevice(graphicsDevice, deviceContext);
}
//--------------------------------------------------------------------------------------
// 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;
}
Ejemplo n.º 30
0
//--------------------------------------------------------------------------------------
// 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; 

    static bool bFirstOnCreateDevice = true;

    // Warn the user that in order to support CS4x, a non-hardware device has been created, continue or quit?
    if ( DXUTGetDeviceSettings().d3d11.DriverType != D3D_DRIVER_TYPE_HARDWARE && bFirstOnCreateDevice )
    {
        if ( MessageBox( 0, L"CS4x capability is missing. "\
                            L"In order to continue, a non-hardware device has been created, "\
                            L"it will be very slow, continue?", L"Warning", MB_ICONEXCLAMATION | MB_YESNO ) != IDYES )
            return E_FAIL;
    }

    bFirstOnCreateDevice = false;

    ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext();
    V_RETURN( g_DialogResourceManager.OnD3D11CreateDevice( pd3dDevice, pd3dImmediateContext ) );
    V_RETURN( g_D3DSettingsDlg.OnD3D11CreateDevice( pd3dDevice ) );
    V_RETURN( g_Tessellator.OnD3D11CreateDevice( pd3dDevice ) );
    g_pTxtHelper = new CDXUTTextHelper( pd3dDevice, pd3dImmediateContext, &g_DialogResourceManager, 15 );

    // find the file
    WCHAR str[MAX_PATH];
    V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"BaseMesh.obj" ) );

    std::wifstream ifs( str );
    WCHAR line[256] = {0};
    CGrowableArray<D3DXVECTOR4> initdata;

    // Parse the .obj file. Both triangle faces and quad faces are supported.
    // Only v and f tags are processed, other tags like vn, vt etc are ignored.
    {
        CGrowableArray<D3DXVECTOR4> v;

        while ( ifs >> line )
        {
            if ( 0 == wcscmp( line, L"#" ) ) 
                ifs.getline( line, 255 );
            else
            if ( 0 == wcscmp( line, L"v" ) )
            {
                D3DXVECTOR4 pos;
                ifs >> pos.x >> pos.y >> pos.z;
                pos.w = 1;
                v.Add( pos );
            }
        }

        ifs.clear( 0 );
        ifs.seekg( 0 );
        while ( ifs >> line )
        {
            if ( 0 == wcscmp( line, L"#" ) ) 
                ifs.getline( line, 255 );
            else
            if ( 0 == wcscmp( line, L"f" ) )
            {
                ifs.getline( line, 255 );
                std::wstringstream ss(line);
                int idx[4], i = 0;
                while ( ss >> line )
                {
                    std::wstringstream ss(line);
                    ss >> idx[i++];
                }
                
                initdata.Add( v[idx[0]-1] ); initdata.Add( v[idx[1]-1] ); initdata.Add( v[idx[2]-1] );
                if ( i >= 4 ) // quad face?
                {
                    initdata.Add( v[idx[2]-1] ); initdata.Add( v[idx[3]-1] ); initdata.Add( v[idx[0]-1] );
                }
            }
        }