Ejemplo n.º 1
0
void RenderTargetPingPong::Apply(ID3D11Device* device, ID3DX11EffectTechnique* technique)
{
	ID3D11DeviceContext* context;
	device->GetImmediateContext(&context);
	
	ID3D11Buffer* zero = 0;
	UINT nought = 0;
	context->IASetVertexBuffers(0,1,&zero,&nought,&nought);
	context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
	context->IASetInputLayout(0);

	{
		ID3D11RenderTargetView* view[] = { m_target->RenderTargetView() };
		context->OMSetRenderTargets(1, const_cast<ID3D11RenderTargetView**> (view), m_depth_stencil_view);
	}

	m_shader_resource_variable->SetResource(m_source->ShaderResourceView());

	for(UINT n = 0; n < Effect::NumPasses(technique); ++n)
	{
		technique->GetPassByIndex(n)->Apply(0,context);
		context->Draw(4,0);
	}

	m_shader_resource_variable->SetResource(0);
	m_last_target = m_target;
	std::swap(m_source,m_target);
}
Ejemplo n.º 2
0
bool SkyBox::Render(std::shared_ptr<D3DRenderer> d3d, DirectX::CXMMATRIX world, DirectX::CXMMATRIX view, DirectX::CXMMATRIX projection, std::shared_ptr<Camera> camera, std::shared_ptr<Light> light)
{
	ID3D11DeviceContext *context = d3d->GetDeviceContext();
	DirectX::XMMATRIX sphereWorld = DirectX::XMMatrixIdentity(), scale = DirectX::XMMatrixScaling(0.3f, 0.3f, 0.3f), translation;

	translation = DirectX::XMMatrixTranslationFromVector(camera->GetPosition());
	sphereWorld = scale * translation;

	if (!SetShaderParameters(context, sphereWorld, view, projection, texture->GetTexture()))
		return false;

	UINT strides = sizeof(DirectX::VertexPositionNormalTexture), offset = 0;

	context->IASetInputLayout(m_layout);
	context->IASetIndexBuffer(sphereIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
	context->IASetVertexBuffers(0, 1, &sphereVertBuffer, &strides, &offset);
	context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	
	context->PSSetShader(pixelShader, NULL, 0);
	context->VSSetShader(vertexShader, NULL, 0);
	context->RSSetState(d3d->GetRasterState(1));

	d3d->SetDepthLessEqual();

	context->DrawIndexed(NumSphereFaces*3, 0, 0);

	d3d->End2D();

	context->RSSetState(d3d->GetRasterState(0));

	return true;
}
void ParticleManager::RenderParticles(DxGraphics* pDxGraphics, Camera& cam)
{
	cam.CalculateViewMatrix();

	XMMATRIX tWorld = XMMatrixTranspose(m_worldMat);
	XMMATRIX tView = XMMatrixTranspose(cam.GetViewMatrix());
	XMMATRIX tProj = XMMatrixTranspose(cam.GetProjMatrix());

	ID3D11DeviceContext* pCon = pDxGraphics->GetImmediateContext();
	
	UINT stride = sizeof(Particle);
	UINT offset = 0;

	pCon->IASetVertexBuffers(0, 1, &m_vBuffer, &stride, &offset);
	pCon->IASetInputLayout(m_inputLayout);
	pCon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);

	pCon->VSSetShader(m_vShader, 0, 0);
	pCon->PSSetShader(m_pShader, 0, 0);

	pCon->UpdateSubresource(m_camWorldBuffer, 0, NULL, &tWorld, 0, 0);
	pCon->UpdateSubresource(m_camViewBuffer, 0, NULL, &tView, 0, 0);
	pCon->UpdateSubresource(m_camProjBuffer, 0, NULL, &tProj, 0, 0);

	pCon->VSSetConstantBuffers(0, 1, &m_camWorldBuffer);
	pCon->VSSetConstantBuffers(1, 1, &m_camViewBuffer);
	pCon->VSSetConstantBuffers(2, 1, &m_camProjBuffer);

	pCon->Draw(m_particleList.size(), 0);

	pCon->VSSetShader(NULL, 0, 0);
	pCon->GSSetShader(NULL, 0, 0);
	pCon->PSSetShader(NULL, 0, 0);
}
    void CFullscreenTriangleDrawer::DrawDX11( ID3D11ShaderResourceView* pTextureSRV )
    {
        ID3D11Device* pDevice = static_cast<ID3D11Device*>( gD3DDevice );
        ID3D11DeviceContext* pContext = NULL;
        pDevice->GetImmediateContext( &pContext );

        CDX11StateGuard stateGuard;

        pContext->IASetInputLayout( NULL );
        pContext->IASetIndexBuffer( NULL, DXGI_FORMAT_UNKNOWN, 0 );
        pContext->IASetVertexBuffers( 0, 0, NULL, NULL, NULL );
        pContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

        pContext->VSSetShader( m_pVertexShader11, NULL, 0 );
        pContext->PSSetShader( m_pPixelShader11, NULL, 0 );
        ID3D11SamplerState* pNullSampler[] = { NULL };
        pContext->PSSetSamplers( 0, 1, pNullSampler );

        pContext->PSSetShaderResources( 0, 1, &pTextureSRV );

        pContext->OMSetBlendState( m_pBlendState11, NULL, 0xFFFFFFFF );

        // Draw
        pContext->Draw( 3, 0 );
    }
