Exemplo n.º 1
0
void FXAASample::DrawScene()
{
	SwapChainPtr->Begin();
	ID3D11RenderTargetView* pRTV = SwapChainPtr->GetRenderTargetView();
	ID3D11DepthStencilView* pDSV = SwapChainPtr->GetDepthStencilView();
	pRTV = colorRT->GetRTView();
	float ClearColor[4] = { sqrt(0.25f), sqrt(0.25f), sqrt(0.5f), 0.0f };
	m_deviceContext->ClearRenderTargetView(pRTV, ClearColor);
	m_deviceContext->ClearDepthStencilView(pDSV, D3D11_CLEAR_DEPTH, 1.0, 0);
	// Rebind to original back buffer and depth buffer
	ID3D11RenderTargetView * pRTVs[2] = { pRTV, NULL };
	pRTVs[0] = colorRT->GetRTView();
	m_deviceContext->OMSetRenderTargets(1, pRTVs, pDSV);
	RenderSample();

	SwapChainPtr->Begin();
	// apply FXAA
	if (m_fxaaEnabled)
	{
		MaterialPtr pFXAAShader = g_objMaterial.GetShader("HLSL\\FXAA.hlsl");
		m_deviceContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
		float frameWidth = (float)mClientWidth;
		float frameHeight = (float)mClientHeight;
		Vector4  vFxaa = Vector4(1.0f / frameWidth, 1.0f / frameHeight, 0.0f, 0.0f);

		pFXAAShader->VSSetConstantBuffers("RCPFrame", &vFxaa);
		pFXAAShader->PSSetConstantBuffers("RCPFrame", &vFxaa);

		pFXAAShader->PSSetShaderResources(TU_DIFFUSE, colorRT->GetSRView());
		pFXAAShader->Apply();
		m_deviceContext->Draw(3, 0);
	}
	else
	{
		g_objSprite.ShowTexture(0, 0, mClientWidth, mClientHeight, colorRT->GetSRView());
	}
	ShowRT();
	SwapChainPtr->Flip();
	
}
Exemplo n.º 2
0
void DeferredLightSample::DrawScene()
{
	SwapChainPtr->Begin();

	ID3D11RenderTargetView* pRTV = SwapChainPtr->GetRenderTargetView();
	ID3D11DepthStencilView*   pDSV = SwapChainPtr->GetDepthStencilView();

	// Fill the G-Buffer
	ID3D11RenderTargetView* pGBufRTV[] = { colorRT->GetRTView(), normalRT->GetRTView(), depthRT->GetRTView() };
	m_deviceContext->OMSetRenderTargets(3, pGBufRTV, pDSV);

	float clearColor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
	float clearColor1[4] = { 0.1921568627450980392156862745098f, 0.30196078431372549019607843137255f, 0.47450980392156862745098039215686f, 1.0f };


	//m_deviceContext->ClearRenderTargetView(pGBufRTV[0], clearColor);
	//m_deviceContext->ClearRenderTargetView(pGBufRTV[1], clearColor);
	//m_deviceContext->ClearRenderTargetView(pGBufRTV[2], clearColor);
	ClearGBuffer();
	RenderScene();
	DrawLights(mTimer.TotalTime());


	lightRTEx->Begin();
	finalCombineEffect->PSSetShaderResources(TU_DIFFUSE, colorRT->GetSRView());
	finalCombineEffect->PSSetShaderResources(TU_CUBE, lightRT->GetSRView());
	ID3D11SamplerState* LinearClamp = g_objStates.LinearClamp();
	m_deviceContext->PSSetSamplers(TU_DIFFUSE, 1, &LinearClamp);
	m_deviceContext->PSSetSamplers(TU_CUBE, 1, &LinearClamp);
	finalCombineEffect->Apply();

	m_deviceContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	FLOAT BlendFactor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };// 0xFFFFFFFF
	m_deviceContext->OMSetBlendState(g_objStates.Opaque(), BlendFactor, 0xFFFFFFFF);
	m_deviceContext->RSSetState(g_objStates.CullCounterClockwise());
	TurnZBufferOff();
	m_deviceContext->Draw(3, 0);

	lightRTEx->End();

	SwapChainPtr->Begin();
	int halfWidth = mClientWidth / 2;
	int halfHeight = mClientHeight / 2;
	TurnZBufferOff();
	g_objSprite.SetAlphaBlend(false);
	g_objSprite.ShowTexture(0, 0, halfWidth, halfHeight, colorRT->GetSRView());
	g_objSprite.ShowTexture(0, halfHeight, halfWidth, mClientHeight, normalRT->GetSRView());
	g_objSprite.ShowTexture(halfWidth, 0, mClientWidth, halfHeight, lightRT->GetSRView());
	g_objSprite.ShowTexture(halfWidth, halfHeight, mClientWidth, mClientHeight, lightRTEx->GetSRView());

	if (m_fxaaEnabled)
	{
		MaterialPtr pFXAAShader = g_objMaterial.GetShader("HLSL\\FXAA.hlsl");
		m_deviceContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
		float frameWidth = (float)mClientWidth;
		float frameHeight = (float)mClientHeight;
		Vector4  vFxaa = Vector4(1.0f / frameWidth, 1.0f / frameHeight, 0.0f, 0.0f);

		pFXAAShader->VSSetConstantBuffers("RCPFrame", &vFxaa);
		pFXAAShader->PSSetConstantBuffers("RCPFrame", &vFxaa);

		pFXAAShader->PSSetShaderResources(TU_DIFFUSE, lightRTEx->GetSRView());
		pFXAAShader->Apply();
		m_deviceContext->Draw(3, 0);
	}
	else
	{
		g_objSprite.ShowTexture(0, 0, mClientWidth, mClientHeight, lightRTEx->GetSRView());
	}


	SwapChainPtr->Flip();
	Test();
}