示例#1
0
void MyApp::drawTessSphereFromMesh()
{

	//

	if (!dx11Support())
		return;

	// set vertex buffer
	UINT stride = sizeof(Vertex);
	UINT offset = 0;
	_dxImmedDC->IASetVertexBuffers(0, 1, &m_alienModel.vb, &stride, &offset);
	_dxImmedDC->IASetIndexBuffer(m_alienModel.ib, DXGI_FORMAT_R32_UINT, 0);

	// set topology
	_dxImmedDC->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST);
	// set input layout
	_dxImmedDC->IASetInputLayout(_inputLayout);

	// effect params
	XMMATRIX mWVP = XMMatrixIdentity() * m_camera.getViewMatrix() * m_camera.getProjectionMatrix();
	setMatrixVar(m_fxTessSingle, (void*)&mWVP, "m_WorldViewProj");
	setFloatVar(m_fxTessSingle, glb_insideTess, "fInsideTess");
	setFloatVar(m_fxTessSingle, glb_edgeTess, "fEdgeTess");
	setFloatVar(m_fxTessSingle, glb_sphereRadius, "fRadius");

	// draw
	ID3DX11EffectTechnique* fxTech;
	fxTech = m_fxTessSingle->GetTechniqueByName("TessSphere");
	
	fxTech->GetPassByIndex(0)->Apply(0, _dxImmedDC);

	_dxImmedDC->DrawIndexed(m_alienModel.numIndices, DXGI_FORMAT_R32_UINT, 0);
}
示例#2
0
void BoxApp::DrawScene()
{
	md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::LightSteelBlue));
	md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);

	md3dImmediateContext->IASetInputLayout(mInputLayout);
    md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	UINT stride = sizeof(Vertex);
    UINT offset = 0;
    md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset);
	md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0);

	// Set constants
	XMMATRIX world = XMLoadFloat4x4(&mWorld);
	XMMATRIX view  = XMLoadFloat4x4(&mView);
	XMMATRIX proj  = XMLoadFloat4x4(&mProj);
	XMMATRIX worldViewProj = world*view*proj;

	mfxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&worldViewProj));

    D3DX11_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );
    for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
        
		// 36 indices for the box.
		md3dImmediateContext->DrawIndexed(36, 0, 0);
    }

	HR(mSwapChain->Present(0, 0));
}
示例#3
0
void DuckHuntMain::DrawScreenQuad(ID3D11ShaderResourceView* srv)
{
	UINT stride = sizeof(Vertex::Basic32);
	UINT offset = 0;

	md3dImmediateContext->IASetInputLayout(InputLayouts::Basic32);
	md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	md3dImmediateContext->IASetVertexBuffers(0, 1, &mScreenQuadVB, &stride, &offset);
	md3dImmediateContext->IASetIndexBuffer(mScreenQuadIB, DXGI_FORMAT_R32_UINT, 0);

	// Scale and shift quad to lower-right corner.
	XMMATRIX world(
		0.5f, 0.0f, 0.0f, 0.0f,
		0.0f, 0.5f, 0.0f, 0.0f,
		0.0f, 0.0f, 1.0f, 0.0f,
		0.5f, -0.5f, 0.0f, 1.0f);

	ID3DX11EffectTechnique* tech = Effects::DebugTexFX->ViewRedTech;
	D3DX11_TECHNIQUE_DESC techDesc;

	tech->GetDesc(&techDesc);
	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		Effects::DebugTexFX->SetWorldViewProj(world);
		Effects::DebugTexFX->SetTexture(srv);

		tech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
		md3dImmediateContext->DrawIndexed(6, 0, 0);
	}
}
示例#4
0
文件: Effect.cpp 项目: panmar/pg2
    void Effect::ExtractPassData(D3DX11_EFFECT_DESC& effectDesc) {
        for(U32 g = 0; g < effectDesc.Groups; ++g) {
            ID3DX11EffectGroup* group = dx11Effect->GetGroupByIndex(g);
            D3DX11_GROUP_DESC groupDesc;
            DXCall(group->GetDesc(&groupDesc));

            for(U32 t = 0; t < groupDesc.Techniques; ++t) {
                ID3DX11EffectTechnique* pTechnique = group->GetTechniqueByIndex(t);
                D3DX11_TECHNIQUE_DESC techniqueDesc;
                DXCall(pTechnique->GetDesc(&techniqueDesc));

                for(U32 p = 0; p < techniqueDesc.Passes; ++p) {
                    ID3DX11EffectPass* pass = pTechnique->GetPassByIndex(p);
                    D3DX11_PASS_DESC passDesc;
                    DXCall(pass->GetDesc(&passDesc));

                    D3DX11_PASS_SHADER_DESC passShaderDesc;
                    DXCall(pass->GetVertexShaderDesc(&passShaderDesc));
                    D3DX11_EFFECT_SHADER_DESC shaderDesc;
                    DXCall(passShaderDesc.pShaderVariable->GetShaderDesc(passShaderDesc.ShaderIndex, &shaderDesc));

                    for(U32 i = 0; i < shaderDesc.NumInputSignatureEntries; ++i) {
                        D3D11_SIGNATURE_PARAMETER_DESC signatureDesc;
                        DXCall(passShaderDesc.pShaderVariable->GetInputSignatureElementDesc(passShaderDesc.ShaderIndex, i, &signatureDesc));
                    }

                    groups[groupDesc.Name].techniques[techniqueDesc.Name].passes[passDesc.Name].data.pass = pass;
                    groups[groupDesc.Name].techniques[techniqueDesc.Name].passes[passDesc.Name].data.inputSignature = passDesc.pIAInputSignature;
                    groups[groupDesc.Name].techniques[techniqueDesc.Name].passes[passDesc.Name].data.inputSignatureSize = passDesc.IAInputSignatureSize;

                }
            }
        }
    }
