Graphics: Add DepthMaterial

This commit is contained in:
Jérôme Leclercq
2021-08-10 10:36:16 +02:00
parent 7aafcfaae9
commit a2a0e6bd54
11 changed files with 213 additions and 73 deletions

View File

@@ -35,6 +35,7 @@
#include <Nazara/Graphics/Camera.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/CullingList.hpp>
#include <Nazara/Graphics/DepthMaterial.hpp>
#include <Nazara/Graphics/ElementRenderer.hpp>
#include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Graphics/ForwardFramePipeline.hpp>

View File

@@ -12,6 +12,8 @@
namespace Nz
{
class FieldOffsets;
class NAZARA_GRAPHICS_API BasicMaterial
{
friend class MaterialPipeline;
@@ -56,7 +58,7 @@ namespace Nz
std::size_t totalSize;
};
private:
protected:
struct OptionIndexes
{
std::size_t alphaTest;
@@ -70,6 +72,11 @@ namespace Nz
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);
static std::vector<std::shared_ptr<UberShader>> BuildShaders();
static std::pair<UniformOffsets, FieldOffsets> BuildUniformOffsets();
private:
static bool Initialize();
static void Uninitialize();

View File

@@ -0,0 +1,38 @@
// Copyright (C) 2017 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
#pragma once
#ifndef NAZARA_DEPTH_MATERIAL_HPP
#define NAZARA_DEPTH_MATERIAL_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/BasicMaterial.hpp>
namespace Nz
{
class NAZARA_GRAPHICS_API DepthMaterial : public BasicMaterial
{
friend class MaterialPipeline;
public:
using BasicMaterial::BasicMaterial;
~DepthMaterial() = default;
static inline const std::shared_ptr<MaterialSettings>& GetSettings();
protected:
static std::vector<std::shared_ptr<UberShader>> BuildShaders();
private:
static bool Initialize();
static void Uninitialize();
static std::shared_ptr<MaterialSettings> s_materialSettings;
};
}
#include <Nazara/Graphics/DepthMaterial.inl>
#endif

View File

@@ -0,0 +1,16 @@
// Copyright (C) 2017 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
#include <Nazara/Graphics/DepthMaterial.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
inline const std::shared_ptr<MaterialSettings>& DepthMaterial::GetSettings()
{
return s_materialSettings;
}
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -9,6 +9,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Graphics/UberShader.hpp>
#include <Nazara/Renderer/RenderPipelineLayout.hpp>
#include <Nazara/Renderer/ShaderModule.hpp>
#include <Nazara/Utility/Enums.hpp>
@@ -19,8 +20,6 @@
namespace Nz
{
class UberShader;
class MaterialSettings
{
public:
@@ -56,6 +55,8 @@ namespace Nz
static constexpr std::size_t InvalidIndex = std::numeric_limits<std::size_t>::max();
static void BuildOption(std::vector<Option>& options, const std::vector<std::shared_ptr<UberShader>>& uberShaders, std::string optionName, const std::string& shaderOptionName);
struct Builder
{
std::vector<std::shared_ptr<UberShader>> shaders;

View File

@@ -165,6 +165,32 @@ namespace Nz
return InvalidIndex;
}
inline void MaterialSettings::BuildOption(std::vector<Option>& options, const std::vector<std::shared_ptr<UberShader>>& uberShaders, std::string optionName, const std::string& shaderOptionName)
{
std::array<UInt64, ShaderStageTypeCount> shaderOptions;
shaderOptions.fill(0);
for (std::size_t i = 0; i < ShaderStageTypeCount; ++i)
{
for (const auto& uberShader : uberShaders)
{
if (uberShader->GetSupportedStages() & static_cast<ShaderStageType>(i))
{
assert(shaderOptions[i] == 0);
shaderOptions[i] |= uberShader->GetOptionFlagByName(shaderOptionName);
}
}
}
if (std::any_of(shaderOptions.begin(), shaderOptions.end(), [&](UInt64 flags) { return flags != 0; }))
{
options.push_back({
std::move(optionName),
shaderOptions
});
}
}
}
#include <Nazara/Graphics/DebugOff.hpp>