Graphics: Add depth render technique/queue

Former-commit-id: 711306ee5f84a9579068ce23240dc105cec15cde
This commit is contained in:
Lynix
2015-06-17 14:32:05 +02:00
parent 39779c059d
commit ebbaaf7ff2
10 changed files with 890 additions and 14 deletions

View File

@@ -7,6 +7,7 @@
#ifndef NDK_SYSTEMS_RENDERSYSTEM_HPP
#define NDK_SYSTEMS_RENDERSYSTEM_HPP
#include <Nazara/Graphics/DepthRenderTechnique.hpp>
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
#include <Nazara/Renderer/RenderTexture.hpp>
#include <NDK/EntityList.hpp>
@@ -37,8 +38,8 @@ namespace Ndk
EntityList m_cameras;
EntityList m_drawables;
EntityList m_lights;
NzDepthRenderTechnique m_shadowTechnique;
NzForwardRenderTechnique m_renderTechnique;
NzForwardRenderTechnique m_shadowTechnique;
NzRenderTexture m_shadowRT;
};
}

View File

@@ -100,24 +100,17 @@ namespace Ndk
if (!lightComponent.IsShadowCastingEnabled() || lightComponent.GetLightType() != nzLightType_Spot)
continue;
/// HACKY
NzCamera lightPOV;
lightPOV.SetPosition(lightNode.GetPosition());
lightPOV.SetFOV(lightComponent.GetOuterAngle());
lightPOV.SetRotation(lightNode.GetRotation());
lightPOV.SetZFar(1000.f);
lightPOV.SetTarget(&m_shadowRT);
NzVector2ui shadowMapSize(lightComponent.GetShadowMap()->GetSize());
m_shadowRT.AttachTexture(nzAttachmentPoint_Depth, 0, lightComponent.GetShadowMap());
NzRenderer::SetMatrix(nzMatrixType_Projection, lightPOV.GetProjectionMatrix());
NzRenderer::SetMatrix(nzMatrixType_View, lightPOV.GetViewMatrix());
///TODO: Cache the matrices in the light?
NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(lightComponent.GetOuterAngle(), 1.f, 1.f, 1000.f));
NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::ViewMatrix(lightNode.GetPosition(), lightNode.GetRotation()));
NzRenderer::SetTarget(&m_shadowRT);
NzRenderer::SetViewport(NzRecti(0, 0, shadowMapSize.x, shadowMapSize.y));
NzAbstractRenderQueue* renderQueue = m_renderTechnique.GetRenderQueue();
NzAbstractRenderQueue* renderQueue = m_shadowTechnique.GetRenderQueue();
renderQueue->Clear();
for (const Ndk::EntityHandle& drawable : m_drawables)
@@ -131,9 +124,9 @@ namespace Ndk
NzSceneData sceneData;
sceneData.ambientColor = NzColor(0, 0, 0);
sceneData.background = nullptr;
sceneData.viewer = &lightPOV;
sceneData.viewer = nullptr; //< Depth technique doesn't require any viewer
m_renderTechnique.Draw(sceneData);
m_shadowTechnique.Draw(sceneData);
}
}