Graphics: Move shadow-mapping related code to LightShadow classes
This commit is contained in:
committed by
Jérôme Leclercq
parent
ec3bc45544
commit
1768f20365
@@ -25,7 +25,7 @@ namespace Nz
|
||||
|
||||
virtual const Color& GetClearColor() const = 0;
|
||||
virtual UInt32 GetRenderMask() const = 0;
|
||||
virtual const RenderTarget& GetRenderTarget() = 0;
|
||||
virtual const RenderTarget& GetRenderTarget() const = 0;
|
||||
virtual ViewerInstance& GetViewerInstance() = 0;
|
||||
virtual const ViewerInstance& GetViewerInstance() const = 0;
|
||||
virtual const Recti& GetViewport() const = 0;
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Nz
|
||||
inline DegreeAnglef GetFOV() const;
|
||||
UInt32 GetRenderMask() const override;
|
||||
inline Int32 GetRenderOrder() const;
|
||||
const RenderTarget& GetRenderTarget() override;
|
||||
const RenderTarget& GetRenderTarget() const;
|
||||
inline const Vector2f& GetSize() const;
|
||||
inline const Rectf& GetTargetRegion() const;
|
||||
ViewerInstance& GetViewerInstance() override;
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Nz
|
||||
void Prepare(RenderFrame& renderFrame, const Frustumf& frustum, const std::vector<FramePipelinePass::VisibleRenderable>& visibleRenderables, std::size_t visibilityHash);
|
||||
|
||||
void RegisterMaterialInstance(const MaterialInstance& materialInstance);
|
||||
FramePass& RegisterToFrameGraph(FrameGraph& frameGraph, std::size_t depthBufferIndex);
|
||||
FramePass& RegisterToFrameGraph(FrameGraph& frameGraph, std::size_t outputAttachment);
|
||||
|
||||
void UnregisterMaterialInstance(const MaterialInstance& materialInstance);
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ namespace Nz
|
||||
|
||||
void FillLightData(void* data) const override;
|
||||
|
||||
std::unique_ptr<LightShadowData> InstanciateShadowData(FramePipeline& pipeline, ElementRendererRegistry& elementRegistry) const override;
|
||||
|
||||
inline float GetAmbientFactor() const;
|
||||
inline float GetDiffuseFactor() const;
|
||||
inline Color GetColor() const;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <Nazara/Graphics/FramePipeline.hpp>
|
||||
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||
#include <Nazara/Graphics/Light.hpp>
|
||||
#include <Nazara/Graphics/LightShadowData.hpp>
|
||||
#include <Nazara/Graphics/MaterialPass.hpp>
|
||||
#include <Nazara/Graphics/RenderElement.hpp>
|
||||
#include <Nazara/Graphics/RenderQueue.hpp>
|
||||
@@ -44,7 +45,13 @@ namespace Nz
|
||||
ForwardFramePipeline(ForwardFramePipeline&&) = delete;
|
||||
~ForwardFramePipeline();
|
||||
|
||||
std::size_t RegisterLight(std::shared_ptr<Light> light, UInt32 renderMask) override;
|
||||
const std::vector<FramePipelinePass::VisibleRenderable>& FrustumCull(const Frustumf& frustum, UInt32 mask, std::size_t& visibilityHash) const override;
|
||||
|
||||
void ForEachRegisteredMaterialInstance(FunctionRef<void(const MaterialInstance& materialInstance)> callback) override;
|
||||
|
||||
void QueueTransfer(TransferInterface* transfer) override;
|
||||
|
||||
std::size_t RegisterLight(const Light* light, UInt32 renderMask) override;
|
||||
std::size_t RegisterRenderable(std::size_t worldInstanceIndex, std::size_t skeletonInstanceIndex, const InstancedRenderable* instancedRenderable, UInt32 renderMask, const Recti& scissorBox) override;
|
||||
std::size_t RegisterSkeleton(SkeletonInstancePtr skeletonInstance) override;
|
||||
std::size_t RegisterViewer(AbstractViewer* viewerInstance, Int32 renderOrder) override;
|
||||
@@ -79,14 +86,11 @@ namespace Nz
|
||||
|
||||
struct LightData
|
||||
{
|
||||
std::shared_ptr<Light> light;
|
||||
std::size_t shadowMapAttachmentIndex;
|
||||
std::unique_ptr<Camera> camera;
|
||||
std::unique_ptr<DepthPipelinePass> pass;
|
||||
std::unique_ptr<LightShadowData> shadowData;
|
||||
const Light* light;
|
||||
UInt32 renderMask;
|
||||
|
||||
NazaraSlot(Light, OnLightDataInvalided, onLightInvalidated);
|
||||
NazaraSlot(Light, OnLightTransformInvalided, onLightTransformInvalidated);
|
||||
NazaraSlot(Light, OnLightShadowCastingChanged, onLightShadowCastingChanged);
|
||||
};
|
||||
|
||||
@@ -150,7 +154,7 @@ namespace Nz
|
||||
std::unordered_map<const RenderTarget*, RenderTargetData> m_renderTargets;
|
||||
std::unordered_map<MaterialInstance*, MaterialInstanceData> m_materialInstances;
|
||||
std::vector<ElementRenderer::RenderStates> m_renderStates;
|
||||
std::vector<FramePipelinePass::VisibleRenderable> m_visibleRenderables;
|
||||
mutable std::vector<FramePipelinePass::VisibleRenderable> m_visibleRenderables;
|
||||
std::vector<std::size_t> m_visibleLights;
|
||||
robin_hood::unordered_set<TransferInterface*> m_transferSet;
|
||||
BakedFrameGraph m_bakedFrameGraph;
|
||||
@@ -159,7 +163,7 @@ namespace Nz
|
||||
Bitset<UInt64> m_removedViewerInstances;
|
||||
Bitset<UInt64> m_removedWorldInstances;
|
||||
ElementRendererRegistry& m_elementRegistry;
|
||||
MemoryPool<RenderableData> m_renderablePool;
|
||||
mutable MemoryPool<RenderableData> m_renderablePool; //< FIXME: has to be mutable because MemoryPool has no const_iterator
|
||||
MemoryPool<LightData> m_lightPool;
|
||||
MemoryPool<SkeletonInstanceData> m_skeletonInstances;
|
||||
MemoryPool<ViewerData> m_viewerPool;
|
||||
|
||||
@@ -9,10 +9,12 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/FramePipelinePass.hpp>
|
||||
#include <Nazara/Graphics/RenderElement.hpp>
|
||||
#include <Nazara/Graphics/SkeletonInstance.hpp>
|
||||
#include <Nazara/Graphics/WorldInstance.hpp>
|
||||
#include <Nazara/Renderer/DebugDrawer.hpp>
|
||||
#include <Nazara/Utils/FunctionRef.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@@ -21,6 +23,7 @@ namespace Nz
|
||||
class AbstractViewer;
|
||||
class InstancedRenderable;
|
||||
class Light;
|
||||
class MaterialInstance;
|
||||
class RenderFrame;
|
||||
|
||||
class NAZARA_GRAPHICS_API FramePipeline
|
||||
@@ -31,9 +34,16 @@ namespace Nz
|
||||
FramePipeline(FramePipeline&&) noexcept = default;
|
||||
virtual ~FramePipeline();
|
||||
|
||||
// TODO: Move RenderQueue handling to proper classes (allowing to reuse them)
|
||||
virtual const std::vector<FramePipelinePass::VisibleRenderable>& FrustumCull(const Frustumf& frustum, UInt32 mask, std::size_t& visibilityHash) const = 0;
|
||||
|
||||
virtual void ForEachRegisteredMaterialInstance(FunctionRef<void(const MaterialInstance& materialInstance)> callback) = 0;
|
||||
|
||||
inline DebugDrawer& GetDebugDrawer();
|
||||
|
||||
virtual std::size_t RegisterLight(std::shared_ptr<Light> light, UInt32 renderMask) = 0;
|
||||
virtual void QueueTransfer(TransferInterface* transfer) = 0;
|
||||
|
||||
virtual std::size_t RegisterLight(const Light* light, UInt32 renderMask) = 0;
|
||||
virtual std::size_t RegisterRenderable(std::size_t worldInstanceIndex, std::size_t skeletonInstanceIndex, const InstancedRenderable* instancedRenderable, UInt32 renderMask, const Recti& scissorBox) = 0;
|
||||
virtual std::size_t RegisterSkeleton(SkeletonInstancePtr skeletonInstance) = 0;
|
||||
virtual std::size_t RegisterViewer(AbstractViewer* viewerInstance, Int32 renderOrder) = 0;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/LightShadowData.hpp>
|
||||
#include <Nazara/Math/BoundingVolume.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
@@ -19,6 +20,8 @@
|
||||
namespace Nz
|
||||
{
|
||||
class CommandBufferBuilder;
|
||||
class ElementRendererRegistry;
|
||||
class FramePipeline;
|
||||
class RenderBuffer;
|
||||
class RenderFrame;
|
||||
class Texture;
|
||||
@@ -42,6 +45,8 @@ namespace Nz
|
||||
inline PixelFormat GetShadowMapFormat() const;
|
||||
inline UInt32 GetShadowMapSize() const;
|
||||
|
||||
virtual std::unique_ptr<LightShadowData> InstanciateShadowData(FramePipeline& pipeline, ElementRendererRegistry& elementRegistry) const = 0;
|
||||
|
||||
inline bool IsShadowCaster() const;
|
||||
|
||||
inline void UpdateShadowMapFormat(PixelFormat format);
|
||||
|
||||
49
include/Nazara/Graphics/LightShadowData.hpp
Normal file
49
include/Nazara/Graphics/LightShadowData.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GRAPHICS_LIGHTSHADOWDATA_HPP
|
||||
#define NAZARA_GRAPHICS_LIGHTSHADOWDATA_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class BakedFrameGraph;
|
||||
class FrameGraph;
|
||||
class FramePass;
|
||||
class MaterialInstance;
|
||||
class RenderFrame;
|
||||
class Texture;
|
||||
|
||||
class NAZARA_GRAPHICS_API LightShadowData
|
||||
{
|
||||
public:
|
||||
LightShadowData() = default;
|
||||
LightShadowData(const LightShadowData&) = delete;
|
||||
LightShadowData(LightShadowData&&) = delete;
|
||||
virtual ~LightShadowData();
|
||||
|
||||
virtual void PrepareRendering(RenderFrame& renderFrame) = 0;
|
||||
|
||||
virtual void RegisterMaterialInstance(const MaterialInstance& matInstance) = 0;
|
||||
virtual void RegisterPassInputs(FramePass& pass) = 0;
|
||||
virtual void RegisterToFrameGraph(FrameGraph& frameGraph) = 0;
|
||||
|
||||
virtual const Texture* RetrieveLightShadowmap(const BakedFrameGraph& bakedGraph) const = 0;
|
||||
|
||||
virtual void UnregisterMaterialInstance(const MaterialInstance& matInstance) = 0;
|
||||
|
||||
LightShadowData& operator=(const LightShadowData&) = delete;
|
||||
LightShadowData& operator=(LightShadowData&&) = delete;
|
||||
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/LightShadowData.inl>
|
||||
|
||||
#endif // NAZARA_GRAPHICS_LIGHTSHADOWDATA_HPP
|
||||
12
include/Nazara/Graphics/LightShadowData.inl
Normal file
12
include/Nazara/Graphics/LightShadowData.inl
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/LightShadowData.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
@@ -54,7 +54,6 @@ namespace Nz
|
||||
|
||||
std::shared_ptr<GraphicalMesh> m_graphicalMesh;
|
||||
std::vector<SubMeshData> m_submeshes;
|
||||
Recti m_scissorBox;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace Nz
|
||||
|
||||
void FillLightData(void* data) const override;
|
||||
|
||||
std::unique_ptr<LightShadowData> InstanciateShadowData(FramePipeline& pipeline, ElementRendererRegistry& elementRegistry) const override;
|
||||
|
||||
inline float GetAmbientFactor() const;
|
||||
inline float GetDiffuseFactor() const;
|
||||
inline Color GetColor() const;
|
||||
|
||||
46
include/Nazara/Graphics/ShadowViewer.hpp
Normal file
46
include/Nazara/Graphics/ShadowViewer.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GRAPHICS_SHADOWVIEWER_HPP
|
||||
#define NAZARA_GRAPHICS_SHADOWVIEWER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||
#include <Nazara/Graphics/ViewerInstance.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_GRAPHICS_API ShadowViewer : public AbstractViewer
|
||||
{
|
||||
public:
|
||||
inline ShadowViewer(const Recti& viewport, UInt32 renderMask);
|
||||
ShadowViewer(const ShadowViewer&) = delete;
|
||||
ShadowViewer(ShadowViewer&&) = delete;
|
||||
~ShadowViewer() = default;
|
||||
|
||||
const Color& GetClearColor() const override;
|
||||
UInt32 GetRenderMask() const override;
|
||||
const RenderTarget& GetRenderTarget() const override;
|
||||
ViewerInstance& GetViewerInstance() override;
|
||||
const ViewerInstance& GetViewerInstance() const override;
|
||||
const Recti& GetViewport() const override;
|
||||
|
||||
inline void UpdateRenderMask(UInt32 renderMask);
|
||||
inline void UpdateViewport(const Recti& viewport);
|
||||
|
||||
ShadowViewer& operator=(const ShadowViewer&) = delete;
|
||||
ShadowViewer& operator=(ShadowViewer&&) = delete;
|
||||
|
||||
private:
|
||||
Recti m_viewport;
|
||||
ViewerInstance m_viewerInstance;
|
||||
UInt32 m_renderMask;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/ShadowViewer.inl>
|
||||
|
||||
#endif // NAZARA_GRAPHICS_SHADOWVIEWER_HPP
|
||||
28
include/Nazara/Graphics/ShadowViewer.inl
Normal file
28
include/Nazara/Graphics/ShadowViewer.inl
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/ShadowViewer.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline ShadowViewer::ShadowViewer(const Recti& viewport, UInt32 renderMask) :
|
||||
m_renderMask(renderMask)
|
||||
{
|
||||
UpdateViewport(viewport);
|
||||
}
|
||||
|
||||
inline void ShadowViewer::UpdateRenderMask(UInt32 renderMask)
|
||||
{
|
||||
m_renderMask = renderMask;
|
||||
}
|
||||
|
||||
inline void ShadowViewer::UpdateViewport(const Recti& viewport)
|
||||
{
|
||||
m_viewport = viewport;
|
||||
m_viewerInstance.UpdateTargetSize({ float(m_viewport.width), float(m_viewport.height) });
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
@@ -38,6 +38,8 @@ namespace Nz
|
||||
inline const Quaternionf& GetRotation() const;
|
||||
inline float GetRadius() const;
|
||||
|
||||
std::unique_ptr<LightShadowData> InstanciateShadowData(FramePipeline& pipeline, ElementRendererRegistry& elementRegistry) const override;
|
||||
|
||||
inline void UpdateAmbientFactor(float factor);
|
||||
inline void UpdateColor(Color color);
|
||||
inline void UpdateDiffuseFactor(float factor);
|
||||
|
||||
56
include/Nazara/Graphics/SpotLightShadowData.hpp
Normal file
56
include/Nazara/Graphics/SpotLightShadowData.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GRAPHICS_SPOTLIGHTSHADOWDATA_HPP
|
||||
#define NAZARA_GRAPHICS_SPOTLIGHTSHADOWDATA_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/DepthPipelinePass.hpp>
|
||||
#include <Nazara/Graphics/Light.hpp>
|
||||
#include <Nazara/Graphics/LightShadowData.hpp>
|
||||
#include <Nazara/Graphics/ShadowViewer.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class FramePipeline;
|
||||
class SpotLight;
|
||||
|
||||
class NAZARA_GRAPHICS_API SpotLightShadowData : public LightShadowData
|
||||
{
|
||||
public:
|
||||
SpotLightShadowData(FramePipeline& pipeline, ElementRendererRegistry& elementRegistry, const SpotLight& light);
|
||||
SpotLightShadowData(const SpotLightShadowData&) = delete;
|
||||
SpotLightShadowData(SpotLightShadowData&&) = delete;
|
||||
~SpotLightShadowData() = default;
|
||||
|
||||
void PrepareRendering(RenderFrame& renderFrame) override;
|
||||
|
||||
void RegisterMaterialInstance(const MaterialInstance& matInstance) override;
|
||||
void RegisterPassInputs(FramePass& pass) override;
|
||||
void RegisterToFrameGraph(FrameGraph& frameGraph) override;
|
||||
|
||||
const Texture* RetrieveLightShadowmap(const BakedFrameGraph& bakedGraph) const override;
|
||||
|
||||
void UnregisterMaterialInstance(const MaterialInstance& matInstance) override;
|
||||
|
||||
SpotLightShadowData& operator=(const SpotLightShadowData&) = delete;
|
||||
SpotLightShadowData& operator=(SpotLightShadowData&&) = delete;
|
||||
|
||||
private:
|
||||
NazaraSlot(Light, OnLightShadowMapSettingChange, m_onLightShadowMapSettingChange);
|
||||
NazaraSlot(Light, OnLightTransformInvalided, m_onLightTransformInvalidated);
|
||||
|
||||
std::optional<DepthPipelinePass> m_depthPass;
|
||||
std::size_t m_attachmentIndex;
|
||||
FramePipeline& m_pipeline;
|
||||
const SpotLight& m_light;
|
||||
ShadowViewer m_viewer;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/SpotLightShadowData.inl>
|
||||
|
||||
#endif // NAZARA_GRAPHICS_SPOTLIGHTSHADOWDATA_HPP
|
||||
12
include/Nazara/Graphics/SpotLightShadowData.inl
Normal file
12
include/Nazara/Graphics/SpotLightShadowData.inl
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/SpotLightShadowData.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
Reference in New Issue
Block a user