Ejemplo n.º 5
0
//-----------------------------------------
void CPUTSprite::DrawSprite(
    CPUTRenderParameters &renderParams,
    CPUTMaterial         &material
)
{
    // TODO: Should we warn here?
    // If it doesn't draw, make sure you created it with createDebugSprite == true
    if( mpVertexBuffer )
    {
        ID3D11DeviceContext *pContext = ((CPUTRenderParametersDX*)&renderParams)->mpContext;

        material.SetRenderStates(renderParams);

        UINT stride = sizeof( SpriteVertex );
        UINT offset = 0;
        pContext->IASetVertexBuffers( 0, 1, &mpVertexBuffer, &stride, &offset );

        // Set the input layout
        pContext->IASetInputLayout( mpInputLayout );

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

        pContext->Draw( 6, 0 );
    }
} // CPUTSprite::DrawSprite()
Ejemplo n.º 6
0
//---------------------------------------------------------------------------
void FontRenderer::FontDrawingBegin(  RenderContext* rc )
{
    assert( m_vertexBuffer != NULL );
    assert( m_indexBuffer != NULL );

    m_currentRC = rc;

    m_fontDrawOps.clear();

    ID3D11DeviceContext* dc = m_currentRC->Context();

    UINT viewportCount = 1;
    D3D11_VIEWPORT vp;
    dc->RSGetViewports(&viewportCount, &vp);

    UINT stride = sizeof(FontTextVertex);
    UINT offset = 0;
    dc->IASetInputLayout(m_vertexLayout);
    dc->IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0);
    dc->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset);
    dc->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    dc->VSSetShader( m_vertexShader, 0, 0 );
    dc->PSSetShader( m_pixelShader, 0, 0 );
    dc->PSSetSamplers( 0, 1, &m_samplerState );

    dc->RSSetState(m_rasterState);

    float blendFactor[4] = {1.0f};
    dc->OMSetBlendState(m_blendState, blendFactor, 0xffffffff);

    m_activeFont = NULL;    // needs to be set!
}
Ejemplo n.º 7
0
	void Render::Draw()
	{
		UINT stride = sizeof(GENERIC::Vertex);
		UINT offset = 0;

		ID3D11DeviceContext* context = RenderDevice::Get()->GetContext();

		context->IASetInputLayout(_inputLayout);
		context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

		context->IASetVertexBuffers(0, 1, &pVB, &stride, &offset);
		context->IASetIndexBuffer(pIB, DXGI_FORMAT_R32_UINT, 0);

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

		XMMATRIX world	= pOwner->GetComponent<Transform>()->GetWorldMatrix();
		XMMATRIX vp		= General::Get()->GetMainCamera()->GetViewProjectionMatrix();
		
		Effect::BasicEffect::Get()->SetWorldMatrix(reinterpret_cast<float*>(&world));
		Effect::BasicEffect::Get()->SetViewProjectionMatrix(reinterpret_cast<float*>(&vp));

		for (UINT i = 0; i < techDesc.Passes; ++i)
		{
			_tech->GetPassByIndex(i)->Apply(0, context);
			context->DrawIndexed(_meshData->GetNumIndices(), 0, 0);
		}
	}
void ComplexTree::draw(ID3D11Device* device, const GameTime& gameTime)
{
	ID3D11DeviceContext* deviceContext;
	device->GetImmediateContext(&deviceContext);

	ID3D11Buffer* buffers[2] = { trunkMesh.GetVB11(0, 0), instanceBuffer };
	unsigned strides[2] = { trunkMesh.GetVertexStride(0,0), sizeof(Vector3) };
	unsigned offsets[2] = {0};
	deviceContext->IASetInputLayout(inputLayout);
	deviceContext->IASetVertexBuffers(0, 2, buffers, strides, offsets);
	deviceContext->IASetIndexBuffer(trunkMesh.GetIB11(0), trunkMesh.GetIBFormat11(0), 0);

	Camera& camera = vegetationRendering.getCamera();
	const Light& light = vegetationRendering.getLight();

	D3D11_VIEWPORT viewport;
	unsigned numViewports = 1;
	deviceContext->RSGetViewports(&numViewports, &viewport);

	evGSCulling->SetBool(vegetationRendering.isGSCullingEnabled());
	evShowSavedCulling->SetBool(vegetationRendering.showSaved());
	evSavedViewProjection->SetMatrix(vegetationRendering.getSavedViewMatrix() * vegetationRendering.getSavedProjectionMatrix());
	evCameraPosition->SetFloatVector(camera.getPosition());
	evLightVector->SetFloatVector(Vector3(light.Direction.x, light.Direction.y, light.Direction.z));
	evAmbientLight->SetFloatVector(Vector3(light.Ambient.r, light.Ambient.g, light.Ambient.b));
	evDiffuseLight->SetFloatVector(Vector3(light.Diffuse.r, light.Diffuse.g, light.Diffuse.b));
	evSpecularLight->SetFloatVector(Vector3(light.Specular.r, light.Specular.g, light.Specular.b));
	evShininess->SetFloat(TREE_SHININESS);

	evWorld->SetMatrix(world);
	evViewProjection->SetMatrix(camera.getView() * camera.getProjection(TREE_NEAR_PLANE, TREE_FAR_PLANE));

	for(unsigned i = 0; i < trunkMesh.GetNumSubsets(0); ++i)
	{
		SDKMESH_SUBSET* subset = trunkMesh.GetSubset(0, i);
		//D3D11_PRIMITIVE_TOPOLOGY primitiveType = trunkMesh.GetPrimitiveType11((SDKMESH_PRIMITIVE_TYPE)subset->PrimitiveType);
		deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST);
		SDKMESH_MATERIAL* material = trunkMesh.GetMaterial(subset->MaterialID);
		if(material)
			evTrunkTexture->SetResource(material->pDiffuseRV11);
		pass->Apply(0, deviceContext);
		deviceContext->DrawIndexedInstanced((unsigned)subset->IndexCount, drawInstanceCount,
			(unsigned)subset->IndexStart, (int)subset->VertexStart,0);
		//deviceContext->DrawIndexed((unsigned)subset->IndexCount, (unsigned)subset->IndexStart, (int)subset->VertexStart);
	}

	/*deviceContext->IASetInputLayout(inputLayoutLOD1);
	unsigned stride = sizeof(float) * 3;
	unsigned offset = 0;
	deviceContext->IASetVertexBuffers(0, 1, &instanceBuffer, &stride, &offset);
	deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);

	evWorld->SetMatrix(Matrix::createScale(Vector3(9)));

	passLOD1->Apply(0, deviceContext);
	deviceContext->Draw(INSTANCE_COUNT, 0);*/

	deviceContext->Release();
}
Ejemplo n.º 9
0
void PipelineStateCache::setInputLayout(ID3D11InputLayout* inputLayout)
{
  if (inputLayout != m_currentInputLayout)
  {
    m_currentInputLayout = inputLayout;
    m_deviceContext->IASetInputLayout(inputLayout);
  }
}
Ejemplo n.º 10
0
void FBXObject::SetupDrawInputVertexShader()
{
	ID3D11DeviceContext* pImmediateContext = DX11App::getInstance()->direct3d.pImmediateContext;

	pImmediateContext->IASetInputLayout( this->pInputLayout.second );
	pImmediateContext->VSSetShader( this->pVertexShader.second, NULL, 0 );
	
}
static void DoRendering (const float* worldMatrix, const float* identityMatrix, float* projectionMatrix, const MyVertex* verts)
{
    // Does actual rendering of a simple triangle

    #if SUPPORT_D3D11
    // D3D11 case
    if (s_DeviceType == kUnityGfxRendererD3D11 && EnsureD3D11ResourcesAreCreated())
    {
        ID3D11DeviceContext* ctx = NULL;
        g_D3D11Device->GetImmediateContext (&ctx);

        ID3D11RenderTargetView*  pCurrentRenderTarget;
        ID3D11DepthStencilView*  pCurrentDepthStencil;

        // Get the current render targets
        ctx->OMGetRenderTargets(1, &pCurrentRenderTarget, &pCurrentDepthStencil);

        ctx->OMSetRenderTargets(1, &g_pD3D11RenderTargetView, nullptr);

        /*
        // update native texture from code
        D3D11_TEXTURE2D_DESC desc;
        g_TexturePointer->GetDesc(&desc);
        unsigned char* data = new unsigned char[desc.Width*desc.Height * 4];
        FillTextureFromCode(desc.Width, desc.Height, desc.Width * 4, data);
        ctx->UpdateSubresource(g_TexturePointer, 0, NULL, data, desc.Width * 4, 0);
        delete[] data;
        */
        const float CLEAR_CLR[4] = { 1, 1, 0, 1 };  // Yellow

        ctx->ClearRenderTargetView(g_pD3D11RenderTargetView, CLEAR_CLR);

        // Restore the original render target
        ctx->OMSetRenderTargets(1, &pCurrentRenderTarget, pCurrentDepthStencil);

        // update constant buffer - just the world matrix in our case
        ctx->UpdateSubresource (g_D3D11CB, 0, NULL, worldMatrix, 64, 0);

        // set shaders
        ctx->VSSetConstantBuffers (0, 1, &g_D3D11CB);
        ctx->VSSetShader (g_D3D11VertexShader, NULL, 0);
        ctx->PSSetShader (g_D3D11PixelShader, NULL, 0);

        // update vertex buffer
        ctx->UpdateSubresource (g_D3D11VB, 0, NULL, verts, sizeof(verts[0])*3, 0);

        // set input assembler data and draw
        ctx->IASetInputLayout (g_D3D11InputLayout);
        ctx->IASetPrimitiveTopology (D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
        UINT stride = sizeof(MyVertex);
        UINT offset = 0;
        ctx->IASetVertexBuffers (0, 1, &g_D3D11VB, &stride, &offset);
        ctx->Draw (3, 0);

        ctx->Release();
    }
    #endif
}
Ejemplo n.º 12
0
void CD3DPixelShader::UnbindShader()
{
  if (!m_inited)
    return;

  ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context();
  pContext->IASetInputLayout(nullptr);
  pContext->VSSetShader(nullptr, nullptr, 0);
}
void DeferredPipeline::Lighting::set_layout_spot_light_shaders_samplers(ID3D11DeviceContext& device_context)
{
	device_context.IASetInputLayout(_vertex_input_layout);

	device_context.VSSetShader(_vertex_shader, nullptr, 0);
	device_context.PSSetShader(_spot_light_pixel_shader, nullptr, 0);

	device_context.PSSetSamplers(0, 1, &_sampler_state);
}
Ejemplo n.º 14
0
void Terrain::DrawShadowMap(const Camera& cam)
{
	ID3D11DeviceContext* dc = pDeviceContext;

	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 view = XMLoadFloat4x4(&d3d->m_LightView);
	XMMATRIX proj = XMLoadFloat4x4(&d3d->m_LightProj);
	XMMATRIX viewProj = XMMatrixMultiply(view, proj);
	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, cam.ViewProj());

	// Set per frame constants.
	
	Effects::TerrainFX->SetViewProj(viewProj);
	Effects::TerrainFX->SetEyePosW(cam.GetPosition());
	Effects::TerrainFX->SetMinDist(20.0f);
	Effects::TerrainFX->SetMaxDist(400.0f);
	Effects::TerrainFX->SetMinTess(0.0f);
	Effects::TerrainFX->SetMaxTess(3.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->SetHeightMap(mHeightMapSRV);
	Effects::TerrainFX->SetShadowMap(d3d->GetShadowMap());
	Effects::TerrainFX->SetShadowTransform(ShadowTransform);

	ID3DX11EffectTechnique* tech = Effects::TerrainFX->TessBuildShadowMapTech;
    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);
}
Ejemplo n.º 15
0
    void Effect::Bind(const string& group, const string& technique, const string& pass) {
        ID3D11DeviceContext* context = GraphicsManager::Get()->GetImmidiateContext();
        
        const PassData& passData = FindPassData(group, technique, pass);
        _ASSERT(passData.inputLayout);

        context->IASetInputLayout(passData.inputLayout);

        _ASSERT(passData.pass);
        passData.pass->Apply(0, context);
    }
            ~CDX11StateGuard()
            {
                ID3D11Device* pDevice = static_cast<ID3D11Device*>( gD3DDevice );
                ID3D11DeviceContext* pContext = NULL;
                pDevice->GetImmediateContext( &pContext );

                // Apply saved state
                pContext->OMSetBlendState( m_pBlendState, m_BlendFactor, m_SampleMask );
                pContext->RSSetState( m_pRasterizerState );
                pContext->IASetPrimitiveTopology( m_PrimitiveTopology );
                pContext->IASetIndexBuffer( m_pIndexBuffer, m_IndexBufferFormat, m_IndexBufferOffset );
                pContext->IASetInputLayout( m_pInputLayout );
                pContext->IASetVertexBuffers( 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, m_pVertexBuffers, m_pVertexBufferStrides, m_pVertexBufferOffsets );
                pContext->VSSetShader( m_pVertexShader, m_ppVertexShaderClassInstances, m_VertexShaderClassInstancesCount );
                pContext->PSSetShader( m_pPixelShader, m_ppPixelShaderClassInstances, m_PixelShaderClassInstancesCount );
                pContext->PSSetSamplers( 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, m_ppPixelShaderSamplers );
                pContext->PSSetShaderResources( 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, m_ppPixelShaderResources );

                // Release references
                SAFE_RELEASE( m_pBlendState );
                SAFE_RELEASE( m_pRasterizerState );
                SAFE_RELEASE( m_pIndexBuffer );
                SAFE_RELEASE( m_pInputLayout );

                for ( UINT i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i )
                {
                    SAFE_RELEASE( m_pVertexBuffers[i] );
                }

                SAFE_RELEASE( m_pVertexShader );

                for ( UINT i = 0; i < m_VertexShaderClassInstancesCount; ++i )
                {
                    SAFE_RELEASE( m_ppVertexShaderClassInstances[i] );
                }

                SAFE_RELEASE( m_pPixelShader );

                for ( UINT i = 0; i < m_PixelShaderClassInstancesCount; ++i )
                {
                    SAFE_RELEASE( m_ppPixelShaderClassInstances[i] );
                }

                for ( UINT i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i )
                {
                    SAFE_RELEASE( m_ppPixelShaderSamplers[i] );
                }

                for ( UINT i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i )
                {
                    SAFE_RELEASE( m_ppPixelShaderResources[i] );
                }
            }
Ejemplo n.º 17
0
void CD3DVertexShader::BindShader()
{
  if (!m_inited)
    return;

  ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context();
  if (!pContext)
    return;

  pContext->IASetInputLayout(m_inputLayout);
  pContext->VSSetShader(m_VS, nullptr, 0);
}
void ParticleManager::UpdateParticles(float dt, DxGraphics* pDxGraphics, Camera& cam)
{
	// Update the world mat
	XMMATRIX transMat = XMMatrixTranslation(0.0f, 0.0f, 0.0f);
	XMMATRIX rotMat = XMMatrixRotationRollPitchYaw(0.0f, 0.0f, 0.0f);
	XMMATRIX scaleMat = XMMatrixScaling(1.0f, 1.0f, 1.0f);

	m_worldMat = rotMat * scaleMat * transMat;

	cam.CalculateViewMatrix();

	// stream out the particles which runs through the physics
	XMMATRIX tWorld = XMMatrixTranspose(m_worldMat);
	XMMATRIX tView = XMMatrixTranspose(cam.GetViewMatrix());
	XMMATRIX tProj = XMMatrixTranspose(cam.GetProjMatrix());

	m_massPoint.dt = dt;

	ID3D11DeviceContext* pCon = pDxGraphics->GetImmediateContext();

	// Set the stream out buffer
	UINT offsetSO[1] = { 0 };
	pCon->SOSetTargets(1, &m_vStream, offsetSO);

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

	pCon->IASetVertexBuffers(0, 1, &m_vBuffer, &stride, &offset);
	pCon->IASetInputLayout(m_inputLayout);
	pCon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);

	pCon->VSSetShader(m_vUpdate, 0, 0);
	pCon->GSSetShader(m_gUpdate, 0, 0);
	pCon->PSSetShader(NULL, 0, 0);

	//// Update the cBuffer
	pCon->UpdateSubresource(m_pointBuffer, 0, NULL, &m_massPoint, 0, 0);

	pCon->VSSetConstantBuffers(3, 1, &m_pointBuffer);

	pCon->Draw(m_particleList.size(), 0);

	pCon->VSSetShader(NULL, 0, 0);
	pCon->GSSetShader(NULL, 0, 0);
	pCon->PSSetShader(NULL, 0, 0);

	// Unbind the SO
	ID3D11Buffer* bufferArray[1] = { 0 };
	pCon->SOSetTargets(1, bufferArray, offsetSO);
	
	std::swap(m_vStream, m_vBuffer);
}
Ejemplo n.º 19
0
void MSAAFilter::RenderAA()
{
    PIXEvent pixEvent(L"MSAA Resolve + Temporal AA");
    ProfileBlock profileBlock(L"MSAA Resolve + Temporal AA");

    ID3D11DeviceContext* context = deviceManager.ImmediateContext();

    ID3D11RenderTargetView* rtvs[1] = { resolveTarget.RTView };

    context->OMSetRenderTargets(1, rtvs, nullptr);

    if(AppSettings::UseStandardResolve)
    {
        if(AppSettings::MSAAMode == 0)
            context->CopyResource(resolveTarget.Texture, colorTarget.Texture);
        else
            context->ResolveSubresource(resolveTarget.Texture, 0, colorTarget.Texture, 0, colorTarget.Format);
        return;
    }

    const uint32 SampleRadius = static_cast<uint32>((AppSettings::ResolveFilterDiameter / 2.0f) + 0.499f);
    ID3D11PixelShader* pixelShader = resolvePS[AppSettings::MSAAMode];
    context->PSSetShader(pixelShader, nullptr, 0);
    context->VSSetShader(resolveVS, nullptr, 0);

    resolveConstants.Data.TextureSize = Float2(static_cast<float>(colorTarget.Width), static_cast<float>(colorTarget.Height));
    resolveConstants.Data.SampleRadius = SampleRadius;;
    resolveConstants.ApplyChanges(context);
    resolveConstants.SetPS(context, 0);

    ID3D11ShaderResourceView* srvs[] = { colorTarget.SRView, velocityTarget.SRView, depthBuffer.SRView, prevFrameTarget.SRView};
    context->PSSetShaderResources(0, ArraySize_(srvs), srvs);

    ID3D11SamplerState* samplers[] = { samplerStates.LinearClamp(), samplerStates.Point() };
    context->PSSetSamplers(0, ArraySize_(samplers), samplers);

    ID3D11Buffer* vbs[1] = { nullptr };
    UINT strides[1] = { 0 };
    UINT offsets[1] = { 0 };
    context->IASetVertexBuffers(0, 1, vbs, strides, offsets);
    context->IASetInputLayout(nullptr);
    context->IASetIndexBuffer(nullptr, DXGI_FORMAT_R16_UINT, 0);
    context->Draw(3, 0);

    rtvs[0] = nullptr;
    context->OMSetRenderTargets(1, rtvs, nullptr);

    srvs[0] = srvs[1] = srvs[2] = nullptr;
    context->PSSetShaderResources(0, 3, srvs);

    context->CopyResource(prevFrameTarget.Texture, resolveTarget.Texture);
}
Ejemplo n.º 20
0
	void MultiTextureShader::RenderShader(Graphics* graphics)
	{
		ID3D11DeviceContext* deviceContext = graphics->GetImmediateContex();
		deviceContext->IASetInputLayout(m_layout);

		// set the vertex and pixel shaders that will be used to render 
		deviceContext->VSSetShader(m_vertexShader,NULL,0);
		deviceContext->PSSetShader(m_pixelShader,NULL,0);

		// set the sampler state
		deviceContext->PSSetSamplers(0,1,&m_sampleState);

	}
Ejemplo n.º 21
0
void Shader::bind(D3DRenderer* renderer)
{
	ID3D11DeviceContext* context = renderer->context();

	context->IASetInputLayout(mpInputLayout);
	context->IASetPrimitiveTopology(mPrimitiveTopology);

	//Set any active shaders and disable ones not in use
	context->VSSetShader(mpVertexShader, NULL, 0);
	context->PSSetShader(mpPixelShader, NULL, 0);
	context->GSSetShader(mpGeometryShader, NULL, 0);
	context->CSSetShader(mpComputeShader, NULL, 0);
	context->HSSetShader(mpHullShader, NULL, 0);
	context->DSSetShader(mpDomainShader, NULL, 0);
}
Ejemplo n.º 22
0
		void ProjectiveTextureShader::RenderShader(int indexCount)
		{
			ID3D11DeviceContext* deviceContext = GraphicsDX::GetDeviceContext();
			deviceContext->IASetInputLayout(m_layout);

			// Set the vertex and pixel shaders that will be used to render this triangle.
			deviceContext->VSSetShader(m_vertexShader, NULL, 0);
			deviceContext->PSSetShader(m_pixelShader, NULL, 0);

			// Set the sampler state in the pixel shader.
			deviceContext->PSSetSamplers(0, 1, &m_sampleState);

			// Render the triangle.
			deviceContext->DrawIndexed(indexCount, 0, 0);
		}
