Graphics/Light: Add cache infos (cosines, tangent) + inline
Former-commit-id: 36e6fb9c2d09597480302da30d3097ec54582fe8
This commit is contained in:
parent
68d6f62cd4
commit
a92a58301a
|
|
@ -34,8 +34,12 @@ class NAZARA_API NzLight : public NzRenderable
|
|||
NzColor GetColor() const;
|
||||
float GetDiffuseFactor() const;
|
||||
float GetInnerAngle() const;
|
||||
float GetInnerAngleCosine() const;
|
||||
float GetInvRadius() const;
|
||||
nzLightType GetLightType() const;
|
||||
float GetOuterAngle() const;
|
||||
float GetOuterAngleCosine() const;
|
||||
float GetOuterAngleTangent() const;
|
||||
float GetRadius() const;
|
||||
|
||||
void SetAmbientFactor(float factor);
|
||||
|
|
@ -60,7 +64,11 @@ class NAZARA_API NzLight : public NzRenderable
|
|||
float m_attenuation;
|
||||
float m_diffuseFactor;
|
||||
float m_innerAngle;
|
||||
float m_innerAngleCosine;
|
||||
float m_invRadius;
|
||||
float m_outerAngle;
|
||||
float m_outerAngleCosine;
|
||||
float m_outerAngleTangent;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
|
|
@ -85,4 +93,6 @@ struct NzLightUniforms
|
|||
};
|
||||
};
|
||||
|
||||
#include <Nazara/Graphics/Light.inl>
|
||||
|
||||
#endif // NAZARA_LIGHT_HPP
|
||||
|
|
|
|||
|
|
@ -0,0 +1,92 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
inline float NzLight::GetAmbientFactor() const
|
||||
{
|
||||
return m_ambientFactor;
|
||||
}
|
||||
|
||||
inline float NzLight::GetAttenuation() const
|
||||
{
|
||||
return m_attenuation;
|
||||
}
|
||||
|
||||
inline NzColor NzLight::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
inline float NzLight::GetDiffuseFactor() const
|
||||
{
|
||||
return m_diffuseFactor;
|
||||
}
|
||||
|
||||
inline float NzLight::GetInnerAngle() const
|
||||
{
|
||||
return m_innerAngle;
|
||||
}
|
||||
|
||||
inline nzLightType NzLight::GetLightType() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
inline float NzLight::GetOuterAngle() const
|
||||
{
|
||||
return m_outerAngle;
|
||||
}
|
||||
|
||||
inline float NzLight::GetRadius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
inline void NzLight::SetAmbientFactor(float factor)
|
||||
{
|
||||
m_ambientFactor = factor;
|
||||
}
|
||||
|
||||
inline void NzLight::SetAttenuation(float attenuation)
|
||||
{
|
||||
m_attenuation = attenuation;
|
||||
}
|
||||
|
||||
inline void NzLight::SetColor(const NzColor& color)
|
||||
{
|
||||
m_color = color;
|
||||
}
|
||||
|
||||
inline void NzLight::SetDiffuseFactor(float factor)
|
||||
{
|
||||
m_diffuseFactor = factor;
|
||||
}
|
||||
|
||||
inline void NzLight::SetInnerAngle(float innerAngle)
|
||||
{
|
||||
m_innerAngle = innerAngle;
|
||||
m_innerAngleCosine = std::cos(NzDegreeToRadian(m_innerAngle));
|
||||
}
|
||||
|
||||
inline void NzLight::SetLightType(nzLightType type)
|
||||
{
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
inline void NzLight::SetOuterAngle(float outerAngle)
|
||||
{
|
||||
m_outerAngle = outerAngle;
|
||||
m_outerAngleCosine = std::cos(NzDegreeToRadian(m_outerAngle));
|
||||
m_outerAngleTangent = std::tan(NzDegreeToRadian(m_outerAngle));
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
}
|
||||
|
||||
inline void NzLight::SetRadius(float radius)
|
||||
{
|
||||
m_radius = radius;
|
||||
|
||||
m_invRadius = 1.f / m_radius;
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
}
|
||||
|
|
@ -17,15 +17,15 @@
|
|||
///TODO: Scale ?
|
||||
|
||||
NzLight::NzLight(nzLightType type) :
|
||||
m_type(type),
|
||||
m_color(NzColor::White),
|
||||
m_ambientFactor((type == nzLightType_Directional) ? 0.2f : 0.f),
|
||||
m_attenuation(0.9f),
|
||||
m_diffuseFactor(1.f),
|
||||
m_innerAngle(15.f),
|
||||
m_outerAngle(45.f),
|
||||
m_radius(5.f)
|
||||
m_type(type)
|
||||
{
|
||||
SetAmbientFactor((type == nzLightType_Directional) ? 0.2f : 0.f);
|
||||
SetAttenuation(0.9f);
|
||||
SetColor(NzColor::White);
|
||||
SetDiffuseFactor(1.f);
|
||||
SetInnerAngle(15.f);
|
||||
SetOuterAngle(45.f);
|
||||
SetRadius(5.f);
|
||||
}
|
||||
|
||||
void NzLight::AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const NzMatrix4f& transformMatrix) const
|
||||
|
|
@ -77,90 +77,6 @@ bool NzLight::Cull(const NzFrustumf& frustum, const NzBoundingVolumef& volume, c
|
|||
return false;
|
||||
}
|
||||
|
||||
float NzLight::GetAmbientFactor() const
|
||||
{
|
||||
return m_ambientFactor;
|
||||
}
|
||||
|
||||
float NzLight::GetAttenuation() const
|
||||
{
|
||||
return m_attenuation;
|
||||
}
|
||||
|
||||
NzColor NzLight::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
float NzLight::GetDiffuseFactor() const
|
||||
{
|
||||
return m_diffuseFactor;
|
||||
}
|
||||
|
||||
float NzLight::GetInnerAngle() const
|
||||
{
|
||||
return m_innerAngle;
|
||||
}
|
||||
|
||||
nzLightType NzLight::GetLightType() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
float NzLight::GetOuterAngle() const
|
||||
{
|
||||
return m_outerAngle;
|
||||
}
|
||||
|
||||
float NzLight::GetRadius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
void NzLight::SetAmbientFactor(float factor)
|
||||
{
|
||||
m_ambientFactor = factor;
|
||||
}
|
||||
|
||||
void NzLight::SetAttenuation(float attenuation)
|
||||
{
|
||||
m_attenuation = attenuation;
|
||||
}
|
||||
|
||||
void NzLight::SetColor(const NzColor& color)
|
||||
{
|
||||
m_color = color;
|
||||
}
|
||||
|
||||
void NzLight::SetDiffuseFactor(float factor)
|
||||
{
|
||||
m_diffuseFactor = factor;
|
||||
}
|
||||
|
||||
void NzLight::SetInnerAngle(float innerAngle)
|
||||
{
|
||||
m_innerAngle = innerAngle;
|
||||
}
|
||||
|
||||
void NzLight::SetLightType(nzLightType type)
|
||||
{
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
void NzLight::SetOuterAngle(float outerAngle)
|
||||
{
|
||||
m_outerAngle = outerAngle;
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
}
|
||||
|
||||
void NzLight::SetRadius(float radius)
|
||||
{
|
||||
m_radius = radius;
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
}
|
||||
|
||||
void NzLight::UpdateBoundingVolume(NzBoundingVolumef* boundingVolume, const NzMatrix4f& transformMatrix) const
|
||||
{
|
||||
NazaraAssert(boundingVolume, "Invalid bounding volume");
|
||||
|
|
@ -209,7 +125,7 @@ void NzLight::MakeBoundingVolume() const
|
|||
|
||||
// Il nous faut maintenant le rayon du cercle projeté à cette distance
|
||||
// Tangente = Opposé/Adjaçent <=> Opposé = Adjaçent*Tangente
|
||||
float radius = m_radius*std::tan(NzDegreeToRadian(m_outerAngle));
|
||||
float radius = m_radius * m_outerAngleTangent;
|
||||
NzVector3f lExtend = NzVector3f::Left()*radius;
|
||||
NzVector3f uExtend = NzVector3f::Up()*radius;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue