Add Phong lighting (WIP)

This commit is contained in:
Jérôme Leclercq
2022-01-11 19:47:29 +01:00
parent 504249e70f
commit b0a3941f4e
40 changed files with 1141 additions and 427 deletions

View File

@@ -19,7 +19,7 @@ namespace Nz
friend class MaterialPipeline;
public:
struct UniformOffsets;
struct BasicUniformOffsets;
BasicMaterial(MaterialPass& material);
~BasicMaterial() = default;
@@ -48,10 +48,10 @@ namespace Nz
inline void SetDiffuseMap(std::shared_ptr<Texture> diffuseMap);
inline void SetDiffuseSampler(TextureSamplerInfo diffuseSampler);
static inline const UniformOffsets& GetOffsets();
static inline const BasicUniformOffsets& GetOffsets();
static inline const std::shared_ptr<MaterialSettings>& GetSettings();
struct UniformOffsets
struct BasicUniformOffsets
{
std::size_t alphaThreshold;
std::size_t diffuseColor;
@@ -59,38 +59,59 @@ namespace Nz
};
protected:
struct OptionIndexes
struct NoInit {};
inline BasicMaterial(MaterialPass& material, NoInit);
struct BasicOptionIndexes
{
std::size_t alphaTest;
std::size_t hasAlphaMap;
std::size_t hasDiffuseMap;
};
struct TextureIndexes
struct BasicTextureIndexes
{
std::size_t alpha;
std::size_t diffuse;
};
static MaterialSettings::Builder Build(const UniformOffsets& offsets, std::vector<UInt8> defaultValues, std::vector<std::shared_ptr<UberShader>> uberShaders, std::size_t* uniformBlockIndex = nullptr, OptionIndexes* optionIndexes = nullptr, TextureIndexes* textureIndexes = nullptr);
struct BasicBuildOptions
{
// Common
std::vector<UInt8> defaultValues;
std::size_t* uniformBlockIndex = nullptr;
std::vector<std::shared_ptr<UberShader>> shaders;
// Basic
BasicUniformOffsets basicOffsets;
BasicOptionIndexes* basicOptionIndexes = nullptr;
BasicTextureIndexes* basicTextureIndexes = nullptr;
};
inline MaterialPass& GetMaterial();
inline const MaterialPass& GetMaterial() const;
static MaterialSettings::Builder Build(BasicBuildOptions& options);
static std::vector<std::shared_ptr<UberShader>> BuildShaders();
static std::pair<UniformOffsets, FieldOffsets> BuildUniformOffsets();
static std::pair<BasicUniformOffsets, FieldOffsets> BuildUniformOffsets();
std::size_t m_uniformBlockIndex;
BasicOptionIndexes m_basicOptionIndexes;
BasicTextureIndexes m_basicTextureIndexes;
BasicUniformOffsets m_basicUniformOffsets;
static std::shared_ptr<MaterialSettings> s_basicMaterialSettings;
static std::size_t s_uniformBlockIndex;
static BasicOptionIndexes s_basicOptionIndexes;
static BasicTextureIndexes s_basicTextureIndexes;
static BasicUniformOffsets s_basicUniformOffsets;
private:
static bool Initialize();
static void Uninitialize();
MaterialPass& m_material;
std::size_t m_uniformBlockIndex;
OptionIndexes m_optionIndexes;
TextureIndexes m_textureIndexes;
UniformOffsets m_uniformOffsets;
static std::shared_ptr<MaterialSettings> s_materialSettings;
static std::size_t s_uniformBlockIndex;
static OptionIndexes s_optionIndexes;
static TextureIndexes s_textureIndexes;
static UniformOffsets s_uniformOffsets;
};
}

View File

