This commit is contained in:
SirLynix
2022-11-19 17:10:27 +01:00
committed by Jérôme Leclercq
parent 4a10c1f8fe
commit e990a320cc
54 changed files with 618 additions and 154 deletions

View File

@@ -30,7 +30,7 @@ namespace Nz
class NAZARA_GRAPHICS_API DepthPipelinePass : public FramePipelinePass
{
public:
DepthPipelinePass(FramePipeline& owner, ElementRendererRegistry& elementRegistry, AbstractViewer* viewer);
DepthPipelinePass(FramePipeline& owner, ElementRendererRegistry& elementRegistry, AbstractViewer* viewer, std::size_t passIndex, std::string passName);
DepthPipelinePass(const DepthPipelinePass&) = delete;
DepthPipelinePass(DepthPipelinePass&&) = delete;
~DepthPipelinePass() = default;
@@ -57,8 +57,9 @@ namespace Nz
NazaraSlot(MaterialInstance, OnMaterialInstanceShaderBindingInvalidated, onMaterialInstanceShaderBindingInvalidated);
};
std::size_t m_depthPassIndex;
std::size_t m_passIndex;
std::size_t m_lastVisibilityHash;
std::string m_passName;
std::vector<std::unique_ptr<ElementRendererData>> m_elementRendererData;
std::vector<ElementRenderer::RenderStates> m_renderStates;
std::vector<RenderElementOwner> m_renderElements;

View File

@@ -11,8 +11,10 @@
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Graphics/PredefinedShaderStructs.hpp>
#include <Nazara/Graphics/RenderElementPool.hpp>
#include <Nazara/Renderer/RenderBufferView.hpp>
#include <array>
#include <memory>
#include <optional>
#include <vector>
@@ -43,6 +45,14 @@ namespace Nz
struct RenderStates
{
RenderStates()
{
shadowMaps2D.fill(nullptr);
shadowMapsCube.fill(nullptr);
}
std::array<const Texture*, PredefinedLightData::MaxLightCount> shadowMaps2D;
std::array<const Texture*, PredefinedLightData::MaxLightCount> shadowMapsCube;
RenderBufferView lightData;
};
};

View File

@@ -95,6 +95,8 @@ namespace Nz
InstanceDataUbo,
LightDataUbo,
OverlayTexture,
Shadowmap2D,
ShadowmapCube,
SkeletalDataUbo,
ViewerDataUbo,

View File

@@ -50,6 +50,9 @@ namespace Nz
std::size_t RegisterViewer(AbstractViewer* viewerInstance, Int32 renderOrder) override;
std::size_t RegisterWorldInstance(WorldInstancePtr worldInstance) override;
const Light* RetrieveLight(std::size_t lightIndex) const override;
const Texture* RetrieveLightShadowmap(std::size_t lightIndex) const override;
void Render(RenderFrame& renderFrame) override;
void UnregisterLight(std::size_t lightIndex) override;
@@ -147,7 +150,7 @@ namespace Nz
std::unordered_map<MaterialInstance*, MaterialInstanceData> m_materialInstances;
std::vector<ElementRenderer::RenderStates> m_renderStates;
std::vector<FramePipelinePass::VisibleRenderable> m_visibleRenderables;
std::vector<const Light*> m_visibleLights;
std::vector<std::size_t> m_visibleLights;
robin_hood::unordered_set<TransferInterface*> m_transferSet;
BakedFrameGraph m_bakedFrameGraph;
Bitset<UInt64> m_shadowCastingLights;

View File

@@ -41,7 +41,7 @@ namespace Nz
inline void InvalidateCommandBuffers();
inline void InvalidateElements();
void Prepare(RenderFrame& renderFrame, const Frustumf& frustum, const std::vector<FramePipelinePass::VisibleRenderable>& visibleRenderables, const std::vector<const Light*>& visibleLights, std::size_t visibilityHash);
void Prepare(RenderFrame& renderFrame, const Frustumf& frustum, const std::vector<FramePipelinePass::VisibleRenderable>& visibleRenderables, const std::vector<std::size_t>& visibleLights, std::size_t visibilityHash);
void RegisterMaterialInstance(const MaterialInstance& material);
FramePass& RegisterToFrameGraph(FrameGraph& frameGraph, std::size_t colorBufferIndex, std::size_t depthBufferIndex, bool hasDepthPrepass);
@@ -76,11 +76,25 @@ namespace Nz
UploadPool::Allocation* allocation = nullptr;
};
struct LightPerElementData
{
RenderBufferView lightUniformBuffer;
std::array<const Texture*, MaxLightCountPerDraw> shadowMaps;
std::size_t lightCount;
};
struct LightUboPool
{
std::vector<std::shared_ptr<RenderBuffer>> lightUboBuffers;
};
struct RenderableLight
{
const Light* light;
std::size_t lightIndex;
float contributionScore;
};
std::size_t m_forwardPassIndex;
std::size_t m_lastVisibilityHash;
std::shared_ptr<LightUboPool> m_lightUboPool;
@@ -88,10 +102,10 @@ namespace Nz
std::vector<ElementRenderer::RenderStates> m_renderStates;
std::vector<RenderElementOwner> m_renderElements;
std::unordered_map<const MaterialInstance*, MaterialPassEntry> m_materialInstances;
std::unordered_map<const RenderElement*, RenderBufferView> m_lightPerRenderElement;
std::unordered_map<const RenderElement*, LightPerElementData> m_lightPerRenderElement;
std::unordered_map<LightKey, RenderBufferView, LightKeyHasher> m_lightBufferPerLights;
std::vector<LightDataUbo> m_lightDataBuffers;
std::vector<const Light*> m_renderableLights;
std::vector<RenderableLight> m_renderableLights;
RenderQueue<const RenderElement*> m_renderQueue;
RenderQueueRegistry m_renderQueueRegistry;
AbstractViewer* m_viewer;

View File

@@ -39,6 +39,9 @@ namespace Nz
virtual std::size_t RegisterViewer(AbstractViewer* viewerInstance, Int32 renderOrder) = 0;
virtual std::size_t RegisterWorldInstance(WorldInstancePtr worldInstance) = 0;
virtual const Light* RetrieveLight(std::size_t lightIndex) const = 0;
virtual const Texture* RetrieveLightShadowmap(std::size_t lightIndex) const = 0;
virtual void Render(RenderFrame& renderFrame) = 0;
virtual void UnregisterLight(std::size_t lightIndex) = 0;

View File

@@ -74,6 +74,7 @@ namespace Nz
struct DefaultTextures
{
std::array<std::shared_ptr<Texture>, ImageTypeCount> depthTextures;
std::array<std::shared_ptr<Texture>, ImageTypeCount> whiteTextures;
};

View File

@@ -24,6 +24,7 @@ namespace Nz
std::size_t parameter2;
std::size_t parameter3;
std::size_t shadowMappingFlag;
std::size_t viewProjMatrix;
};
std::size_t lightsOffset;

View File

@@ -55,9 +55,11 @@ namespace Nz
private:
inline void UpdateBoundingVolume();
inline void UpdateViewProjMatrix();
Color m_color;
Quaternionf m_rotation;
Matrix4f m_viewProjMatrix;
RadianAnglef m_innerAngle;
RadianAnglef m_outerAngle;
Vector3f m_direction;

View File

@@ -97,8 +97,6 @@ namespace Nz
{
m_innerAngle = innerAngle;
m_innerAngleCos = m_innerAngle.GetCos();
UpdateBoundingVolume();
}
inline void SpotLight::UpdateOuterAngle(RadianAnglef outerAngle)
@@ -108,6 +106,7 @@ namespace Nz
m_outerAngleTan = m_outerAngle.GetTan();
UpdateBoundingVolume();
UpdateViewProjMatrix();
}
inline void SpotLight::UpdatePosition(const Vector3f& position)
@@ -115,6 +114,7 @@ namespace Nz
m_position = position;
UpdateBoundingVolume();
UpdateViewProjMatrix();
}
inline void SpotLight::UpdateRadius(float radius)
@@ -123,6 +123,7 @@ namespace Nz
m_invRadius = 1.f / m_radius;
UpdateBoundingVolume();
UpdateViewProjMatrix();
}
inline void SpotLight::UpdateRotation(const Quaternionf& rotation)
@@ -131,6 +132,7 @@ namespace Nz
m_direction = rotation * Vector3f::Forward();
UpdateBoundingVolume();
UpdateViewProjMatrix();
}
inline void SpotLight::UpdateBoundingVolume()
@@ -158,6 +160,19 @@ namespace Nz
Light::UpdateBoundingVolume(boundingVolume); //< will trigger OnLightDataInvalided
}
inline void SpotLight::UpdateViewProjMatrix()
{
Matrix4f biasMatrix(0.5f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.0f, 1.0f);
Matrix4f projection = Matrix4f::Perspective(m_outerAngle * 2.f, 1.f, 1.f, m_radius);
Matrix4f view = Matrix4f::TransformInverse(m_position, m_rotation);
m_viewProjMatrix = view * projection * biasMatrix;
}
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -33,6 +33,7 @@ namespace Nz
private:
std::vector<ShaderBinding::Binding> m_bindingCache;
std::vector<ShaderBinding::TextureBinding> m_textureBindingCache;
RenderElementPool<RenderSubmesh> m_submeshPool;
};