void D3DPBRApp::DrawLUT()
{
	ID3DX11EffectTechnique* activeMeshTech = Effects::CommonPassFX->LUTSTech;
	Effects::CommonPassFX->PrefilterMap->SetResource(mLUTSRV);
	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);
	}
}
示例#6
0
void XM_CALLCONV Lava::Draw( FXMMATRIX viewProj, ID3D11DeviceContext* context ) {
	context->IASetInputLayout( InputLayouts::Lava );
	context->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
	UINT stride = sizeof( Vertex::LavaVertex );
	UINT offset = 0;
	ID3D11Buffer* buffers[1] = { mesh->VB() };
	context->IASetVertexBuffers( 0, 1, &buffers[0], &stride, &offset );
	context->IASetIndexBuffer( mesh->IB(), mesh->IndexFormat(), 0 );

	XMMATRIX world = XMMatrixIdentity();
	XMMATRIX worldInvTranspose = MathUtils::InverseTranspose( world );
	XMMATRIX worldViewProj = world*viewProj;

	MyEffects::LavaFX->SetWorld( world );
	MyEffects::LavaFX->SetWorldInvTranspose( worldInvTranspose );
	MyEffects::LavaFX->SetWorldViewProj( worldViewProj );
	MyEffects::LavaFX->SetDiffuseMap( diffuseView );

	ID3DX11EffectTechnique* tech = MyEffects::LavaFX->lavaTechnique;
	D3DX11_TECHNIQUE_DESC td;
	tech->GetDesc( &td );
	for( UINT p = 0; p<td.Passes; ++p ) {
		tech->GetPassByIndex( p )->Apply( 0, context );
		context->DrawIndexed( mesh->IndexCount(), 0, 0 );
	}
}
void cGridMesh::Draw()
{
	// Set Layout And Topology
	g_pD3DDC->IASetInputLayout(cInputLayouts::Simple);
	g_pD3DDC->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	// Set VertexBuffer And IndexBuffer
	UINT stride = sizeof(Vertex::Simple);
	UINT offset = 0;
	g_pD3DDC->IASetVertexBuffers(0, 1, &m_VB, &stride, &offset);
	g_pD3DDC->IASetIndexBuffer(m_IB, DXGI_FORMAT_R32_UINT, 0);

	// worldViewProj Çà·ÄÀ» ±¸ÇÑ´Ù.
	XMMATRIX world	= XMLoadFloat4x4(&GetTransformMatrix());
	XMMATRIX view	= g_pCameraManager->GetView();
	XMMATRIX proj	= g_pCameraManager->GetProj();
	XMMATRIX worldViewProj = world * view * proj;

	// ¼ÎÀÌ´õ¿¡ »ó¼ö°ª ¼³Á¤.
	cEffects::SimpleFX->SetWorldViewProj(worldViewProj);

	ID3DX11EffectTechnique* tech = cEffects::SimpleFX->ColorTech;
	D3DX11_TECHNIQUE_DESC techDesc;
	tech->GetDesc(&techDesc);
	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		tech->GetPassByIndex(p)->Apply(0, g_pD3DDC);

		// »öÀÎÀ» »ç¿ëÇؼ­ ±×¸°´Ù.
		g_pD3DDC->DrawIndexed(m_GridIndexCount, 0, 0);
	}

	HR(g_pD3DSC->Present(0, 0));
}
示例#8
0
void GaussianMain::ShowImage(ID3D11DeviceContext* pd3dImmediateContext)
{
	// Output to default render target
	ID3D11RenderTargetView* rtv_array[1] = {g_pRTV_Default};
	pd3dImmediateContext->OMSetRenderTargets(1, rtv_array, g_pDSV_Default);
	pd3dImmediateContext->RSSetViewports(1, g_VP_Default);

	ID3DX11EffectTechnique* pTech = g_pFX_Render->GetTechniqueByName("Tech_ShowImage");
	ID3DX11EffectPass* pPass = g_bColorBlur ? pTech->GetPassByName("Pass_ShowColorImage") : pTech->GetPassByName("Pass_ShowMonoImage");

	if (g_bColorBlur)
		g_pFX_Render->GetVariableByName("g_texColorInput")->AsShaderResource()->SetResource(g_pSRV_Output);
	else
		g_pFX_Render->GetVariableByName("g_texMonoInput")->AsShaderResource()->SetResource(g_pSRV_Output);

	UINT strides = sizeof(SCREEN_VERTEX);
	UINT offsets = 0;
	ID3D11Buffer* pBuffers[1] = {g_pScreenQuadVB};

	pd3dImmediateContext->IASetInputLayout(g_pQuadLayout);
	pd3dImmediateContext->IASetVertexBuffers(0, 1, pBuffers, &strides, &offsets);
	pd3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);

	pPass->Apply(0, pd3dImmediateContext);
	pd3dImmediateContext->Draw( 4, 0 );
}
示例#9
0
void MyApp::drawTessTerrain()
{
	static float  time = 0.0f;
	time += 0.001f;

	if (!dx11Support())
		return;

	// set vertex buffer
	UINT stride = sizeof(Vertex);
	UINT offset = 0;
	_dxImmedDC->IASetVertexBuffers(0, 1, &m_vbSingle, &stride, &offset);

	// set topology
	_dxImmedDC->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST);
	// set input layout
	_dxImmedDC->IASetInputLayout(_inputLayout);

	// effect params
	XMMATRIX mWVP = XMMatrixIdentity() * m_camera.getViewMatrix() * m_camera.getProjectionMatrix();
	setMatrixVar(m_fxTessTerrain, (void*)&mWVP, "m_WorldViewProj");
	setFloatVar(m_fxTessTerrain, glb_insideTess, "fInsideTess");
	setFloatVar(m_fxTessTerrain, glb_edgeTess, "fEdgeTess");
	setFloatVar(m_fxTessTerrain, glb_terrainHeight, "fHeightController");
	passLightParams(m_fxTessTerrain);

	// draw
	ID3DX11EffectTechnique* fxTech;
	if (glb_selectedTessPartitioning == TessPartitioning::INTEGER)
		fxTech = m_fxTessTerrain->GetTechniqueByName("TessBezierSurface_Integer");
	else if (glb_selectedTessPartitioning == TessPartitioning::FRAC_EVEN)
		fxTech = m_fxTessTerrain->GetTechniqueByName("TessBezierSurface_FracEven");
	else 
		fxTech = m_fxTessTerrain->GetTechniqueByName("TessBezierSurface_FracOdd");

	int patch_dim  = 5; 


	float patch_size = GRID_WIDTH / (float)glb_terrainPatchDim;
	setIntVar(m_fxTessTerrain, glb_terrainPatchDim, "iNumPatch");
	setFloatVar(m_fxTessTerrain, patch_size, "fPatchSize");
	setBoolVar(m_fxTessTerrain, true, "bViewAdaptiveTess"); // [!]
	setFloatVar(m_fxTessTerrain, GRID_WIDTH, "fWidth");
	setVectorVar(m_fxTessTerrain, (void*)&m_camera.getPosVector(), "vEyePos");
	setSrvVar(m_fxTessTerrain, m_srvTerrainHmap, "texTerrainHeightmap");
	setSrvVar(m_fxTessTerrain, m_srvTerrainNmap, "texTerrainNormalmap");
	setBoolVar(m_fxTessTerrain, glb_bOn, "bOn");
	setFloatVar(m_fxTessTerrain, time, "fTime");
	setFloatVar(m_fxTessTerrain, glb_terrainMinTessFactor, "fMinTessFactor");
	setFloatVar(m_fxTessTerrain, glb_terrainMaxTessFactor, "fMaxTessFactor");
	setFloatVar(m_fxTessTerrain, glb_terrainMinViewDist, "fMinViewDist");
	setFloatVar(m_fxTessTerrain, glb_terrainMaxViewDist, "fMaxViewDist");
	setBoolVar(m_fxTessTerrain, glb_bTerrainDebugView, "bDebug");
	
	
	fxTech->GetPassByIndex(0)->Apply(0, _dxImmedDC);


	_dxImmedDC->DrawInstanced(1, glb_terrainPatchDim*glb_terrainPatchDim, 0, 0);
}
示例#10
0
void MyApp::drawImplicitObjects()
{

	// store current Input Layout & Primitive Topology
	ID3D11InputLayout* ia;
	D3D11_PRIMITIVE_TOPOLOGY primTopology;
	_dxImmedDC->IAGetInputLayout(&ia);
	_dxImmedDC->IAGetPrimitiveTopology(&primTopology);

	// no vertex buffer needs a null input layout
	_dxImmedDC->IASetInputLayout(0);
	_dxImmedDC->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
	
	// Variables
	XMMATRIX mWorld = XMMatrixIdentity();
	setMatrixVar(m_fxImplicit, (void*)&mWorld, "World");
	setMatrixVar(m_fxImplicit, (void*)&m_camera.getViewMatrix(), "View");
	setMatrixVar(m_fxImplicit, (void*)&m_camera.getProjectionMatrix(), "Projection");
	setFloatVar(m_fxImplicit, 0, "Time");
	setVectorVar(m_fxImplicit, (void*)&m_camera.getPosVector(), "eyePos");

	XMVECTOR det;
	XMMATRIX viewInverse = XMMatrixInverse(&det, m_camera.getViewMatrix());
	setMatrixVar(m_fxImplicit, (void*)&viewInverse, "mInverseView");

	// draw 4 vertices 
	ID3DX11EffectTechnique * tech = 0;
	tech = m_fxImplicit->GetTechniqueByIndex(0);
	tech->GetPassByIndex(0)->Apply(0, _dxImmedDC);
	_dxImmedDC->Draw( 4, 0 );

	// restore Input Layout & Primitive Topology
	_dxImmedDC->IASetInputLayout(ia);
	_dxImmedDC->IASetPrimitiveTopology(primTopology);
}
示例#11
0
bool 
ShaderD3D11::renderMeshes (const Ibl::RenderRequest& inputRequest,
                           const std::set<const Ibl::Mesh*>      & meshes) const
{

    Ibl::CullMode cachedCullMode =
            _deviceInterface->cullMode();

    // Form a new request around the meshes request.
    Ibl::RenderRequest request = inputRequest;

    if (meshes.size() > 0)
    {
        for (auto it =
             meshes.begin(); it != meshes.end(); it++)
        {
            const Ibl::Mesh* mesh = (*it);
            request.mesh = (mesh);
            request.material = mesh->material();

            if (!mesh->visible())
                continue;

            if (mesh->material()->twoSided())
            {
                _deviceInterface->setCullMode (Ibl::CullNone);
            }

            if (const Ibl::GpuTechniqueD3D11* technique = 
                    dynamic_cast<const Ibl::GpuTechniqueD3D11*>(request.technique))
            {
                ID3DX11EffectTechnique* techniqueHandle = 
                    technique->handle();

                const D3DX11_TECHNIQUE_DESC& description =
                    technique->description();

               setTechniqueParameters (request);
               setMeshParameters (request);
               
                for (uint32_t passIndex = 0; passIndex < description.Passes; passIndex++)
                {
                    // Need to set input handle here
                    if (technique->setupInputLayout (mesh, passIndex))
                    {
                        techniqueHandle->GetPassByIndex (passIndex)->Apply(0, _immediateCtx);
                        mesh->render(&request, technique);
                    }
                }
            }

            if (mesh->material()->twoSided())
            {
                _deviceInterface->setCullMode (cachedCullMode);
            }
        }
    }
    return true;
}
示例#12
0
void ForwardRenderer::DrawScreenQuad()
{
    float blendFactor[] = { 0.0f, 0.0f, 0.0f, 0.0f };

    XMMATRIX view = XMLoadFloat4x4( RendererCore::Instance()->GetView() );
    XMMATRIX proj = XMLoadFloat4x4( RendererCore::Instance()->GetProj() );

    int iCount = m_vDrawScreenElements.size();
    for ( int i = 0; i < iCount; ++i )
    {
        DrawElement* pElem = m_vDrawScreenElements[i];
        if ( !pElem )
            continue;

        UINT stride = pElem->stride;
        UINT offset = pElem->offset;

        ID3D11Buffer* pVB = pElem->m_spVB->GetVB();

        GetD3D11DeviceImmContext()->IASetInputLayout( pElem->m_pInputLayout );
        GetD3D11DeviceImmContext()->IASetPrimitiveTopology( pElem->ePrimitiveTopology );
        GetD3D11DeviceImmContext()->IASetVertexBuffers( 0, 1, &pVB, &stride, &offset );
        GetD3D11DeviceImmContext()->IASetIndexBuffer( pElem->m_spIB->GetIB(), DXGI_FORMAT_R32_UINT, 0 );


        if ( pElem->m_pRasterS )
            GetD3D11DeviceImmContext()->RSSetState( pElem->m_pRasterS );
        if ( pElem->m_pBlendS )
            GetD3D11DeviceImmContext()->OMSetBlendState( pElem->m_pBlendS, blendFactor, 0xffffffff );
        if ( pElem->m_pDepthStencilS )
            GetD3D11DeviceImmContext()->OMSetDepthStencilState( pElem->m_pDepthStencilS, pElem->m_uiStencilRef );



        for ( auto itor = pElem->m_vecSubElement.begin(); itor != pElem->m_vecSubElement.end(); ++itor )
        {
            ID3DX11EffectTechnique* pTech = pElem->m_spShader->GetTech( (*itor).m_iTechIndex );
            if ( !pTech )
                continue;

            D3DX11_TECHNIQUE_DESC techDesc;
            pTech->GetDesc( &techDesc );

            TexturePtr spDiffuseMap = (*itor).m_spDiffuseMap;

            for ( UINT p = 0; p < techDesc.Passes; ++p )
            {
                XMMATRIX worldViewProj = XMLoadFloat4x4( &(*itor).m_World );

                pElem->m_spShader->SetWorldViewProj( worldViewProj );
                pElem->m_spShader->SetDiffuseMap( spDiffuseMap->GetSRV() );

                pTech->GetPassByIndex( p )->Apply( 0, GetD3D11DeviceImmContext() );
                GetD3D11DeviceImmContext()->DrawIndexed( 6, 0, 0 );
            }
        }
    }

}
示例#13
0
void Tree::init(const char* filename, ID3D11Device* g_device, ID3D11DeviceContext* g_context)
{
	
	Mesh::init(filename, g_device, g_context);
	
	_leaves.init("", g_device, g_context);

	//////////////////////////
	bFire = false;

	m_numSubsets = 1;

	//////////////////////////
	


	createEffect("../Desert_Island/shaders/tree.fxo", g_device);

	fx_m_World				= getFX()->GetVariableByName("m_World")->AsMatrix();
	fx_m_WorldViewProj		= getFX()->GetVariableByName("m_WorldViewProj")->AsMatrix();
	fx_m_L_ViewProj			= getFX()->GetVariableByName("m_L_ViewProj")->AsMatrix();
	
	fx_tex_shadow_map		= getFX()->GetVariableByName("tex_shadow_map")->AsShaderResource();

	fx_lights				= getFX()->GetVariableByName("lights");

	fx_num_lights			= getFX()->GetVariableByName("num_lights")->AsScalar();

	fx_pEye					= getFX()->GetVariableByName("pEye")->AsVector();
	fx_bShadowed			= getFX()->GetVariableByName("bShadowed")->AsScalar();
	fx_bUsePCSS				= getFX()->GetVariableByName("bUsePCSS")->AsScalar();

	///////////

	HRESULT hr = D3DX11CreateShaderResourceViewFromFile(g_dev(), L"../Desert_island/media/tree_heightmap.jpg", 0, 0, &srv_heightmap, 0);
	if (FAILED(hr))
		MessageBoxA(0, "Error creating tree heightmap srv", 0, 0);

	
	
	///////////

	// Input layout - Vertex IA
	D3D11_INPUT_ELEMENT_DESC vertex_layout[] = {
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
        { "NORMAL", 0,  DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TANGENT", 0,  DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEX_COORDS", 0,  DXGI_FORMAT_R32G32_FLOAT, 0, 36, D3D11_INPUT_PER_VERTEX_DATA, 0 }
	};

	D3DX11_PASS_DESC passDesc;
	ID3DX11EffectTechnique* tech = getFX()->GetTechniqueByIndex(0);
	tech->GetPassByIndex(0)->GetDesc(&passDesc);

	hr = createInputLayout(g_dev(), vertex_layout, 4, passDesc.pIAInputSignature, passDesc.IAInputSignatureSize);
	if (FAILED(hr))
		MessageBoxA(0, "Error creating tree IA", 0, 0);

}
示例#14
0
void MyApp::drawImplicitToTexture()
{

	// store current Input Layout & Primitive Topology
	ID3D11InputLayout* ia;
	D3D11_PRIMITIVE_TOPOLOGY primTopology;
	_dxImmedDC->IAGetInputLayout(&ia);
	_dxImmedDC->IAGetPrimitiveTopology(&primTopology);
	ID3D11RenderTargetView* rtv;
	ID3D11DepthStencilView* dsv;
	_dxImmedDC->OMGetRenderTargets(1, &rtv, &dsv);
	D3D11_VIEWPORT vp;
	unsigned int num_vp = 1;
	_dxImmedDC->RSGetViewports(&num_vp, &vp);

	// no vertex buffer needs a null input layout
	_dxImmedDC->IASetInputLayout(0);
	_dxImmedDC->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
	
	// Set Texture Array as Render Target
	float clearColor[4] = { 0.6f, 0.7f, 0.5f, 1.0f };
	_dxImmedDC->ClearRenderTargetView(m_rtvImplicit, clearColor);
	_dxImmedDC->OMSetRenderTargets(1, &m_rtvImplicit, 0);
	D3D11_VIEWPORT new_vp;
	new_vp.Height = new_vp.Width = (float)m_implicitQuadDimension;
	new_vp.MaxDepth = 1.0f;		new_vp.MinDepth = 0.0f;
	new_vp.TopLeftX = 0.0f;		new_vp.TopLeftY = 0.0f;
	_dxImmedDC->RSSetViewports(1, &new_vp);

	// Variables
	XMMATRIX mWorld = XMMatrixIdentity();
	setMatrixVar(m_fxImplicit, (void*)&mWorld, "World");
	setMatrixVar(m_fxImplicit, (void*)&m_camera.getViewMatrix(), "View");
	setMatrixVar(m_fxImplicit, (void*)&m_camera.getProjectionMatrix(), "Projection");
	setFloatVar(m_fxImplicit, 0, "Time");
	setVectorVar(m_fxImplicit, (void*)&m_camera.getPosVector(), "eyePos");
	setIntVar(m_fxImplicit, glb_iImplicitDepth, "iDepth");

	XMVECTOR det;
	XMMATRIX viewInverse = XMMatrixInverse(&det, m_camera.getViewMatrix());
	setMatrixVar(m_fxImplicit, (void*)&viewInverse, "mInverseView");

	// draw 4 vertices 
	ID3DX11EffectTechnique * tech = 0;
	tech = m_fxImplicit->GetTechniqueByIndex(0);

	for (int i=0; i<5; i++)
	{
		setIntVar(m_fxImplicit, i, "iArrayIndex");
		tech->GetPassByIndex(0)->Apply(0, _dxImmedDC);
		_dxImmedDC->Draw( 4, 0 );
	}

	// restore Input Layout & Primitive Topology
	_dxImmedDC->RSSetViewports(num_vp, &vp);
	_dxImmedDC->IASetInputLayout(ia);
	_dxImmedDC->IASetPrimitiveTopology(primTopology);
	_dxImmedDC->OMSetRenderTargets(1, &rtv, dsv);
}
示例#15
0
void Terrain::Draw(ID3D11DeviceContext* dc, const Camera& cam, DirectionalLight lights[3])
{
	dc->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
	dc->IASetInputLayout(InputLayouts::Terrain);

	UINT stride = sizeof(Vertex::Terrain);
    UINT offset = 0;
    dc->IASetVertexBuffers(0, 1, &mQuadPatchVB, &stride, &offset);
	dc->IASetIndexBuffer(mQuadPatchIB, DXGI_FORMAT_R16_UINT, 0);

	XMMATRIX viewProj = cam.ViewProj();
	XMMATRIX world  = XMLoadFloat4x4(&mWorld);
	XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
	XMMATRIX worldViewProj = world*viewProj;
	XMMATRIX ShadowTransform = world * XMLoadFloat4x4(&d3d->m_ShadowTransform);

	XMFLOAT4 worldPlanes[6];
	ExtractFrustumPlanes(worldPlanes, viewProj);

	// Set per frame constants.
	Effects::TerrainFX->SetViewProj(viewProj);
	Effects::TerrainFX->SetEyePosW(cam.GetPosition());
	Effects::TerrainFX->SetDirLights(lights);
	Effects::TerrainFX->SetFogColor(Colors::Silver);
	Effects::TerrainFX->SetFogStart(15.0f);
	Effects::TerrainFX->SetFogRange(175.0f);
	Effects::TerrainFX->SetMinDist(20.0f);
	Effects::TerrainFX->SetMaxDist(400.0f);
	Effects::TerrainFX->SetMinTess(0.0f);
	Effects::TerrainFX->SetMaxTess(6.0f);
	Effects::TerrainFX->SetTexelCellSpaceU(1.0f / mInfo.HeightmapWidth);
	Effects::TerrainFX->SetTexelCellSpaceV(1.0f / mInfo.HeightmapHeight);
	Effects::TerrainFX->SetWorldCellSpace(mInfo.CellSpacing);
	Effects::TerrainFX->SetWorldFrustumPlanes(worldPlanes);
	
	Effects::TerrainFX->SetLayerMapArray(mLayerMapArraySRV);
	Effects::TerrainFX->SetBlendMap(mBlendMapSRV);
	Effects::TerrainFX->SetHeightMap(mHeightMapSRV);
	Effects::TerrainFX->SetShadowMap(d3d->GetShadowMap());
	Effects::TerrainFX->SetShadowTransform(ShadowTransform);

	Effects::TerrainFX->SetMaterial(mMat);

	ID3DX11EffectTechnique* tech = Effects::TerrainFX->Light1Tech;
    D3DX11_TECHNIQUE_DESC techDesc;
    tech->GetDesc( &techDesc );

    for(UINT i = 0; i < techDesc.Passes; ++i)
    {
        ID3DX11EffectPass* pass = tech->GetPassByIndex(i);
		pass->Apply(0, dc);

		dc->DrawIndexed(mNumPatchQuadFaces*4, 0, 0);
	}	

	dc->HSSetShader(0, 0, 0);
	dc->DSSetShader(0, 0, 0);
}
示例#16
0
bool
ShaderD3D11::renderMeshSubset (Ibl::PrimitiveType primitiveType,
                               size_t startIndex,
                               size_t numIndices,
                               const Ibl::RenderRequest& request) const
{
    uint32_t cPasses = 0;
    uint32_t iPass = 0;

    Ibl::CullMode cachedCullMode =
            _deviceInterface->cullMode();
    bool hasMaterial = request.mesh->material() != nullptr;

    if (const Ibl::GpuTechniqueD3D11* technique = 
        dynamic_cast<const Ibl::GpuTechniqueD3D11*>(request.technique))
    {
        if (setParameters(request))
        {
            if (hasMaterial)
            {
                if (request.mesh->material()->twoSided())
                {
                    _deviceInterface->setCullMode (Ibl::CullNone);
                }
            }

            ID3DX11EffectTechnique* techniqueHandle = 
                technique->handle();

            const D3DX11_TECHNIQUE_DESC& description =
                technique->description();

            for (uint32_t passIndex = 0; passIndex < description.Passes; passIndex++)
            {
                // Need to set input handle here
                if (technique->setupInputLayout (request.mesh, passIndex))
                {
                    techniqueHandle->GetPassByIndex (passIndex)->Apply(0, _immediateCtx);

                    // This assumes that the vertex buffer is already bound
                    _immediateCtx->IASetPrimitiveTopology((D3D_PRIMITIVE_TOPOLOGY)(primitiveType));
                    _immediateCtx->DrawIndexed((uint32_t)(numIndices), (uint32_t)(startIndex), 0);
                }
            }

            if (hasMaterial)
            {
                if (request.mesh->material()->twoSided())
                {
                    _deviceInterface->setCullMode (cachedCullMode);
                }
            }
        }
    }

    return true;
}
void D3DPBRApp::DrawScene(Camera& camera)
{
	md3dImmediateContext->IASetInputLayout(InputLayouts::Basic32);
	md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	md3dImmediateContext->RSSetViewports(1, &mScreenViewport);

	UINT stride = sizeof(Vertex::Basic32);
	UINT offset = 0;

	//

	XMMATRIX view     = camera.View();
	XMMATRIX proj     = camera.Proj();
	XMMATRIX viewProj = camera.ViewProj();




	// Set per frame constants.
	Effects::CommonPassFX->SetDirLights(mDirLights);
	Effects::CommonPassFX->SetEyePosW(mCam.GetPosition());
	Effects::CommonPassFX->SetEnvMap(mDynamicCubeMapSRV);

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

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

		if( GetAsyncKeyState('1') & 0x8000 )
			md3dImmediateContext->RSSetState(RenderStates::WireframeRS);

		md3dImmediateContext->IASetVertexBuffers(0, 1, &m_pVB, &stride, &offset);
		md3dImmediateContext->IASetIndexBuffer(m_pIB, DXGI_FORMAT_R32_UINT, 0);

		XMMATRIX world = XMLoadFloat4x4(&mMeshWorld);
		XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
		XMMATRIX worldViewProj = world*view*proj;

		Effects::CommonPassFX->SetWorld(world);
		Effects::CommonPassFX->SetWorldInvTranspose(worldInvTranspose);
		Effects::CommonPassFX->SetWorldViewProj(worldViewProj);
		Effects::CommonPassFX->SetMaterial(mMeshMat);

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

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

		// Restore default
		md3dImmediateContext->RSSetState(0);
	}

}
示例#18
0
bool
ShaderD3D11::renderMesh (const Ibl::RenderRequest& request) const
{
    uint32_t cPasses = 0;
    uint32_t iPass = 0;

    if (!request.mesh->visible())
        return true;

    Ibl::CullMode cachedCullMode =
            _deviceInterface->cullMode();
    bool hasMaterial = request.mesh->material() != nullptr;

    if (const Ibl::GpuTechniqueD3D11* technique = 
        dynamic_cast<const Ibl::GpuTechniqueD3D11*>(request.technique))
    {
        if (setParameters(request))
        {
            if (hasMaterial)
            {
                if (request.mesh->material()->twoSided())
                {
                    _deviceInterface->setCullMode (Ibl::CullNone);
                }
            }

            ID3DX11EffectTechnique* techniqueHandle = 
                technique->handle();

            const D3DX11_TECHNIQUE_DESC& description =
                technique->description();

            for (uint32_t passIndex = 0; passIndex < description.Passes; passIndex++)
            {
                // Need to set input handle here
                if (technique->setupInputLayout (request.mesh, passIndex))
                {
                    techniqueHandle->GetPassByIndex (passIndex)->Apply(0, _immediateCtx);
                    request.mesh->render(&request, technique);
                }
            }

            if (hasMaterial)
            {
                if (request.mesh->material()->twoSided())
                {
                    _deviceInterface->setCullMode (cachedCullMode);
                }
            }
        }
    }

    return true;
}
示例#19
0
void cPillar::Render()
{
	cFBXObject::Render();


	m_pDeviceContext->RSSetState(m_RS);
	m_pDeviceContext->IASetInputLayout(mInputLayout);
	m_pDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

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

	//set per frame constants
	DirLights->SetRawValue(mDirLights, 0, 3 * sizeof(DirectionalLight));
	EyePosW->SetRawValue(&g_CameraPos, 0, sizeof(XMFLOAT3));

	ID3DX11EffectTechnique* activeTech;

	if (m_isTooned)
		activeTech = Light2TexToonedTech;
	else
		activeTech = Light3TexTech;


	D3DX11_TECHNIQUE_DESC techDesc;
	activeTech->GetDesc(&techDesc);

	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		m_pDeviceContext->IASetVertexBuffers(0, 1, &m_VB, &stride, &offset);
		m_pDeviceContext->IASetIndexBuffer(m_IB, DXGI_FORMAT_R32_UINT, 0);

		XMMATRIX TEMPworld = XMLoadFloat4x4(&m_WorldMatrix);

		XMMATRIX TEMPworldInvTranspose = MathHelper::InverseTranspose(TEMPworld);
		XMMATRIX TEMPview = XMLoadFloat4x4(&g_View4X4);
		XMMATRIX TEMPproj = XMLoadFloat4x4(&g_Proj4X4);
		XMMATRIX TEMPworldViewProj = TEMPworld*TEMPview*TEMPproj;


		World->SetMatrix(reinterpret_cast<float*>(&TEMPworld));
		WorldInvTranspose->SetMatrix(reinterpret_cast<float*>(&TEMPworldInvTranspose));
		WorldViewProj->SetMatrix(reinterpret_cast<float*>(&TEMPworldViewProj));
		TexTransform->SetMatrix(reinterpret_cast<float*>(&mTexTransform));
		Mat->SetRawValue(&mObjectMat, 0, sizeof(Material));
		DiffuseMap->SetResource(mDiffuseMapSRV);

		activeTech->GetPassByIndex(p)->Apply(0, m_pDeviceContext);
		// 36 indices for the box.
		m_pDeviceContext->Draw(vertices.size(), 0);
	}


}
示例#20
0
void JF::Component::ColisionBox::Render()
{
	// Declear)
	float blendFactors[] = { 0.0f, 0.0f, 0.0f, 0.0f };

	// Get)
	auto* pTransform = GetOwner()->GetComponent<JF::Component::Transform>();

	// Check)
	RETURN_IF(pTransform == nullptr, );

	// Set Layout And Topology
	gRENDERER->DeviceContext()->IASetInputLayout(InputLayouts::PosColor);
	gRENDERER->DeviceContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST);

	// Set VertexBuffer And IndexBuffer
	UINT stride = sizeof(JF::Vertex::PosColor);
	UINT offset = 0;
	gRENDERER->DeviceContext()->IASetVertexBuffers(0, 1, &m_VertBuff, &stride, &offset);
	gRENDERER->DeviceContext()->IASetIndexBuffer(m_IndexBuff, DXGI_FORMAT_R32_UINT, 0);

	// worldViewProj 행렬을 구한다.
	XMFLOAT3 rPosition	= XMFLOAT3(pTransform->GetPosition().x + m_Center.x, pTransform->GetPosition().y + m_Center.y, pTransform->GetPosition().z + m_Center.z);
	XMFLOAT3 rScale		= XMFLOAT3(pTransform->GetScale().x * m_Size.x, pTransform->GetScale().y * m_Size.y, pTransform->GetScale().z * m_Size.z);
	XMFLOAT4 rRotation	= pTransform->GetRotation();

	XMMATRIX scl, rot, tsl;
	scl = XMMatrixScalingFromVector(XMLoadFloat3(&rScale));
	rot = XMMatrixRotationQuaternion(XMLoadFloat4(&rRotation));
	tsl = XMMatrixTranslationFromVector(XMLoadFloat3(&rPosition));

	XMMATRIX world = scl*rot*tsl;
	XMMATRIX view = Camera::g_pMainCamera->GetView();
	XMMATRIX proj = Camera::g_pMainCamera->GetProj();
	XMMATRIX worldViewProj = world * view * proj;

	Effects::SimpleFX->SetWorldViewProj(worldViewProj);

	// 노말맵이 있는지에따라 FX Tech 설정 변경.
	ID3DX11EffectTechnique* Tech;
	Tech = Effects::SimpleFX->ColorTech;

	D3DX11_TECHNIQUE_DESC techDesc;
	Tech->GetDesc(&techDesc);
	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		Tech->GetPassByIndex(p)->Apply(0, gRENDERER->DeviceContext());
		gRENDERER->DeviceContext()->DrawIndexed(m_indexCnt, 0, 0);
	}

	// 기본 랜더상태로 복원한다.
	gRENDERER->DeviceContext()->RSSetState(0);
	gRENDERER->DeviceContext()->OMSetBlendState(0, blendFactors, 0xffffffff);
}
示例#21
0
void ZombieForce::DrawScene()
{
	md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::Blue));
	md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);

	md3dImmediateContext->IASetInputLayout(InputLayouts::Basic32);
    md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
 
	UINT stride = sizeof(Vertex::Basic32);
    UINT offset = 0;
	
	mCam.UpdateViewMatrix();

	XMMATRIX view  = mCam.View();
	XMMATRIX proj  = mCam.Proj();
	XMMATRIX viewProj = mCam.ViewProj();

	// Set per frame constants.
	Effects::BillboardFX->SetDirLights(mDirLights);
	Effects::BillboardFX->SetEyePosW(mCam.GetPosition());
	Effects::BillboardFX->SetCubeMap(mSky->CubeMapSRV());

	//ID3DX11EffectTechnique* activeTech = Effects::BasicFX->Light2TexTech;
	ID3DX11EffectTechnique* activeTech = Effects::BillboardFX->Light2TexTech;

    D3DX11_TECHNIQUE_DESC techDesc;
	activeTech->GetDesc( &techDesc );
    for(UINT p = 0; p < techDesc.Passes; ++p)
    {
		pyramid->DrawPyramid(md3dImmediateContext,activeTech, mCam);
		//myFirstSphere->DrawSphere(md3dImmediateContext,activeTech, mCam);
		myFirstPlane->DrawPlane(md3dImmediateContext,activeTech, mCam);
		//myFirstGeoSphere->DrawGeoSphere(md3dImmediateContext,activeTech, mCam);
		//myFirstCylinder->DrawCylinder(md3dImmediateContext,activeTech, mCam);
		for(unsigned int i = 0; i < spheres.size(); ++i)
		{
			spheres[i]->DrawSphere(md3dImmediateContext,activeTech, mCam);
		}
		for(unsigned int i = 0; i < boxes.size(); ++i)
		{
			boxes[i]->DrawBox(md3dImmediateContext,activeTech, mCam);
		}
		CMESHMANAGER->Render(md3dImmediateContext, activeTech, mCam);
    }

	mSky->Draw(md3dImmediateContext, mCam);

	// restore default states, as the SkyFX changes them in the effect file.
	md3dImmediateContext->RSSetState(0);
	md3dImmediateContext->OMSetDepthStencilState(0, 0);

	HR(mSwapChain->Present(0, 0));
}
示例#22
0
void Mesh::draw(int subset, ID3DX11Effect* fx, const char* technique) const
{
	UINT stride = sizeof(Vertex); UINT offset = 0;
	
	g_context->IASetVertexBuffers(0, 1, &vertex_buffer, &stride, &offset); /* <---- Causes Memory Leak !! */
	g_context->IASetIndexBuffer(index_buffer, DXGI_FORMAT_R32_UINT, 0);

	ID3DX11EffectTechnique* tech = fx->GetTechniqueByName(technique);
	tech->GetPassByIndex(0)->Apply(0, g_context);

	g_context->DrawIndexed(m_subsets[subset].size*3, m_subsets[subset].startIndex*3, 0);
}
示例#23
0
void MyApp::drawTessSphereFromOct(Sphere* sphere)
{
	if (!dx11Support())
		return;

	bool tess = true;


	// set vertex buffer
	UINT stride = sizeof(Vertex);
	UINT offset = 0;
	_dxImmedDC->IASetVertexBuffers(0, 1, &m_vbControlPoints, &stride, &offset);

	// set topology
	if (tess)
		_dxImmedDC->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST);
	else
		_dxImmedDC->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	// set input layout
	_dxImmedDC->IASetInputLayout(_inputLayout);

	// effect params
	XMMATRIX mWVP = XMMatrixIdentity() * m_camera.getViewMatrix() * m_camera.getProjectionMatrix();
	setMatrixVar(m_fxTessSphere, (void*)&mWVP, "m_WorldViewProj");
	setFloatVar(m_fxTessSphere, glb_insideTess, "fInsideTess");
	setFloatVar(m_fxTessSphere, glb_edgeTess, "fEdgeTess");
	
	setFloatVar(m_fxTessSphere, sphere->radius, "fRadius");
	setVectorVar(m_fxTessSphere, (void*)&(sphere->getPos()), "vPos");
	setIntVar(m_fxTessSphere, sphere->tessFactor, "iTessFactor");
	setSrvVar(m_fxTessSphere, this->m_srvSpaceship, "texSpaceship");
	passLightParams(m_fxTessSphere);

	// draw
	ID3DX11EffectTechnique* fxTech;
	if (tess)
		fxTech = m_fxTessSphere->GetTechniqueByName("TessSphere");
	else
		fxTech = m_fxTessSphere->GetTechniqueByName("NoTess");

	fxTech->GetPassByIndex(0)->Apply(0, _dxImmedDC);


