Example #1
0
void CDirectionalLight::SetBlackAndWhiteMap(CRenderManager &RenderManager, bool Blurred)
{
	CDynamicTexture* l_Texture = m_BlackAndWhiteMap;
	if (Blurred)
		l_Texture = m_BlackAndWhiteBlurredMap;

	if (l_Texture == NULL)
	{
		assert(false);
		return;
	}

	Vect3f l_ShadowMapFrameDisplacement = v3fZERO;

	CGameObject* l_PlayerGameObject = CEngine::GetSingleton().GetGameObjectManager()->GetPlayer();
	CRenderableObject* l_Player = l_PlayerGameObject->GetRenderableObject();
	Vect3f l_PlayerPos = l_Player->GetPosition();
	SetPosition(l_PlayerPos + m_PlayerOffset);

	unsigned int l_ShadowMapWidth = l_Texture->GetWidth();
	unsigned int l_ShadowMapHeight = l_Texture->GetHeight();

	ID3D11RenderTargetView *l_RenderTargetViews[1];
	l_RenderTargetViews[0] = l_Texture->GetRenderTargetView();
	D3D11_VIEWPORT m_viewport;
	m_viewport.Width = (float)l_ShadowMapWidth;
	m_viewport.Height = (float)l_ShadowMapHeight;
	m_viewport.MinDepth = 0.0f;
	m_viewport.MaxDepth = 1.0f;
	m_viewport.TopLeftX = 0.0f;
	m_viewport.TopLeftY = 0.0f;
	RenderManager.GetContextManager()->GetDeviceContext()->RSSetViewports(1, &m_viewport);
	RenderManager.GetContextManager()->SetRenderTargets(1, l_RenderTargetViews, l_Texture->GetDepthStencilView());
}
void CDeferredShadingSceneRendererCommand::SecondPass(CRenderManager &RenderManager)
{
	RenderManager.GetContextManager()->EnableDeferredShadingBlendState();
	RenderManager.GetContextManager()->SetRasterizerState(CContextManager::RS_CULL_FRONT); //Back(far) faces only

	D3D11_DEPTH_STENCIL_DESC depthstencil_desc;
	depthstencil_desc.DepthEnable = FALSE;
	depthstencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
	depthstencil_desc.DepthFunc = D3D11_COMPARISON_LESS;

	depthstencil_desc.StencilEnable = TRUE;
	depthstencil_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
	depthstencil_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;

	depthstencil_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
	depthstencil_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
	depthstencil_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_INVERT;
	depthstencil_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;

	depthstencil_desc.BackFace.StencilFunc = D3D11_COMPARISON_NOT_EQUAL;
	depthstencil_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
	depthstencil_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
	depthstencil_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;

	//Stencil function is 'Equal' (Stencil ref = zero)

	HRESULT l_Result = CEngine::GetSingleton().GetRenderManager()->GetContextManager()->GetDevice()->CreateDepthStencilState(&depthstencil_desc, &m_DepthStencilState);

	RenderManager.GetContextManager()->UnsetRenderTargets();

	UINT l_StencilRef = 0;
	RenderManager.GetContextManager()->GetDeviceContext()->OMSetDepthStencilState(m_DepthStencilState, l_StencilRef);
	//Always clears Stencil to zero
}
void CDeferredShadingSceneRendererCommand::ExecuteDeferredShading(CRenderManager &RenderManager)
{
	CContextManager* l_ContextManager = RenderManager.GetContextManager();
	l_ContextManager->EnableDeferredShadingBlendState();

	CLightManager* l_LightManager = CEngine::GetSingleton().GetLightManager();
	std::vector<CLight*> l_Lights = l_LightManager->GetResourcesVector();
	size_t l_Size = l_Lights.size();

	int l_Width = l_ContextManager->GetFrameBufferWidth();
	int l_Height = l_ContextManager->GetFrameBufferHeight();

	ActivateTextures();

	for (size_t i = 0; i < l_Size; ++i)
	{
		if (l_Lights[i]->GetActive())
		{
			CEngine::GetSingleton().GetEffectManager()->SetLightConstants(0, l_Lights[i]);
			m_RenderableObjectTechnique->GetEffectTechnique()->SetConstantBuffer(1, &CEffectManager::m_LightEffectParameters);
			RenderManager.DrawScreenQuad(m_RenderableObjectTechnique->GetEffectTechnique(), NULL, 0, 0, 1.0f, 1.0f, CColor(v4fZERO));
		}
	}

	CEngine::GetSingleton().GetRenderManager()->GetContextManager()->DisableAlphaBlendState();
}
void CDeferredShadingSceneRendererCommand::FirstPast(CRenderManager &RenderManager)
{
	CContextManager* l_ContextManager = RenderManager.GetContextManager();
	l_ContextManager->Clear(false, true);
	l_ContextManager->EnableDeferredShadingBlendState();
	l_ContextManager->SetRasterizerState(CContextManager::RS_CULL_BACK); //Front (near) faces only

	D3D11_DEPTH_STENCIL_DESC depthstencil_desc;
	depthstencil_desc.DepthEnable = TRUE;
	depthstencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
	depthstencil_desc.DepthFunc = D3D11_COMPARISON_LESS;

	depthstencil_desc.StencilEnable = TRUE;
	depthstencil_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
	depthstencil_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;

	depthstencil_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
	depthstencil_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INVERT;
	depthstencil_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
	depthstencil_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;

	depthstencil_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
	depthstencil_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_INVERT;
	depthstencil_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
	depthstencil_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
	
	HRESULT l_Result = CEngine::GetSingleton().GetRenderManager()->GetContextManager()->GetDevice()->CreateDepthStencilState(&depthstencil_desc, &m_DepthStencilState);
	UINT l_StencilRef = 0;
	l_ContextManager->UnsetColorRenderTarget();
	l_ContextManager->GetDeviceContext()->OMSetDepthStencilState(m_DepthStencilState, l_StencilRef);
}
void CDeferredShadingSceneRendererCommand::ExecuteDeferredShadingUsingLightVolumes(CRenderManager &RenderManager)
{
	CLightManager* l_LightManager = CEngine::GetSingleton().GetLightManager();
	std::vector<CLight*> l_Lights = l_LightManager->GetResourcesVector();
	size_t l_Size = l_Lights.size();

	int l_Width = RenderManager.GetContextManager()->GetFrameBufferWidth();
	int l_Height = RenderManager.GetContextManager()->GetFrameBufferHeight();

	ActivateTextures();

	for (size_t i = 0; i<l_Size; ++i)
	{
		/*Only 1 light*/
		if (l_Lights[i]->GetActive())
		{
			CEngine::GetSingleton().GetEffectManager()->SetLightConstants(0, l_Lights[i]);
			m_RenderableObjectTechnique->GetEffectTechnique()->SetConstantBuffer(1, &CEffectManager::m_LightEffectParameters);

			if (l_Lights[i]->GetType() != CLight::OMNI) //
			{
				RenderManager.GetContextManager()->SetRasterizerState(CContextManager::RS_SOLID);
				RenderManager.DrawScreenQuad(m_RenderableObjectTechnique->GetEffectTechnique(), NULL, 0, 0, 1.0f, 1.0f, CColor(v4fZERO));
			}
			else
			{
				float l_LightRadius = l_Lights[i]->GetEndRangeAttenuation();
				Mat44f l_Scale;
				l_Scale.SetFromScale(l_LightRadius, l_LightRadius, l_LightRadius);

				Mat44f l_LightTransform = l_Lights[i]->GetTransform();

				RenderManager.GetContextManager()->SetWorldMatrix(l_Scale*l_LightTransform);

				FirstPast(RenderManager);
				CRenderableObjectTechnique* l_Technique  = CEngine::GetSingleton().GetRenderableObjectTechniqueManager()->GetResource("deferred_shading_omnilight_sphere_renderable_object_technique");
				m_SphereFirstPass->Render(&RenderManager, l_Technique);
				SecondPass(RenderManager);
				m_SphereFirstPass->Render(&RenderManager);
			}
		}
	}

	CEngine::GetSingleton().GetRenderManager()->GetContextManager()->DisableAlphaBlendState();
}
void CGenerateBlackAndWhiteMapsSceneRendererCommand::Execute(CRenderManager &RenderManager)
{
	CLightManager* l_LightManager = CEngine::GetSingleton().GetLightManager();
	std::vector<CLight*> l_Lights = l_LightManager->GetResourcesVector();
	size_t l_Size = l_Lights.size();

	ActivateTextures();

	//We are going to render from camera perspective
	//RenderManager.GetContextManager()->SetMatrices(RenderManager.GetCurrentCamera());

	for (size_t i = 0; i<l_Size; ++i)
	{
		if (l_Lights[i]->GetActive() && l_Lights[i]->GetGenerateShadowMap())
		{
			l_Lights[i]->SetBlackAndWhiteMap(RenderManager, false); //Set BlackAndWhiteTexture as rendertarget
			//Doens't change matrix, beacuse we must render from camera perspective

			CEngine::GetSingleton().GetEffectManager()->SetBlackAndWhiteLightConstants(l_Lights[i]);
			RenderManager.DrawScreenQuad(m_RenderableObjectTechnique->GetEffectTechnique(), NULL, 0, 0, 1.0f, 1.0f, CColor(1.0f, 1.0f, 1.0f, 1.0f));

			CMaterial* l_GaussianFilterMaterial = CEngine::GetSingleton().GetMaterialManager()->GetResource("GaussianFilterMaterial");
			CMaterial* l_GuiMaterial = CEngine::GetSingleton().GetMaterialManager()->GetResource("GUIMaterial");

			RenderManager.GetContextManager()->UnsetRenderTargets();
			RenderManager.GetContextManager()->SetDefaultViewPort();

			l_Lights[i]->SetBlackAndWhiteMap(RenderManager, true);
			CPoolRenderableObjectTechnique* l_GaussianFilterPool = CEngine::GetSingleton().GetRenderableObjectTechniqueManager()->GetPoolRenderableObjectTechniques().GetResource("gaussian_filter_pool_renderable_object_technique");
			l_GaussianFilterPool->Apply();

			l_Lights[i]->GetBlackAndWhiteMap()->Activate(0);
			l_GaussianFilterMaterial->Apply();

			RenderManager.DrawScreenQuad(l_GaussianFilterMaterial->GetRenderableObjectTechnique()->GetEffectTechnique(), NULL, 0, 0, 1.0f, 1.0f, CColor(0.0, 0.0, 0.0, 0.0));
		}
	}

	RenderManager.GetContextManager()->UnsetRenderTargets();
	RenderManager.GetContextManager()->SetDefaultViewPort();
}
Example #7
0
void CDirectionalLight::SetShadowMap(CRenderManager &RenderManager)
{
	if (m_ShadowMap == NULL)
	{
		assert(false);
		return;
	}
	Vect3f l_ShadowMapFrameDisplacement = v3fZERO;

	CGameObject* l_PlayerGameObject = CEngine::GetSingleton().GetGameObjectManager()->GetPlayer();
	CRenderableObject* l_Player = l_PlayerGameObject->GetRenderableObject();
	Vect3f l_PlayerPos = l_Player->GetPosition();
	SetPosition(l_PlayerPos + m_PlayerOffset);
	
	m_ViewShadowMap.SetIdentity();
	m_ViewShadowMap.SetFromLookAt(m_Position, m_Position+m_Direction, v3fY);
	
	unsigned int l_ShadowMapWidth=m_ShadowMap->GetWidth();
	unsigned int l_ShadowMapHeight=m_ShadowMap->GetHeight();
	
	m_ProjectionShadowMap.SetFromOrtho(m_OrthoShadowMapSize.x,m_OrthoShadowMapSize.y, 0.1f, m_EndRangeAttenuation);
	
	CEffectManager::m_SceneEffectParameters.m_View=m_ViewShadowMap;
	CEffectManager::m_SceneEffectParameters.m_Projection=m_ProjectionShadowMap;
	
	ID3D11RenderTargetView *l_RenderTargetViews[1];
	l_RenderTargetViews[0]=m_ShadowMap->GetRenderTargetView();
	D3D11_VIEWPORT m_viewport;
	m_viewport.Width=(float)l_ShadowMapWidth;
	m_viewport.Height=(float)l_ShadowMapHeight;
	m_viewport.MinDepth=0.0f;
	m_viewport.MaxDepth=1.0f;
	m_viewport.TopLeftX=0.0f;
	m_viewport.TopLeftY=0.0f;
	RenderManager.GetContextManager()->GetDeviceContext()->RSSetViewports(1, &m_viewport);
	RenderManager.GetContextManager()->SetRenderTargets(1, l_RenderTargetViews, m_ShadowMap->GetDepthStencilView());
}
void CEnableAlphaBlendSceneRendererCommand::Execute(CRenderManager &RenderManager)
{
	RenderManager.GetContextManager()->EnableAlphaBlendState();
}
void CUnsetRenderTargetSceneRendererCommand::Execute(CRenderManager &RenderManager)
{
	RenderManager.GetContextManager()->UnsetRenderTargets();
}