Ejemplo n.º 23
0
void D3D11Mesh::Render()
{
	ID3D11DeviceContext* pContext = m_shader->GetContext();
	ID3D11ShaderResourceView* ptexRv = dynamic_cast<D3D11Texture*>(m_tex)->m_textureRV;

	unsigned int stride = sizeof(Vertex);
	unsigned int offset = 0;

	pContext->IASetInputLayout(m_vertexLayout);
	pContext->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset);
	pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	pContext->PSSetShaderResources(0, 1, &ptexRv);

	pContext->Draw(m_numtriangles*3, 0);
}
Ejemplo n.º 24
0
void D3D11App::DebugViewTexture2D(ID3D11ShaderResourceView *srv, const float x, const float y, const float width, const float height, const int slice)
{
	// Make sure we have enough space in the vertex buffer
	SetToolsVBSize(4 * sizeof(Pos2Tex3));

	// Fill vertex buffer
	Pos2Tex3 *dest;
	ID3D11DeviceContext* context = m_context->GetDeviceContext();
	D3D11_MAPPED_SUBRESOURCE resource;
	context->Map(m_toolsVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &resource);
	dest = reinterpret_cast<Pos2Tex3*> ( resource.pData );
		dest[0].pos = float2(x, y + height);
		dest[0].tex = float3(0, 0, (float) slice);
		dest[1].pos = float2(x + width, y + height);
		dest[1].tex = float3(1, 0, (float) slice);
		dest[2].pos = float2(x, y);
		dest[2].tex = float3(0, 1, (float) slice);
		dest[3].pos = float2(x + width, y);
		dest[3].tex = float3(1, 1, (float) slice);
	context->Unmap(m_toolsVB, 0);


	ID3D11DeviceContext *dev = m_context->GetDeviceContext();

	// Setup the effect
	m_context->SetEffect(m_toolsEffect);
	if (slice < 0)
	{
		m_context->SetTexture("tex2d", srv);
		m_context->Apply(2, 0);
	}
	else
	{
		m_context->SetTexture("texArray", srv);
		m_context->Apply(2, 1);
	}

	dev->IASetInputLayout(m_pos2Tex3Layout);

	UINT stride = sizeof(Pos2Tex3);
	UINT offset = 0;
	dev->IASetVertexBuffers(0, 1, &m_toolsVB, &stride, &offset);

	// Render a textured quad
	dev->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
	dev->Draw(4, 0);
}
Ejemplo n.º 25
0
const void ShaderClass::RenderShader(UINT indexCount, UINT indexStart)const
{
	ID3D11DeviceContext* c = SystemClass::GetInstance()->mGrapInst->GetContext();

	// Set the vertex input layout.
	c->IASetInputLayout(mLayout);

	// Set the vertex and pixel shaders that will be used to render this triangle.
	c->VSSetShader(mVertexShader, nullptr, 0);
	c->HSSetShader(mHullShader, nullptr, 0);
	c->DSSetShader(mDomainShader, nullptr, 0);
	c->GSSetShader(mGeometryShader, nullptr, 0);
	c->PSSetShader(mPixelShader, nullptr, 0);

	// Render mesh stored in active buffers
	c->DrawIndexed(indexCount, indexStart, 0);
}
Ejemplo n.º 26
0
void Draw()
{
	ID3D11DeviceContext* context = g_d3d.context_.get();
	
	// Clear
	float clearColor[] = { 0.3f, 0.3f, 0.3f, 1.0f };
	context->ClearRenderTargetView( g_d3d.backBufferRTV_.get(), clearColor );

	auto* rtv = g_d3d.backBufferRTV_.get();
	context->OMSetRenderTargets( 1, &rtv, nullptr );
	
	// Draw body

	auto cbModelWVP = DirectX::XMMatrixIdentity();
	auto matWorld = DirectX::XMMatrixIdentity();
	matWorld = DirectX::XMMatrixRotationRollPitchYaw( g_d3d.jointRot_[ 0 ], g_d3d.jointRot_[ 1 ], g_d3d.jointRot_[ 2 ] );
	auto matView =  DirectX::XMMatrixLookAtLH(
		DirectX::XMVectorSet( 0, 0, -3, 0 ), DirectX::XMVectorSet( 0, 0, 5, 0 ), DirectX::XMVectorSet( 0, 1, 0, 0 )
		);
	auto matProj = DirectX::XMMatrixPerspectiveFovLH(
		DirectX::XMConvertToRadians( 50 ), (float)g_windowWidth / (float)g_windowHeight, 0.01f, 1000.0f
		);
	cbModelWVP = matWorld * matView * matProj;
	cbModelWVP = DirectX::XMMatrixTranspose( cbModelWVP );
	g_d3d.context_->UpdateSubresource( g_d3d.modelCB_.get(), 0, nullptr, &cbModelWVP, 0, 0 );

	auto* vb = g_d3d.modelVB_.get();
	unsigned int stride = sizeof( D3D::MeshFormat );
	unsigned int offset = 0;
	auto* cb = g_d3d.modelCB_.get();
	D3D11_VIEWPORT viewport = { 0, 0, g_windowWidth, g_windowHeight, 0, 1 };
	context->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
	context->IASetInputLayout( g_d3d.modelIL_.get() );
	context->IASetVertexBuffers( 0, 1, &vb, &stride, &offset );
	context->VSSetShader( g_d3d.modelVS_.get(), nullptr, 0 );
	context->VSSetConstantBuffers( 0, 1, &cb );
	context->RSSetState( g_d3d.rasterState_.get() );
	context->PSSetShader( g_d3d.modelPS_.get(), nullptr, 0 );
	context->RSSetViewports( 1, &viewport );
	context->Draw( 18, 0 );

	g_d3d.swapChain_->Present( 1, 0 );
}
Ejemplo n.º 27
0
	void CubeDemo::draw(const GameTimer & timer)
	{
		ID3D11DeviceContext * deviceContext = mGame->deviceContext();
		deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
		deviceContext->IASetInputLayout(mInputLayout);

		UINT stride = sizeof(BasicEffectVertex);
		UINT offset = 0;
		deviceContext->IASetVertexBuffers(0, 1, &mVertexBuffer, &stride, &offset);
		deviceContext->IASetIndexBuffer( mIndexBuffer, DXGI_FORMAT_R32_UINT, 0);

		XMMATRIX worldMatrix = XMLoadFloat4x4(&mWorldMatrix);
		XMMATRIX wvp = worldMatrix * mCamera->viewMatrix() * mCamera->projectionMatrix();
		mWvpVariable->SetMatrix(reinterpret_cast<float*>(&wvp));

		mPass->Apply(0, deviceContext);
		deviceContext->DrawIndexed(36,0, 0);

	}
