| 270 | } |
| 271 | |
| 272 | void RenderSystem::UpdateDirectionalShadowMaps(const Nz::AbstractViewer& /*viewer*/) |
| 273 | { |
| 274 | if (!m_shadowRT.IsValid()) |
| 275 | m_shadowRT.Create(); |
| 276 | |
| 277 | Nz::SceneData dummySceneData; |
| 278 | dummySceneData.ambientColor = Nz::Color(0, 0, 0); |
| 279 | dummySceneData.background = nullptr; |
| 280 | dummySceneData.viewer = nullptr; //< Depth technique doesn't require any viewer |
| 281 | |
| 282 | for (const Ndk::EntityHandle& light : m_directionalLights) |
| 283 | { |
| 284 | LightComponent& lightComponent = light->GetComponent<LightComponent>(); |
| 285 | NodeComponent& lightNode = light->GetComponent<NodeComponent>(); |
| 286 | |
| 287 | if (!lightComponent.IsShadowCastingEnabled()) |
| 288 | continue; |
| 289 | |
| 290 | Nz::Vector2ui shadowMapSize(lightComponent.GetShadowMap()->GetSize()); |
| 291 | |
| 292 | m_shadowRT.AttachTexture(Nz::AttachmentPoint_Depth, 0, lightComponent.GetShadowMap()); |
| 293 | Nz::Renderer::SetTarget(&m_shadowRT); |
| 294 | Nz::Renderer::SetViewport(Nz::Recti(0, 0, shadowMapSize.x, shadowMapSize.y)); |
| 295 | |
| 296 | Nz::AbstractRenderQueue* renderQueue = m_shadowTechnique.GetRenderQueue(); |
| 297 | renderQueue->Clear(); |
| 298 | |
| 299 | ///TODO: Culling |
| 300 | for (const Ndk::EntityHandle& drawable : m_drawables) |
| 301 | { |
| 302 | GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>(); |
| 303 | |
| 304 | graphicsComponent.AddToRenderQueue(renderQueue); |
| 305 | } |
| 306 | |
| 307 | ///TODO: Cache the matrices in the light? |
| 308 | Nz::Renderer::SetMatrix(Nz::MatrixType_Projection, Nz::Matrix4f::Ortho(0.f, 100.f, 100.f, 0.f, 1.f, 100.f)); |
| 309 | Nz::Renderer::SetMatrix(Nz::MatrixType_View, Nz::Matrix4f::ViewMatrix(lightNode.GetRotation() * Nz::Vector3f::Forward() * 100.f, lightNode.GetRotation())); |
| 310 | |
| 311 | m_shadowTechnique.Clear(dummySceneData); |
| 312 | m_shadowTechnique.Draw(dummySceneData); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | /*! |
| 317 | * \brief Updates the point spot shadow maps |
nothing calls this directly
no test coverage detected