コード例 #1
0
void D3DPBRApp::BuildGeometry()
{
	GeometryGenerator::MeshData sphere;
	GeometryGenerator geoGen;
	geoGen.CreateSphere(5.f, 40, 40, sphere);
	m_indexnum = sphere.Indices.size();
	std::vector<Vertex::Basic32> vertices(sphere.Vertices.size());
	for (int i = 0; i < vertices.size(); i++)
	{
		vertices[i].Normal = sphere.Vertices[i].Normal;
		vertices[i].Pos = sphere.Vertices[i].Position;
		vertices[i].Tangent = sphere.Vertices[i].TangentU;
		vertices[i].Tex = sphere.Vertices[i].TexC;
	}

	D3D11_BUFFER_DESC dbd;
	dbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	dbd.ByteWidth = sizeof(Vertex::Basic32) * vertices.size();
	dbd.CPUAccessFlags = 0;
	dbd.StructureByteStride = 0;
	dbd.MiscFlags = 0;
	dbd.Usage = D3D11_USAGE_DEFAULT;
	D3D11_SUBRESOURCE_DATA vinitdata;
	vinitdata.pSysMem = &vertices[0];

	HR(md3dDevice->CreateBuffer(&dbd, &vinitdata, &m_pVB));

	std::vector<UINT> indeces(sphere.Indices.begin(), sphere.Indices.end());

	dbd.BindFlags = D3D11_BIND_INDEX_BUFFER;
	dbd.ByteWidth = sizeof(UINT) * m_indexnum;
	vinitdata.pSysMem = &indeces[0];

	HR(md3dDevice->CreateBuffer(&dbd, &vinitdata, &m_pIB));
}
コード例 #2
0
ファイル: VtkVisPipeline.cpp プロジェクト: Yonghui56/ogs6
void VtkVisPipeline::highlightMeshComponent(vtkUnstructuredGridAlgorithm const*const source, unsigned index, bool is_element)
{
    int nSources = this->_rootItem->childCount();
    for (int i = 0; i < nSources; i++)
    {
        VtkVisPipelineItem* parentItem = static_cast<VtkVisPipelineItem*>(_rootItem->child(i));
        if (parentItem->algorithm() == source)
        {
            QList<QVariant> itemData;
            itemData << "Selected Mesh Component" << true;
            QList<QVariant> selected_index;
            selected_index << index << index;

            VtkCompositeFilter* filter (nullptr);
            if (is_element)
            {
                filter = VtkFilterFactory::CreateCompositeFilter("VtkCompositeElementSelectionFilter",
                                                                  parentItem->transformFilter());
                static_cast<VtkCompositeElementSelectionFilter*>(filter)->setSelectionArray("vtkIdFilter_Ids");
                static_cast<VtkCompositeElementSelectionFilter*>(filter)->SetUserVectorProperty("Threshold Between", selected_index);
            }
            else
            {
                filter = VtkFilterFactory::CreateCompositeFilter("VtkCompositeNodeSelectionFilter",
                                                                  parentItem->transformFilter());
                std::vector<unsigned> indeces(1);
                indeces[0] = index;
                static_cast<VtkCompositeNodeSelectionFilter*>(filter)->setSelectionArray(indeces);
            }
            VtkVisPointSetItem* item = new VtkVisPointSetItem(filter, parentItem, itemData);
            QModelIndex parent_index = static_cast<TreeModel*>(this)->index(i, 0, QModelIndex());
            _highlighted_mesh_component = this->addPipelineItem(item, parent_index);
            break;
        }
    }
}
コード例 #3
0
void D3DPBRApp::CreateLUT()
{
	D3D11_TEXTURE2D_DESC texDesc;
	texDesc.Width = 512;
	texDesc.Height = 512;
	texDesc.MipLevels = 0;
	texDesc.ArraySize = 1;
	texDesc.SampleDesc.Count = 1;
	texDesc.SampleDesc.Quality = 0;
	texDesc.Format = DXGI_FORMAT_R16G16_FLOAT;
	texDesc.Usage = D3D11_USAGE_DEFAULT;
	texDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
	texDesc.CPUAccessFlags = 0;
	texDesc.MiscFlags = 0;

	ID3D11Texture2D* LUTTex = 0;
	HR(md3dDevice->CreateTexture2D(&texDesc, 0, &LUTTex));

	//
	// Create a render target view to each cube map face 
	// (i.e., each element in the texture array).
	// 

	D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
	rtvDesc.Format = texDesc.Format;
	rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
	rtvDesc.Texture2D.MipSlice = 0;



	HR(md3dDevice->CreateRenderTargetView(LUTTex, &rtvDesc, &mLUTRTV));
	

	//
	// Create a shader resource view to the cube map.
	//

	D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
	srvDesc.Format = texDesc.Format;
	srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
	srvDesc.Texture2D.MipLevels = -1;
	srvDesc.Texture2D.MostDetailedMip = 0;


	HR(md3dDevice->CreateShaderResourceView(LUTTex, &srvDesc, &mLUTSRV));





	D3D11_TEXTURE2D_DESC depthTexDesc;
	depthTexDesc.Width = 512;
	depthTexDesc.Height = 512;
	depthTexDesc.MipLevels = 1;
	depthTexDesc.ArraySize = 1;
	depthTexDesc.SampleDesc.Count = 1;
	depthTexDesc.SampleDesc.Quality = 0;
	depthTexDesc.Format = DXGI_FORMAT_D32_FLOAT;
	depthTexDesc.Usage = D3D11_USAGE_DEFAULT;
	depthTexDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
	depthTexDesc.CPUAccessFlags = 0;
	depthTexDesc.MiscFlags = 0;

	ID3D11Texture2D* depthTex = 0;
	HR(md3dDevice->CreateTexture2D(&depthTexDesc, 0, &depthTex));

	D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
	dsvDesc.Format = depthTexDesc.Format;
	dsvDesc.Flags  = 0;
	dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
	dsvDesc.Texture2D.MipSlice = 0;
	HR(md3dDevice->CreateDepthStencilView(depthTex, &dsvDesc, &mLUTDSV));

	ReleaseCOM(depthTex);

	//
	// Viewport for drawing into cubemap.
	// 

	mLUTViewport.TopLeftX = 0.0f;
	mLUTViewport.TopLeftY = 0.0f;
	mLUTViewport.Width    = (float)512;
	mLUTViewport.Height   = (float)512;
	mLUTViewport.MinDepth = 0.0f;
	mLUTViewport.MaxDepth = 1.0f;



	GeometryGenerator::MeshData quad;
	GeometryGenerator geoGen;
	geoGen.CreateFullscreenQuad(quad);
	mQuadIndexNum = quad.Indices.size();
	
	std::vector<Vertex::Basic32> vertices(quad.Vertices.size());
	for (int i = 0; i < vertices.size(); i++)
	{
		vertices[i].Normal = quad.Vertices[i].Normal;
		vertices[i].Pos = quad.Vertices[i].Position;
		vertices[i].Tangent = quad.Vertices[i].TangentU;
		vertices[i].Tex = quad.Vertices[i].TexC;
	}

	D3D11_BUFFER_DESC dbd;
	dbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	dbd.ByteWidth = sizeof(Vertex::Basic32) * vertices.size();
	dbd.CPUAccessFlags = 0;
	dbd.StructureByteStride = 0;
	dbd.MiscFlags = 0;
	dbd.Usage = D3D11_USAGE_DEFAULT;
	D3D11_SUBRESOURCE_DATA vinitdata;
	vinitdata.pSysMem = &vertices[0];
	
	HR(md3dDevice->CreateBuffer(&dbd, &vinitdata, &mQuadVB));

	std::vector<UINT> indeces(quad.Indices.begin(), quad.Indices.end());

	dbd.BindFlags = D3D11_BIND_INDEX_BUFFER;
	dbd.ByteWidth = sizeof(UINT) * mQuadIndexNum;
	vinitdata.pSysMem = &indeces[0];

	
	HR(md3dDevice->CreateBuffer(&dbd, &vinitdata, &mQuadIB));

	md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	md3dImmediateContext->ClearRenderTargetView(mLUTRTV, reinterpret_cast<const float*>(&Colors::Black));
	md3dImmediateContext->ClearDepthStencilView(mLUTDSV, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);
	md3dImmediateContext->OMSetRenderTargets(1, &mLUTRTV, mLUTDSV);

	md3dImmediateContext->RSSetViewports(1, &mLUTViewport);
	md3dImmediateContext->IASetInputLayout(InputLayouts::Basic32);


	ID3DX11EffectTechnique* activeMeshTech = Effects::CommonPassFX->LUTTech;

	UINT stride = sizeof(Vertex::Basic32);
	UINT offset = 0;
	D3DX11_TECHNIQUE_DESC techDesc;
	activeMeshTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
	{
		// Draw the Mesh.


		md3dImmediateContext->IASetVertexBuffers(0, 1, &mQuadVB, &stride, &offset);
		md3dImmediateContext->IASetIndexBuffer(mQuadIB, DXGI_FORMAT_R32_UINT, 0);




		activeMeshTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
		md3dImmediateContext->DrawIndexed(mQuadIndexNum, 0, 0);

		//m_pSky->Draw(md3dImmediateContext, camera);

		// Restore default
		md3dImmediateContext->RSSetState(0);
	}
	
	HR(D3DX11SaveTextureToFile(md3dImmediateContext, LUTTex, D3DX11_IFF_DDS, _T("lut.dds")));
	ReleaseCOM(LUTTex);
}