#ifdef _TESS_INDEX_BUFFER
	_dxImmedDC->IASetIndexBuffer(m_ibControlPoints, DXGI_FORMAT_R32_UINT, 0);
	_dxImmedDC->DrawIndexed(24, 0, 0);
#else
	_dxImmedDC->Draw(24, 0);
#endif

}
示例#24
0
void Entity::Draw(ID3DX11EffectTechnique* activeTech, ID3D11DeviceContext* context, UINT pass, const Camera& camera, float dt)
{
	XMMATRIX world = XMLoadFloat4x4(&mWorld);
	XMMATRIX shad = XMLoadFloat4x4(&mShadowTrans);
	XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
	XMMATRIX worldViewProj = world*camera.View()*camera.Proj();
	Effects::BasicFX->SetWorld(world);
	Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
	Effects::BasicFX->SetWorldViewProj(worldViewProj);
	Effects::BasicFX->SetShadowTransform(world*shad);
	if (!useTexTrans){ Effects::BasicFX->SetTexTransform(XMMatrixScaling(origTexScale.x, origTexScale.y, origTexScale.z)); }
	if (useTexTrans)
	{
		Effects::BasicFX->SetTexTransform(XMMatrixTranslation(texTrans.x, texTrans.y, texTrans.z)*XMMatrixScaling(origTexScale.x, origTexScale.y, origTexScale.z));
		texTrans.x += dt*texTransMult.x;
		texTrans.y += dt*texTransMult.y;
		texTrans.z += dt*texTransMult.z;
	}
	if (mBasicTexTrans)
	{
		XMMATRIX Scale;
		mFlipTexture ? Scale = XMMatrixScaling(-origTexScale.x, origTexScale.y, origTexScale.z) : Scale = XMMatrixScaling(origTexScale.x, origTexScale.y, origTexScale.z);
		Effects::BasicFX->SetTexTransform(XMMatrixTranslation(texTrans.x, texTrans.y, texTrans.z)*Scale);
	}
	if (mUseAnimation)
	{
		XMMATRIX Scale;
		mAnim->Flipped() ? Scale = XMMatrixScaling(-origTexScale.x, origTexScale.y, origTexScale.z) : Scale = XMMatrixScaling(origTexScale.x, origTexScale.y, origTexScale.z);
		Effects::BasicFX->SetTexTransform(XMMatrixTranslation(mAnim->GetX(), mAnim->GetY(), texTrans.z)*Scale);
	}

	Effects::BasicFX->SetMaterial(mMat);
	Effects::BasicFX->SetDiffuseMap(mTexSRV);

	if (mExplode)
	{
		ID3DX11EffectTechnique* ExploadTech;
		ExploadTech = Effects::BasicFX->ExplosionTech;
		Effects::BasicFX->SetDT(explosionDist);
		ExploadTech->GetPassByIndex(pass)->Apply(0, context);
	}
	else
	{
		activeTech->GetPassByIndex(pass)->Apply(0, context);
	}

	mBackFaceCull ? context->RSSetState(0) : context->RSSetState(RenderStates::NoCullRS);

	context->DrawIndexed(mIndexCount, mIndexOffset, mVertexOffset);
}
示例#25
0
文件: BoxDemo.cpp 项目: Dr-Wol/JWAGP
void BoxApp::DrawScene()
{
	md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::LightSteelBlue));
	md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);

	md3dImmediateContext->IASetInputLayout(mInputLayout);
	
	md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	// Press the Left Mouse Button to activate Wireframe mode, a simple if statement was made to show both work
	if (GetAsyncKeyState(VK_LBUTTON)){
		md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP);
	}

	UINT stride = sizeof(Vertex);
    UINT offset = 0;
    md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset);
	md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0);

	// Set constants
	XMMATRIX world = XMLoadFloat4x4(&mWorld);
	XMMATRIX view  = XMLoadFloat4x4(&mView);
	XMMATRIX proj  = XMLoadFloat4x4(&mProj);
	XMMATRIX worldViewProj = world*view*proj;

	XMMATRIX viewProj = view*proj;

	mfxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&worldViewProj));

    D3DX11_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );
    for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
        
		// 114 indices for the box and Octagonal.
		md3dImmediateContext->DrawIndexed(2048, 0, 0);

		for (int i = 0; i < 5; ++i)
		{
			world = XMLoadFloat4x4(&mCylWorld[i]);
			mfxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&(world*viewProj)));
			mTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
			md3dImmediateContext->DrawIndexed(mCylinderIndexCount, mCylinderIndexOffset, mCylinderVertexOffset);
		}
    }

	HR(mSwapChain->Present(0, 0));
}
示例#26
0
	bool D3D11EffectMaterial::SelectTechByName(const char* szName)
	{
		ID3DX11EffectTechnique* pTech = m_pEffect->GetTechniqueByName(szName);
		if(pTech == NULL)
		{
			return false;
		}
		if(FALSE == pTech->IsValid())
		{
			return false;
		}
		m_pTech = pTech;

		return true;
	}
void XM_CALLCONV PhysicsDebugDrawer::Begin(FXMMATRIX viewProj ) {
	ctx->OMGetBlendState(&oldBlendState, oldBlendFactor,  NULL);
	ctx->OMGetDepthStencilState(&oldStencilState, &oldStencilRef);
	ctx->RSGetState( &oldRasterizerState );

	XMMATRIX world = XMMatrixIdentity();
	XMMATRIX worldViewProj = world*viewProj;

	MyEffects::SimpleFX->SetWorldViewProj( worldViewProj );

	ctx->IASetInputLayout( InputLayouts::Simple );
	ID3DX11EffectTechnique* tech = MyEffects::SimpleFX->simpleTechnique;
	tech->GetPassByIndex( 0 )->Apply( 0, ctx );
	primitiveBatch->Begin();
}
void Triangle::draw(ID3D11DeviceContext* a_Context, CXMMATRIX a_ViewProjection)
{
    bind(a_Context);
    XMMATRIX modelViewProjection = XMLoadFloat4x4(&m_Transform) * a_ViewProjection;
    m_ShaderMVP->SetMatrix(reinterpret_cast<float*>(&modelViewProjection));

    ID3DX11EffectTechnique* technique = m_Shader->GetTechniqueByIndex(0);
    D3DX11_TECHNIQUE_DESC techDesc;
    technique->GetDesc(&techDesc);
    for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        technique->GetPassByIndex(p)->Apply(0, a_Context);
        a_Context->Draw(3, 0);
    }
}
示例#29
0
void Billboard::DrawHPSprites(CXMMATRIX viewProj)
{
	Effects::HPSpriteFX->SetDirLights(mDirLights);
	Effects::HPSpriteFX->SetEyePosW(mEyePosW);
	Effects::HPSpriteFX->SetFogColor(Colors::Silver);
	Effects::HPSpriteFX->SetFogStart(15.0f);
	Effects::HPSpriteFX->SetFogRange(175.0f);
	Effects::HPSpriteFX->SetViewProj(viewProj);
	Effects::HPSpriteFX->SetMaterial(m_HPMat);
	Effects::HPSpriteFX->SetHPTextureMapArray(m_HPTextureMapArraySRV);

	m_pDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
	m_pDeviceContext->IASetInputLayout(InputLayouts::HPPointSprite);
	UINT stride = sizeof(Vertex::HPPointSprite);
	UINT offset = 0;

	ID3DX11EffectTechnique* HPTech;
	switch (mRenderOptions)
	{
	case RenderOptions::Lighting:
		HPTech = Effects::HPSpriteFX->Light3Tech;
		break;
	case RenderOptions::Textures:
		HPTech = Effects::HPSpriteFX->Light3TexAlphaClipTech;
		break;
	case RenderOptions::TexturesAndFog:
		HPTech = Effects::HPSpriteFX->Light3TexAlphaClipFogTech;
		break;
	}

	D3DX11_TECHNIQUE_DESC techDesc;
	HPTech->GetDesc(&techDesc);
	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		m_pDeviceContext->IASetVertexBuffers(0, 1, &m_HPSpritesVB, &stride, &offset);

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

		if (mAlphaToCoverageOn)
		{
			m_pDeviceContext->OMSetBlendState(RenderStates::AlphaToCoverageBS, blendFactor, 0xffffffff);
		}
		HPTech->GetPassByIndex(p)->Apply(0, m_pDeviceContext);
		m_pDeviceContext->Draw(HP_Count, 0);

		m_pDeviceContext->OMSetBlendState(0, blendFactor, 0xffffffff);
	}
}
示例#30
0
void TreeBillboardApp::DrawTreeSprites(CXMMATRIX viewProj)
{
    Effects::TreeSpriteFX->SetDirLights(m_dirLight);
    Effects::TreeSpriteFX->SetEyePosW(m_camPosition);
	Effects::TreeSpriteFX->SetFogColor(oc::Colors::Silver);
	Effects::TreeSpriteFX->SetFogStart(15.0f);
	Effects::TreeSpriteFX->SetFogRange(175.0f);
	Effects::TreeSpriteFX->SetViewProj(viewProj);
	Effects::TreeSpriteFX->SetMaterial(m_treeMat);
    Effects::TreeSpriteFX->SetTreeTextureMapArray(m_treeTextureMapArraySRV.Get());

    m_dxImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
	m_dxImmediateContext->IASetInputLayout(InputLayouts::TreePointSprite.Get());
	uint32 stride = sizeof(Vertex::TreePointSprite);
    uint32 offset = 0;

    ID3DX11EffectTechnique* treeTech = nullptr;
    switch(m_renderOptions)
	{
	case RenderOptions::Lighting:
        treeTech = Effects::TreeSpriteFX->Light3Tech;
		break;
	case RenderOptions::Textures:
		treeTech = Effects::TreeSpriteFX->Light3TexAlphaClipTech;
		break;
	case RenderOptions::TexturesAndFog:
		treeTech = Effects::TreeSpriteFX->Light3TexAlphaClipFogTech;
		break;
	}

    D3DX11_TECHNIQUE_DESC techDesc;
	treeTech->GetDesc( &techDesc );
	for(uint32 p = 0; p < techDesc.Passes; ++p)
    {
        m_dxImmediateContext->IASetVertexBuffers(0, 1, m_treeSpritesVB.GetAddressOf(), &stride, &offset);

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

        if(m_alphaToCoverageOn)
		{
            m_dxImmediateContext->OMSetBlendState(RenderStates::AlphaToCoverageBS.Get(), blendFactor, 0xffffffff);
		}
		treeTech->GetPassByIndex(p)->Apply(0, m_dxImmediateContext.Get());
		m_dxImmediateContext->Draw(TreeCount, 0);

		m_dxImmediateContext->OMSetBlendState(0, blendFactor, 0xffffffff);
	}
}