Ejemplo n.º 28
0
	//----------------------------------------------------------------------------------------------------
	bool EEPoints2D::Render()
	{
		if (!EEObject::Render())
			return false;

		MapObjectBuffer();

		ID3D11DeviceContext *deviceContext = EECore::s_EECore->GetDeviceContext();
		deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
		deviceContext->IASetInputLayout(s_pointsIL);
		UINT stride = sizeof(EEPoints2DVertex);
		UINT offset = 0;
		deviceContext->IASetVertexBuffers(0, 1, &m_pointsVB, &stride, &offset);
		deviceContext->IASetIndexBuffer(NULL, DXGI_FORMAT_R32_UINT, 0);
		deviceContext->VSSetShader(s_pointsVS, NULL, 0);
		deviceContext->PSSetShader(s_pointsPS, NULL, 0);
		deviceContext->Draw(m_points.size(), 0);

		return true;
	}
Ejemplo n.º 29
0
		void FontShader::renderShader(int i_indexCount)
		{
			ID3D11DeviceContext* deviceContext = GraphicsDX::GetDeviceContext();

			// Set the vertex input layout.
			deviceContext->IASetInputLayout(_layout);

			// Set the vertex and pixel shaders that will be used to render the triangles.
			deviceContext->VSSetShader(_vertexShader, NULL, 0);
			deviceContext->HSSetShader(nullptr, NULL, 0);
			deviceContext->DSSetShader(nullptr, NULL, 0);
			deviceContext->GSSetShader(nullptr, NULL, 0);
			deviceContext->PSSetShader(_pixelShader, NULL, 0);

			// Set the sampler state in the pixel shader.
			deviceContext->PSSetSamplers(0, 1, &_sampleState);

			// Render the triangles.
			deviceContext->DrawIndexed(i_indexCount, 0, 0);
		}
