Graphics/Material: Add shadow support

The real fun will be in the shader


Former-commit-id: e29e98cbf3c35e4cf14c68852e03dc9da1df0ff1
This commit is contained in:
Lynix 2015-06-18 00:03:38 +02:00
parent 763701df7f
commit ac8578c510
3 changed files with 31 additions and 0 deletions

View File

@ -63,6 +63,8 @@ class NAZARA_GRAPHICS_API NzMaterial : public NzRefCounted, public NzResource
inline void EnableAlphaTest(bool alphaTest); inline void EnableAlphaTest(bool alphaTest);
inline void EnableDepthSorting(bool depthSorting); inline void EnableDepthSorting(bool depthSorting);
inline void EnableLighting(bool lighting); inline void EnableLighting(bool lighting);
inline void EnableShadowCasting(bool castShadows);
inline void EnableShadowReceive(bool receiveShadows);
inline void EnableTransform(bool transform); inline void EnableTransform(bool transform);
inline NzTexture* GetAlphaMap() const; inline NzTexture* GetAlphaMap() const;
@ -100,6 +102,8 @@ class NAZARA_GRAPHICS_API NzMaterial : public NzRefCounted, public NzResource
inline bool IsDepthSortingEnabled() const; inline bool IsDepthSortingEnabled() const;
inline bool IsEnabled(nzRendererParameter renderParameter) const; inline bool IsEnabled(nzRendererParameter renderParameter) const;
inline bool IsLightingEnabled() const; inline bool IsLightingEnabled() const;
inline bool IsShadowCastingEnabled() const;
inline bool IsShadowReceiveEnabled() const;
inline bool IsTransformEnabled() const; inline bool IsTransformEnabled() const;
inline bool LoadFromFile(const NzString& filePath, const NzMaterialParams& params = NzMaterialParams()); inline bool LoadFromFile(const NzString& filePath, const NzMaterialParams& params = NzMaterialParams());
@ -177,6 +181,8 @@ class NAZARA_GRAPHICS_API NzMaterial : public NzRefCounted, public NzResource
bool m_alphaTestEnabled; bool m_alphaTestEnabled;
bool m_depthSortingEnabled; bool m_depthSortingEnabled;
bool m_lightingEnabled; bool m_lightingEnabled;
bool m_shadowCastingEnabled;
bool m_shadowReceiveEnabled;
bool m_transformEnabled; bool m_transformEnabled;
float m_alphaThreshold; float m_alphaThreshold;
float m_shininess; float m_shininess;

View File

@ -38,6 +38,7 @@ inline void NzMaterial::EnableAlphaTest(bool alphaTest)
inline void NzMaterial::EnableDepthSorting(bool depthSorting) inline void NzMaterial::EnableDepthSorting(bool depthSorting)
{ {
// Has no influence on shaders
m_depthSortingEnabled = depthSorting; m_depthSortingEnabled = depthSorting;
} }
@ -48,6 +49,19 @@ inline void NzMaterial::EnableLighting(bool lighting)
InvalidateShaders(); InvalidateShaders();
} }
inline void NzMaterial::EnableShadowCasting(bool castShadows)
{
// Has no influence on shaders
m_shadowCastingEnabled = castShadows;
}
inline void NzMaterial::EnableShadowReceive(bool receiveShadows)
{
m_shadowReceiveEnabled = receiveShadows;
InvalidateShaders();
}
inline void NzMaterial::EnableTransform(bool transform) inline void NzMaterial::EnableTransform(bool transform)
{ {
m_transformEnabled = transform; m_transformEnabled = transform;
@ -226,6 +240,16 @@ inline bool NzMaterial::IsLightingEnabled() const
return m_lightingEnabled; return m_lightingEnabled;
} }
inline bool NzMaterial::IsShadowCastingEnabled() const
{
return m_shadowCastingEnabled;
}
inline bool NzMaterial::IsShadowReceiveEnabled() const
{
return m_shadowReceiveEnabled;
}
inline bool NzMaterial::IsTransformEnabled() const inline bool NzMaterial::IsTransformEnabled() const
{ {
return m_transformEnabled; return m_transformEnabled;

View File

@ -195,6 +195,7 @@ void NzMaterial::GenerateShader(nzUInt32 flags) const
list.SetParameter("LIGHTING", m_lightingEnabled); list.SetParameter("LIGHTING", m_lightingEnabled);
list.SetParameter("NORMAL_MAPPING", m_normalMap.IsValid()); list.SetParameter("NORMAL_MAPPING", m_normalMap.IsValid());
list.SetParameter("PARALLAX_MAPPING", m_heightMap.IsValid()); list.SetParameter("PARALLAX_MAPPING", m_heightMap.IsValid());
list.SetParameter("SHADOW_MAPPING", m_shadowReceiveEnabled);
list.SetParameter("SPECULAR_MAPPING", m_specularMap.IsValid()); list.SetParameter("SPECULAR_MAPPING", m_specularMap.IsValid());
list.SetParameter("TEXTURE_MAPPING", m_alphaMap.IsValid() || m_diffuseMap.IsValid() || m_emissiveMap.IsValid() || list.SetParameter("TEXTURE_MAPPING", m_alphaMap.IsValid() || m_diffuseMap.IsValid() || m_emissiveMap.IsValid() ||
m_normalMap.IsValid() || m_heightMap.IsValid() || m_specularMap.IsValid() || m_normalMap.IsValid() || m_heightMap.IsValid() || m_specularMap.IsValid() ||