@@ -9,6 +9,11 @@
namespace Nz
{
inline BasicMaterial::BasicMaterial(MaterialPass& material, NoInit) :
m_material(material)
{
}
/*!
* \brief Enable/Disable alpha test for this material
*
@@ -26,37 +31,37 @@ namespace Nz
inline void BasicMaterial::EnableAlphaTest(bool alphaTest)
{
NazaraAssert(HasAlphaTest(), "Material has no alpha test option");
m_material.SetOptionValue(m_optionIndexes.alphaTest, alphaTest);
m_material.SetOptionValue(m_basicOptionIndexes.alphaTest, alphaTest);
}
inline const std::shared_ptr<Texture>& BasicMaterial::GetAlphaMap() const
{
NazaraAssert(HasAlphaMap(), "Material has no alpha texture slot");
return m_material.GetTexture(m_textureIndexes.alpha);
return m_material.GetTexture(m_basicTextureIndexes.alpha);
}
inline const TextureSamplerInfo& BasicMaterial::GetAlphaSampler() const
{
NazaraAssert(HasAlphaMap(), "Material has no alpha texture slot");
return m_material.GetTextureSampler(m_textureIndexes.alpha);
return m_material.GetTextureSampler(m_basicTextureIndexes.alpha);
}
inline const std::shared_ptr<Texture>& BasicMaterial::GetDiffuseMap() const
{
NazaraAssert(HasDiffuseMap(), "Material has no alpha texture slot");
return m_material.GetTexture(m_textureIndexes.diffuse);
return m_material.GetTexture(m_basicTextureIndexes.diffuse);
}
inline const TextureSamplerInfo& BasicMaterial::GetDiffuseSampler() const
{
NazaraAssert(HasDiffuseMap(), "Material has no alpha texture slot");
return m_material.GetTextureSampler(m_textureIndexes.diffuse);
return m_material.GetTextureSampler(m_basicTextureIndexes.diffuse);
}
inline bool BasicMaterial::IsAlphaTestEnabled() const
{
NazaraAssert(HasAlphaTest(), "Material has no alpha test option");
const auto& optionOpt = m_material.GetOptionValue(m_optionIndexes.alphaTest);
const auto& optionOpt = m_material.GetOptionValue(m_basicOptionIndexes.alphaTest);
if (std::holds_alternative<ShaderAst::NoValue>(optionOpt))
return false;
@@ -65,69 +70,79 @@ namespace Nz
inline bool BasicMaterial::HasAlphaMap() const
{
return m_textureIndexes.alpha != MaterialSettings::InvalidIndex;
return m_basicTextureIndexes.alpha != MaterialSettings::InvalidIndex;
}
inline bool BasicMaterial::HasAlphaTest() const
{
return m_optionIndexes.alphaTest != MaterialSettings::InvalidIndex;
return m_basicOptionIndexes.alphaTest != MaterialSettings::InvalidIndex;
}
inline bool BasicMaterial::HasAlphaTestThreshold() const
{
return m_uniformOffsets.alphaThreshold != MaterialSettings::InvalidIndex;
return m_basicUniformOffsets.alphaThreshold != MaterialSettings::InvalidIndex;
}
inline bool BasicMaterial::HasDiffuseColor() const
{
return m_uniformOffsets.diffuseColor != MaterialSettings::InvalidIndex;
return m_basicUniformOffsets.diffuseColor != MaterialSettings::InvalidIndex;
}
inline bool BasicMaterial::HasDiffuseMap() const
{
return m_textureIndexes.diffuse != MaterialSettings::InvalidIndex;
return m_basicTextureIndexes.diffuse != MaterialSettings::InvalidIndex;
}
inline void BasicMaterial::SetAlphaMap(std::shared_ptr<Texture> alphaMap)
{
NazaraAssert(HasAlphaMap(), "Material has no alpha map slot");
bool hasAlphaMap = (alphaMap != nullptr);
m_material.SetTexture(m_textureIndexes.alpha, std::move(alphaMap));
m_material.SetTexture(m_basicTextureIndexes.alpha, std::move(alphaMap));
if (m_optionIndexes.hasDiffuseMap != MaterialSettings::InvalidIndex)
m_material.SetOptionValue(m_optionIndexes.hasAlphaMap, hasAlphaMap);
if (m_basicOptionIndexes.hasDiffuseMap != MaterialSettings::InvalidIndex)
m_material.SetOptionValue(m_basicOptionIndexes.hasAlphaMap, hasAlphaMap);
}
inline void BasicMaterial::SetAlphaSampler(TextureSamplerInfo alphaSampler)
{
NazaraAssert(HasAlphaMap(), "Material has no alpha map slot");
m_material.SetTextureSampler(m_textureIndexes.alpha, std::move(alphaSampler));
m_material.SetTextureSampler(m_basicTextureIndexes.alpha, std::move(alphaSampler));
}
inline void BasicMaterial::SetDiffuseMap(std::shared_ptr<Texture> diffuseMap)
{
NazaraAssert(HasDiffuseMap(), "Material has no diffuse map slot");
bool hasDiffuseMap = (diffuseMap != nullptr);
m_material.SetTexture(m_textureIndexes.diffuse, std::move(diffuseMap));
m_material.SetTexture(m_basicTextureIndexes.diffuse, std::move(diffuseMap));
if (m_optionIndexes.hasDiffuseMap != MaterialSettings::InvalidIndex)
m_material.SetOptionValue(m_optionIndexes.hasDiffuseMap, hasDiffuseMap);
if (m_basicOptionIndexes.hasDiffuseMap != MaterialSettings::InvalidIndex)
m_material.SetOptionValue(m_basicOptionIndexes.hasDiffuseMap, hasDiffuseMap);
}
inline void BasicMaterial::SetDiffuseSampler(TextureSamplerInfo diffuseSampler)
{
NazaraAssert(HasDiffuseMap(), "Material has no diffuse map slot");
m_material.SetTextureSampler(m_textureIndexes.diffuse, std::move(diffuseSampler));
m_material.SetTextureSampler(m_basicTextureIndexes.diffuse, std::move(diffuseSampler));
}
inline MaterialPass& BasicMaterial::GetMaterial()
{
return m_material;
}
inline const MaterialPass& BasicMaterial::GetMaterial() const
{
return m_material;
}
inline const std::shared_ptr<MaterialSettings>& BasicMaterial::GetSettings()
{
return s_materialSettings;
return s_basicMaterialSettings;
}
inline auto BasicMaterial::GetOffsets() -> const UniformOffsets&
inline auto BasicMaterial::GetOffsets() -> const BasicUniformOffsets&
{
return s_uniformOffsets;
return s_basicUniformOffsets;
}
}

View File

@@ -29,7 +29,7 @@ namespace Nz
static bool Initialize();
static void Uninitialize();
static std::shared_ptr<MaterialSettings> s_materialSettings;
static std::shared_ptr<MaterialSettings> s_basicMaterialSettings;
};
}

View File

@@ -9,7 +9,7 @@ namespace Nz
{
inline const std::shared_ptr<MaterialSettings>& DepthMaterial::GetSettings()
{
return s_materialSettings;
return s_basicMaterialSettings;
}
}

View File

@@ -16,6 +16,7 @@
namespace Nz
{
class AbstractBuffer;
class CommandBufferBuilder;
class RenderElement;
class RenderFrame;
@@ -25,13 +26,20 @@ namespace Nz
class NAZARA_GRAPHICS_API ElementRenderer
{
public:
struct RenderStates;
ElementRenderer() = default;
virtual ~ElementRenderer();
virtual std::unique_ptr<ElementRendererData> InstanciateData() = 0;
virtual void Prepare(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, RenderFrame& currentFrame, const Pointer<const RenderElement>* elements, std::size_t elementCount);
virtual void Prepare(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, RenderFrame& currentFrame, const RenderStates& renderStates, const Pointer<const RenderElement>* elements, std::size_t elementCount);
virtual void Render(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer<const RenderElement>* elements, std::size_t elementCount) = 0;
virtual void Reset(ElementRendererData& rendererData, RenderFrame& currentFrame);
struct RenderStates
{
std::shared_ptr<AbstractBuffer> lightData;
};
};
struct NAZARA_GRAPHICS_API ElementRendererData

View File

@@ -12,6 +12,15 @@
namespace Nz
{
enum class BasicLightType
{
Directional,
Point,
Spot,
Max = Spot
};
enum class BasicRenderElement
{
SpriteChain = 0,
@@ -54,6 +63,7 @@ namespace Nz
enum class PredefinedShaderBinding
{
InstanceDataUbo,
LightDataUbo,
OverlayTexture,
ViewerDataUbo,

View File

@@ -108,6 +108,7 @@ namespace Nz
std::size_t m_depthPassIndex;
std::size_t m_forwardPassIndex;
std::shared_ptr<AbstractBuffer> m_lightDataBuffer;
std::unordered_map<AbstractViewer*, ViewerData> m_viewers;
std::unordered_map<MaterialPass*, MaterialData> m_materials;
std::unordered_map<WorldInstancePtr, std::unordered_map<const InstancedRenderable*, RenderableData>> m_renderables;

View File

@@ -57,10 +57,6 @@ namespace Nz
std::array<std::shared_ptr<Texture>, ImageTypeCount> whiteTextures;
};
static void FillDrawDataPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set);
static void FillViewerPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set);
static void FillWorldPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set);
private:
void BuildBlitPipeline();
void BuildDefaultTextures();

View File

@@ -75,7 +75,7 @@ namespace Nz
inline const std::shared_ptr<Texture>& GetTexture(std::size_t textureIndex) const;
inline const TextureSamplerInfo& GetTextureSampler(std::size_t textureIndex) const;
inline const std::shared_ptr<AbstractBuffer>& GetUniformBuffer(std::size_t bufferIndex) const;
inline const std::vector<UInt8>& GetUniformBufferConstData(std::size_t bufferIndex);
inline const std::vector<UInt8>& GetUniformBufferConstData(std::size_t bufferIndex) const;
inline std::vector<UInt8>& GetUniformBufferData(std::size_t bufferIndex);
inline bool HasTexture(std::size_t textureIndex) const;

View File

@@ -391,7 +391,7 @@ namespace Nz
return m_uniformBuffers[bufferIndex].buffer;
}
inline const std::vector<UInt8>& MaterialPass::GetUniformBufferConstData(std::size_t bufferIndex)
inline const std::vector<UInt8>& MaterialPass::GetUniformBufferConstData(std::size_t bufferIndex) const
{
NazaraAssert(bufferIndex < m_uniformBuffers.size(), "Invalid uniform buffer index");
return m_uniformBuffers[bufferIndex].data;

View File

@@ -8,38 +8,31 @@
#define NAZARA_GRAPHICS_PHONGLIGHTINGMATERIAL_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/BasicMaterial.hpp>
#include <Nazara/Graphics/MaterialPass.hpp>
namespace Nz
{
class NAZARA_GRAPHICS_API PhongLightingMaterial
class NAZARA_GRAPHICS_API PhongLightingMaterial : public BasicMaterial
{
friend class MaterialPipeline;
public:
PhongLightingMaterial(MaterialPass& material);
inline const std::shared_ptr<Texture>& GetAlphaMap() const;
float GetAlphaThreshold() const;
Color GetAmbientColor() const;
Color GetDiffuseColor() const;
inline const std::shared_ptr<Texture>& GetDiffuseMap() const;
inline TextureSampler& GetDiffuseSampler();
inline const TextureSampler& GetDiffuseSampler() const;
inline const std::shared_ptr<Texture>& GetEmissiveMap() const;
inline const TextureSamplerInfo& GetEmissiveSampler() const;
inline const std::shared_ptr<Texture>& GetHeightMap() const;
inline const TextureSamplerInfo& GetHeightSampler() const;
inline const std::shared_ptr<Texture>& GetNormalMap() const;
inline const TextureSamplerInfo& GetNormalSampler() const;
float GetShininess() const;
Color GetSpecularColor() const;
inline const std::shared_ptr<Texture>& GetSpecularMap() const;
inline TextureSampler& GetSpecularSampler();
inline const TextureSampler& GetSpecularSampler() const;
inline const TextureSamplerInfo& GetSpecularSampler() const;
inline bool HasAlphaMap() const;
inline bool HasAlphaThreshold() const;
inline bool HasAmbientColor() const;
inline bool HasDiffuseColor() const;
inline bool HasDiffuseMap() const;
inline bool HasEmissiveMap() const;
inline bool HasHeightMap() const;
inline bool HasNormalMap() const;
@@ -47,53 +40,68 @@ namespace Nz
inline bool HasSpecularColor() const;
inline bool HasSpecularMap() const;
inline void SetAlphaMap(std::shared_ptr<Texture> alphaMap);
void SetAlphaThreshold(float alphaThreshold);
void SetAmbientColor(const Color& ambient);
void SetDiffuseColor(const Color& diffuse);
inline void SetDiffuseMap(std::shared_ptr<Texture> diffuseMap);
inline void SetDiffuseSampler(const TextureSampler& sampler);
inline void SetEmissiveMap(std::shared_ptr<Texture> textureName);
inline void SetHeightMap(std::shared_ptr<Texture> textureName);
inline void SetNormalMap(std::shared_ptr<Texture> textureName);
inline void SetEmissiveMap(std::shared_ptr<Texture> emissiveMap);
inline void SetEmissiveSampler(TextureSamplerInfo emissiveSampler);
inline void SetHeightMap(std::shared_ptr<Texture> heightMap);
inline void SetHeightSampler(TextureSamplerInfo heightSampler);
inline void SetNormalMap(std::shared_ptr<Texture> normalMap);
inline void SetNormalSampler(TextureSamplerInfo normalSampler);
void SetShininess(float shininess);
void SetSpecularColor(const Color& specular);
inline void SetSpecularMap(std::shared_ptr<Texture> specularMap);
inline void SetSpecularSampler(const TextureSampler& sampler);
inline void SetSpecularSampler(TextureSamplerInfo specularSampler);
static const std::shared_ptr<MaterialSettings>& GetSettings();
private:
protected:
struct PhongOptionIndexes
{
std::size_t hasEmissiveMap;
std::size_t hasHeightMap;
std::size_t hasNormalMap;
std::size_t hasSpecularMap;
};
struct PhongUniformOffsets
{
std::size_t alphaThreshold;
std::size_t shininess;
std::size_t ambientColor;
std::size_t diffuseColor;
std::size_t shininess;
std::size_t totalSize;
std::size_t specularColor;
};
struct TextureIndexes
struct PhongTextureIndexes
{
std::size_t alpha;
std::size_t diffuse;
std::size_t emissive;
std::size_t height;
std::size_t normal;
std::size_t specular;
};
struct PhongBuildOptions : BasicBuildOptions
{
PhongUniformOffsets phongOffsets;
PhongOptionIndexes* phongOptionIndexes = nullptr;
PhongTextureIndexes* phongTextureIndexes = nullptr;
};
PhongOptionIndexes m_phongOptionIndexes;
PhongTextureIndexes m_phongTextureIndexes;
PhongUniformOffsets m_phongUniformOffsets;
static MaterialSettings::Builder Build(PhongBuildOptions& options);
static std::vector<std::shared_ptr<UberShader>> BuildShaders();
static std::pair<PhongUniformOffsets, FieldOffsets> BuildUniformOffsets();
private:
static bool Initialize();
static void Uninitialize();
MaterialPass& m_material;
std::size_t m_phongUniformIndex;
TextureIndexes m_textureIndexes;
PhongUniformOffsets m_phongUniformOffsets;
static std::shared_ptr<MaterialSettings> s_materialSettings;
static std::shared_ptr<MaterialSettings> s_phongMaterialSettings;
static std::size_t s_phongUniformBlockIndex;
static TextureIndexes s_textureIndexes;
static PhongOptionIndexes s_phongOptionIndexes;
static PhongTextureIndexes s_phongTextureIndexes;
static PhongUniformOffsets s_phongUniformOffsets;
};
}

View File

@@ -9,50 +9,52 @@
namespace Nz
{
inline const std::shared_ptr<Texture>& PhongLightingMaterial::GetAlphaMap() const
{
NazaraAssert(HasAlphaMap(), "Material has no alpha map slot");
return m_material.GetTexture(m_textureIndexes.alpha);
}
inline const std::shared_ptr<Texture>& PhongLightingMaterial::GetDiffuseMap() const
{
NazaraAssert(HasDiffuseMap(), "Material has no alpha map slot");
return m_material.GetTexture(m_textureIndexes.diffuse);
}
inline const std::shared_ptr<Texture>& PhongLightingMaterial::GetEmissiveMap() const
{
NazaraAssert(HasEmissiveMap(), "Material has no alpha map slot");
return m_material.GetTexture(m_textureIndexes.emissive);
NazaraAssert(HasEmissiveMap(), "Material has no emissive map slot");
return GetMaterial().GetTexture(m_phongTextureIndexes.emissive);
}
inline const TextureSamplerInfo& PhongLightingMaterial::GetEmissiveSampler() const
{
NazaraAssert(HasSpecularMap(), "Material has no emissive map slot");
return GetMaterial().GetTextureSampler(m_phongTextureIndexes.emissive);
}
inline const std::shared_ptr<Texture>& PhongLightingMaterial::GetHeightMap() const
{
NazaraAssert(HasHeightMap(), "Material has no alpha map slot");
return m_material.GetTexture(m_textureIndexes.height);
NazaraAssert(HasHeightMap(), "Material has no height map slot");
return GetMaterial().GetTexture(m_phongTextureIndexes.height);
}
inline const TextureSamplerInfo& PhongLightingMaterial::GetHeightSampler() const
{
NazaraAssert(HasSpecularMap(), "Material has no height map slot");
return GetMaterial().GetTextureSampler(m_phongTextureIndexes.height);
}
inline const std::shared_ptr<Texture>& PhongLightingMaterial::GetNormalMap() const
{
NazaraAssert(HasNormalMap(), "Material has no alpha map slot");
return m_material.GetTexture(m_textureIndexes.normal);
NazaraAssert(HasNormalMap(), "Material has no normal map slot");
return GetMaterial().GetTexture(m_phongTextureIndexes.normal);
}
inline const TextureSamplerInfo& PhongLightingMaterial::GetNormalSampler() const
{
NazaraAssert(HasSpecularMap(), "Material has no normal map slot");
return GetMaterial().GetTextureSampler(m_phongTextureIndexes.normal);
}
inline const std::shared_ptr<Texture>& PhongLightingMaterial::GetSpecularMap() const
{
NazaraAssert(HasSpecularMap(), "Material has no alpha map slot");
return m_material.GetTexture(m_textureIndexes.specular);
NazaraAssert(HasSpecularMap(), "Material has no specular map slot");
return GetMaterial().GetTexture(m_phongTextureIndexes.specular);
}
inline bool PhongLightingMaterial::HasAlphaMap() const
inline const TextureSamplerInfo& PhongLightingMaterial::GetSpecularSampler() const
{
return m_textureIndexes.alpha != MaterialSettings::InvalidIndex;
}
inline bool PhongLightingMaterial::HasAlphaThreshold() const
{
return m_phongUniformOffsets.alphaThreshold != MaterialSettings::InvalidIndex;
NazaraAssert(HasSpecularMap(), "Material has no specular map slot");
return GetMaterial().GetTextureSampler(m_phongTextureIndexes.specular);
}
inline bool PhongLightingMaterial::HasAmbientColor() const
@@ -60,29 +62,19 @@ namespace Nz
return m_phongUniformOffsets.ambientColor != MaterialSettings::InvalidIndex;
}
inline bool PhongLightingMaterial::HasDiffuseColor() const
{
return m_phongUniformOffsets.diffuseColor != MaterialSettings::InvalidIndex;
}
inline bool PhongLightingMaterial::HasDiffuseMap() const
{
return m_textureIndexes.diffuse != MaterialSettings::InvalidIndex;
}
inline bool PhongLightingMaterial::HasEmissiveMap() const
{
return m_textureIndexes.emissive != MaterialSettings::InvalidIndex;
return m_phongTextureIndexes.emissive != MaterialSettings::InvalidIndex;
}
inline bool PhongLightingMaterial::HasHeightMap() const
{
return m_textureIndexes.height != MaterialSettings::InvalidIndex;
return m_phongTextureIndexes.height != MaterialSettings::InvalidIndex;
}
inline bool PhongLightingMaterial::HasNormalMap() const
{
return m_textureIndexes.normal != MaterialSettings::InvalidIndex;
return m_phongTextureIndexes.normal != MaterialSettings::InvalidIndex;
}
inline bool PhongLightingMaterial::HasShininess() const
@@ -97,25 +89,71 @@ namespace Nz
inline bool PhongLightingMaterial::HasSpecularMap() const
{
return m_textureIndexes.specular != MaterialSettings::InvalidIndex;
return m_phongTextureIndexes.specular != MaterialSettings::InvalidIndex;
}
inline void PhongLightingMaterial::SetAlphaMap(std::shared_ptr<Texture> alphaMap)
inline void PhongLightingMaterial::SetEmissiveMap(std::shared_ptr<Texture> emissiveMap)
{
NazaraAssert(HasAlphaMap(), "Material has no alpha map slot");
m_material.SetTexture(m_textureIndexes.alpha, std::move(alphaMap));
NazaraAssert(HasEmissiveMap(), "Material has no emissive map slot");
bool hasEmissiveMap = (emissiveMap != nullptr);
GetMaterial().SetTexture(m_phongTextureIndexes.emissive, std::move(emissiveMap));
if (m_phongOptionIndexes.hasEmissiveMap != MaterialSettings::InvalidIndex)
GetMaterial().SetOptionValue(m_phongOptionIndexes.hasEmissiveMap, hasEmissiveMap);
}
inline void PhongLightingMaterial::SetDiffuseMap(std::shared_ptr<Texture> diffuseMap)
inline void PhongLightingMaterial::SetEmissiveSampler(TextureSamplerInfo emissiveSampler)
{
NazaraAssert(HasDiffuseMap(), "Material has no diffuse map slot");
m_material.SetTexture(m_textureIndexes.diffuse, std::move(diffuseMap));
NazaraAssert(HasEmissiveMap(), "Material has no emissive map slot");
GetMaterial().SetTextureSampler(m_phongTextureIndexes.emissive, std::move(emissiveSampler));
}
inline void PhongLightingMaterial::SetHeightMap(std::shared_ptr<Texture> heightMap)
{
NazaraAssert(HasHeightMap(), "Material has no specular map slot");
bool hasHeightMap = (heightMap != nullptr);
GetMaterial().SetTexture(m_phongTextureIndexes.height, std::move(heightMap));
if (m_phongOptionIndexes.hasHeightMap != MaterialSettings::InvalidIndex)
GetMaterial().SetOptionValue(m_phongOptionIndexes.hasHeightMap, hasHeightMap);
}
inline void PhongLightingMaterial::SetHeightSampler(TextureSamplerInfo heightSampler)
{
NazaraAssert(HasHeightMap(), "Material has no height map slot");
GetMaterial().SetTextureSampler(m_phongTextureIndexes.height, std::move(heightSampler));
}
inline void PhongLightingMaterial::SetNormalMap(std::shared_ptr<Texture> normalMap)
{
NazaraAssert(HasNormalMap(), "Material has no normal map slot");
m_material.SetTexture(m_textureIndexes.normal, std::move(normalMap));
bool hasNormalMap = (normalMap != nullptr);
GetMaterial().SetTexture(m_phongTextureIndexes.normal, std::move(normalMap));
if (m_phongOptionIndexes.hasNormalMap != MaterialSettings::InvalidIndex)
GetMaterial().SetOptionValue(m_phongOptionIndexes.hasNormalMap, hasNormalMap);
}
inline void PhongLightingMaterial::SetNormalSampler(TextureSamplerInfo normalSampler)
{
NazaraAssert(HasNormalMap(), "Material has no normal map slot");
GetMaterial().SetTextureSampler(m_phongTextureIndexes.normal, std::move(normalSampler));
}
inline void PhongLightingMaterial::SetSpecularMap(std::shared_ptr<Texture> specularMap)
{
NazaraAssert(HasNormalMap(), "Material has no specular map slot");
bool hasSpecularMap = (specularMap != nullptr);
GetMaterial().SetTexture(m_phongTextureIndexes.specular, std::move(specularMap));
if (m_phongOptionIndexes.hasSpecularMap != MaterialSettings::InvalidIndex)
GetMaterial().SetOptionValue(m_phongOptionIndexes.hasSpecularMap, hasSpecularMap);
}
inline void PhongLightingMaterial::SetSpecularSampler(TextureSamplerInfo specularSampler)
{
NazaraAssert(HasSpecularMap(), "Material has no specular map slot");
GetMaterial().SetTextureSampler(m_phongTextureIndexes.specular, std::move(specularSampler));
}
}

View File

@@ -15,7 +15,7 @@ namespace Nz
{
struct NAZARA_GRAPHICS_API PredefinedLightData
{
struct InnerStruct
struct Light
{
std::size_t type;
std::size_t color;
@@ -24,15 +24,18 @@ namespace Nz
std::size_t parameter2;
std::size_t parameter3;
std::size_t shadowMappingFlag;
std::size_t totalSize;
};
InnerStruct innerOffsets;
std::array<std::size_t, 3> lightArray;
std::size_t lightArraySize;
std::size_t lightsOffset;
std::size_t lightCountOffset;
std::size_t lightSize;
std::size_t totalSize;
Light lightMemberOffsets;
static constexpr std::size_t MaxLightCount = 3;
static PredefinedLightData GetOffsets();
static MaterialSettings::SharedUniformBlock GetUniformBlock();
static MaterialSettings::SharedUniformBlock GetUniformBlock(UInt32 bindingIndex, ShaderStageTypeFlags shaderStages);
};
struct NAZARA_GRAPHICS_API PredefinedInstanceData

View File

@@ -89,7 +89,7 @@ namespace Nz
inline void Sprite::UpdateVertices()
{
Boxf aabb;
Boxf aabb = Boxf::Zero();
VertexStruct_XYZ_Color_UV* vertices = m_vertices.data();
@@ -105,7 +105,10 @@ namespace Nz
vertices->position = Vector3f(m_size * cornerExtent[UnderlyingCast(corner)], 0.f) - m_origin;
vertices->uv = m_textureCoords.GetCorner(corner);
aabb.Set(vertices->position);
if (aabb.IsValid())
aabb.ExtendTo(vertices->position);
else
aabb.Set(vertices->position);
vertices++;
}

View File

@@ -31,7 +31,7 @@ namespace Nz
~SpriteChainRenderer() = default;
std::unique_ptr<ElementRendererData> InstanciateData() override;
void Prepare(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, RenderFrame& currentFrame, const Pointer<const RenderElement>* elements, std::size_t elementCount) override;
void Prepare(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, RenderFrame& currentFrame, const RenderStates& renderStates, const Pointer<const RenderElement>* elements, std::size_t elementCount) override;
void Render(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer<const RenderElement>* elements, std::size_t elementCount) override;
void Reset(ElementRendererData& rendererData, RenderFrame& currentFrame) override;

View File

@@ -21,13 +21,13 @@ namespace Nz
class NAZARA_GRAPHICS_API SubmeshRenderer : public ElementRenderer
{
public:
SubmeshRenderer();
SubmeshRenderer() = default;
~SubmeshRenderer() = default;
std::unique_ptr<ElementRendererData> InstanciateData();
void Prepare(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, RenderFrame& currentFrame, const Pointer<const RenderElement>* elements, std::size_t elementCount);
std::unique_ptr<ElementRendererData> InstanciateData() override;
void Prepare(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, RenderFrame& currentFrame, const RenderStates& renderStates, const Pointer<const RenderElement>* elements, std::size_t elementCount) override;
void Render(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer<const RenderElement>* elements, std::size_t elementCount) override;
void Reset(ElementRendererData& rendererData, RenderFrame& currentFrame);
void Reset(ElementRendererData& rendererData, RenderFrame& currentFrame) override;
private:
std::vector<ShaderBinding::Binding> m_bindingCache;

View File

@@ -28,6 +28,7 @@ namespace Nz
ViewerInstance(ViewerInstance&&) noexcept = default;
~ViewerInstance() = default;
inline const Vector3f& GetEyePosition() const;
inline const Matrix4f& GetInvProjectionMatrix() const;
inline const Matrix4f& GetInvViewMatrix() const;
inline const Matrix4f& GetInvViewProjMatrix() const;
@@ -39,6 +40,7 @@ namespace Nz
inline const std::shared_ptr<AbstractBuffer>& GetViewerBuffer() const;
void UpdateBuffers(UploadPool& uploadPool, CommandBufferBuilder& builder);
inline void UpdateEyePosition(const Vector3f& eyePosition);
inline void UpdateProjectionMatrix(const Matrix4f& projectionMatrix);
inline void UpdateProjectionMatrix(const Matrix4f& projectionMatrix, const Matrix4f& invProjectionMatrix);
inline void UpdateProjViewMatrices(const Matrix4f& projectionMatrix, const Matrix4f& viewMatrix);
@@ -60,6 +62,7 @@ namespace Nz
Matrix4f m_viewProjMatrix;
Matrix4f m_viewMatrix;
Vector2f m_targetSize;
Vector3f m_eyePosition;
bool m_dataInvalided;
};
}

View File

@@ -8,6 +8,11 @@
namespace Nz
{
inline const Vector3f& ViewerInstance::GetEyePosition() const
{
return m_eyePosition;
}
inline const Matrix4f& ViewerInstance::GetInvProjectionMatrix() const
{
return m_invProjectionMatrix;
@@ -53,6 +58,12 @@ namespace Nz
return m_viewerDataBuffer;
}
inline void ViewerInstance::UpdateEyePosition(const Vector3f& eyePosition)
{
m_eyePosition = eyePosition;
m_dataInvalided = true;
}
inline void ViewerInstance::UpdateProjectionMatrix(const Matrix4f& projectionMatrix)
{
m_projectionMatrix = projectionMatrix;

View File

@@ -103,7 +103,9 @@ namespace Nz
Length = 3,
Max = 4,
Min = 5,
Normalize = 9,
Pow = 6,
Reflect = 8,
SampleTexture = 2,
};

View File

@@ -40,6 +40,7 @@ namespace Nz::ShaderAst
std::unordered_set<std::string> reservedIdentifiers;
std::unordered_map<std::size_t, ConstantValue> optionValues;
bool makeVariableNameUnique = false;
bool removeConstDeclaration = false;
bool reduceLoopsToWhile = false;
bool removeCompoundAssignments = false;
bool removeOptionDeclaration = false;