Graphics/Light: Make shadow map format/size parametrable
Former-commit-id: 8151d71d58ab760584c0ace1e0686c44bab9d3b2
This commit is contained in:
parent
2c4a35b2d1
commit
529673ebc1
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 <Nazara/Renderer/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue