From 529673ebc1b7215db2b016131e226d2890c0d501 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 30 Jun 2015 20:48:46 +0200 Subject: [PATCH] Graphics/Light: Make shadow map format/size parametrable Former-commit-id: 8151d71d58ab760584c0ace1e0686c44bab9d3b2 --- include/Nazara/Graphics/Light.hpp | 7 ++++++ include/Nazara/Graphics/Light.inl | 41 ++++++++++++++++++++++++++++++- src/Nazara/Graphics/Light.cpp | 4 ++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/include/Nazara/Graphics/Light.hpp b/include/Nazara/Graphics/Light.hpp index a473b031d..5d42c0961 100644 --- a/include/Nazara/Graphics/Light.hpp +++ b/include/Nazara/Graphics/Light.hpp @@ -49,6 +49,8 @@ class NAZARA_GRAPHICS_API NzLight : public NzRenderable inline float GetOuterAngleTangent() const; inline float GetRadius() const; inline NzTextureRef GetShadowMap() const; + inline nzPixelFormat GetShadowMapFormat() const; + inline const NzVector2ui& GetShadowMapSize() const; inline bool IsShadowCastingEnabled() const; @@ -60,6 +62,8 @@ class NAZARA_GRAPHICS_API NzLight : public NzRenderable inline void SetLightType(nzLightType type); inline void SetOuterAngle(float outerAngle); inline void SetRadius(float radius); + inline void SetShadowMapFormat(nzPixelFormat shadowFormat); + inline void SetShadowMapSize(const NzVector2ui& size); void UpdateBoundingVolume(const NzMatrix4f& transformMatrix) override; @@ -68,10 +72,13 @@ class NAZARA_GRAPHICS_API NzLight : public NzRenderable private: void MakeBoundingVolume() const override; + inline void InvalidateShadowMap(); void UpdateShadowMap() const; nzLightType m_type; + nzPixelFormat m_shadowMapFormat; NzColor m_color; + NzVector2ui m_shadowMapSize; mutable NzTextureRef m_shadowMap; bool m_shadowCastingEnabled; mutable bool m_shadowMapUpdated; diff --git a/include/Nazara/Graphics/Light.inl b/include/Nazara/Graphics/Light.inl index f0f7600ff..b5408ce43 100644 --- a/include/Nazara/Graphics/Light.inl +++ b/include/Nazara/Graphics/Light.inl @@ -8,7 +8,9 @@ inline NzLight::NzLight(const NzLight& light) : NzRenderable(light), m_type(light.m_type), +m_shadowMapFormat(light.m_shadowMapFormat), m_color(light.m_color), +m_shadowMapSize(light.m_shadowMapSize), m_shadowCastingEnabled(light.m_shadowCastingEnabled), m_shadowMapUpdated(false), m_ambientFactor(light.m_ambientFactor), @@ -96,6 +98,16 @@ inline NzTextureRef NzLight::GetShadowMap() const return m_shadowMap; } +inline nzPixelFormat NzLight::GetShadowMapFormat() const +{ + return m_shadowMapFormat; +} + +inline const NzVector2ui& NzLight::GetShadowMapSize() const +{ + return m_shadowMapSize; +} + inline bool NzLight::IsShadowCastingEnabled() const { return m_shadowCastingEnabled; @@ -130,6 +142,8 @@ inline void NzLight::SetInnerAngle(float innerAngle) inline void NzLight::SetLightType(nzLightType type) { m_type = type; + + InvalidateShadowMap(); } inline void NzLight::SetOuterAngle(float outerAngle) @@ -150,6 +164,24 @@ inline void NzLight::SetRadius(float radius) InvalidateBoundingVolume(); } +inline void NzLight::SetShadowMapFormat(nzPixelFormat shadowFormat) +{ + NazaraAssert(NzPixelFormat::GetType(shadowFormat) == nzPixelFormatType_Depth, "Shadow format type is not a depth format"); + + m_shadowMapFormat = shadowFormat; + + InvalidateShadowMap(); +} + +inline void NzLight::SetShadowMapSize(const NzVector2ui& size) +{ + NazaraAssert(size.x > 0 && size.y > 0, "Shadow map size must have a positive size"); + + m_shadowMapSize = size; + + InvalidateShadowMap(); +} + inline NzLight& NzLight::operator=(const NzLight& light) { NzRenderable::operator=(light); @@ -166,10 +198,17 @@ inline NzLight& NzLight::operator=(const NzLight& light) m_outerAngleTangent = light.m_outerAngleTangent; m_radius = light.m_radius; m_shadowCastingEnabled = light.m_shadowCastingEnabled; - m_shadowMapUpdated = false; + m_shadowMapFormat = light.m_shadowMapFormat; + m_shadowMapSize = light.m_shadowMapSize; m_type = light.m_type; + InvalidateShadowMap(); return *this; } +inline void NzLight::InvalidateShadowMap() +{ + m_shadowMapUpdated = false; +} + #include diff --git a/src/Nazara/Graphics/Light.cpp b/src/Nazara/Graphics/Light.cpp index ee0e233ca..be93fd055 100644 --- a/src/Nazara/Graphics/Light.cpp +++ b/src/Nazara/Graphics/Light.cpp @@ -17,6 +17,8 @@ NzLight::NzLight(nzLightType type) : m_type(type), +m_shadowMapFormat(nzPixelFormat_Depth16), +m_shadowMapSize(512, 512), m_shadowCastingEnabled(false), m_shadowMapUpdated(false) { @@ -186,7 +188,7 @@ void NzLight::UpdateShadowMap() const if (!m_shadowMap) m_shadowMap = NzTexture::New(); - m_shadowMap->Create(nzImageType_2D, nzPixelFormat_Depth16, 256, 256); + m_shadowMap->Create((m_type == nzLightType_Point) ? nzImageType_Cubemap : nzImageType_2D, m_shadowMapFormat, m_shadowMapSize.x, m_shadowMapSize.y); } else m_shadowMap.Reset();