Ejemplo n.º 30
0
//-----------------------------------------------------------------------------
void CPUTMeshDX11::Draw(CPUTRenderParameters &renderParams, CPUTModel *pModel, ID3D11InputLayout *pInputLayout )
{
	mDrawCallCount++;
    // Skip empty meshes.
    if( !mIndexCount ) { return; }

// TODO: Modify CPUTPerfTaskMarker so that calls compile out, instead of explicitly wrapping every call with ifdef CPUT_GPA_INSTRUMENTATION
#ifdef CPUT_GPA_INSTRUMENTATION
    CPUTPerfTaskMarker marker = CPUTPerfTaskMarker(D3DCOLOR(0xff0000), _L("CPUT Draw Mesh"));
#endif
    ID3D11DeviceContext *pContext = ((CPUTRenderParametersDX*)&renderParams)->mpContext;

    pContext->IASetPrimitiveTopology( mD3DMeshTopology );
    pContext->IASetVertexBuffers(0, 1, &mpVertexBuffer, &mVertexStride, &mVertexBufferOffset);
    pContext->IASetIndexBuffer(mpIndexBuffer, mIndexBufferFormat, 0);

    pContext->IASetInputLayout( pInputLayout );

    pContext->DrawIndexed( mIndexCount, 0, 0 );
}