Graphics: Add RenderMask (WIP)

This commit is contained in:
Jérôme Leclercq
2021-10-29 16:50:38 +02:00
parent 078060cfc9
commit 9e1df33440
11 changed files with 87 additions and 44 deletions

View File

@@ -8,6 +8,11 @@
namespace Nz
{
UInt32 Camera::GetRenderMask() const
{
return m_renderMask;
}
const RenderTarget& Camera::GetRenderTarget()
{
if (!m_renderTarget)

View File

@@ -46,7 +46,7 @@ namespace Nz
m_invalidatedWorldInstances.insert(worldInstance);
}
void ForwardFramePipeline::RegisterInstancedDrawable(WorldInstancePtr worldInstance, const InstancedRenderable* instancedRenderable)
void ForwardFramePipeline::RegisterInstancedDrawable(WorldInstancePtr worldInstance, const InstancedRenderable* instancedRenderable, UInt32 renderMask)
{
m_removedWorldInstances.erase(worldInstance);
@@ -57,6 +57,8 @@ namespace Nz
if (auto it = renderableMap.find(instancedRenderable); it == renderableMap.end())
{
auto& renderableData = renderableMap.emplace(instancedRenderable, RenderableData{}).first->second;
renderableData.renderMask = renderMask;
renderableData.onMaterialInvalidated.Connect(instancedRenderable->OnMaterialInvalidated, [this](InstancedRenderable* instancedRenderable, std::size_t materialIndex, const std::shared_ptr<Material>& newMaterial)
{
if (newMaterial)
@@ -100,8 +102,11 @@ namespace Nz
for (auto&& [viewer, viewerData] : m_viewers)
{
viewerData.rebuildDepthPrepass = true;
viewerData.rebuildForwardPass = true;
if (viewer->GetRenderMask() & renderMask)
{
viewerData.rebuildDepthPrepass = true;
viewerData.rebuildForwardPass = true;
}
}
}
}
@@ -178,6 +183,8 @@ namespace Nz
{
auto& viewerData = data;
UInt32 renderMask = viewer->GetRenderMask();
// Frustum culling
const Matrix4f& viewProjMatrix = viewer->GetViewerInstance().GetViewProjMatrix();
@@ -192,6 +199,9 @@ namespace Nz
for (const auto& [renderable, renderableData] : renderables)
{
if (renderMask & renderableData.renderMask == 0)
continue;
// Get global AABB
BoundingVolumef boundingVolume(renderable->GetAABB());
boundingVolume.Update(worldInstance->GetWorldMatrix());

View File

@@ -61,8 +61,8 @@ namespace Nz
NodeComponent& entityNode = registry.get<NodeComponent>(entity);
const WorldInstancePtr& worldInstance = entityGfx.GetWorldInstance();
for (const auto& renderable : entityGfx.GetRenderables())
m_pipeline->RegisterInstancedDrawable(worldInstance, renderable.get());
for (const auto& renderableEntry : entityGfx.GetRenderables())
m_pipeline->RegisterInstancedDrawable(worldInstance, renderableEntry.renderable.get(), renderableEntry.renderMask);
m_invalidatedWorldNode.insert(entity);
@@ -73,16 +73,16 @@ namespace Nz
m_invalidatedWorldNode.insert(entity);
});
graphicsEntity.onRenderableAttached.Connect(entityGfx.OnRenderableAttached, [this](GraphicsComponent* gfx, const std::shared_ptr<InstancedRenderable>& renderable)
graphicsEntity.onRenderableAttached.Connect(entityGfx.OnRenderableAttached, [this](GraphicsComponent* gfx, const GraphicsComponent::Renderable& renderableEntry)
{
const WorldInstancePtr& worldInstance = gfx->GetWorldInstance();
m_pipeline->RegisterInstancedDrawable(worldInstance, renderable.get());
m_pipeline->RegisterInstancedDrawable(worldInstance, renderableEntry.renderable.get(), renderableEntry.renderMask);
});
graphicsEntity.onRenderableDetach.Connect(entityGfx.OnRenderableDetach, [this](GraphicsComponent* gfx, const std::shared_ptr<InstancedRenderable>& renderable)
graphicsEntity.onRenderableDetach.Connect(entityGfx.OnRenderableDetach, [this](GraphicsComponent* gfx, const GraphicsComponent::Renderable& renderableEntry)
{
const WorldInstancePtr& worldInstance = gfx->GetWorldInstance();
m_pipeline->UnregisterInstancedDrawable(worldInstance, renderable.get());
m_pipeline->UnregisterInstancedDrawable(worldInstance, renderableEntry.renderable.get());
});
});
@@ -107,8 +107,8 @@ namespace Nz
GraphicsComponent& entityGfx = registry.get<GraphicsComponent>(entity);
const WorldInstancePtr& worldInstance = entityGfx.GetWorldInstance();
for (const auto& renderable : entityGfx.GetRenderables())
m_pipeline->UnregisterInstancedDrawable(worldInstance, renderable.get());
for (const auto& renderableEntry : entityGfx.GetRenderables())
m_pipeline->UnregisterInstancedDrawable(worldInstance, renderableEntry.renderable.get());
}
void RenderSystem::OnNodeDestroy(entt::registry& registry, entt::entity entity)