Graphics: Add default materials
This commit is contained in:
parent
7f7ddb415b
commit
99c9df5731
|
|
@ -123,7 +123,11 @@ int main()
|
|||
}
|
||||
|
||||
for (std::size_t i = 0; i < bobMesh->GetSubMeshCount(); ++i)
|
||||
bobModel->SetMaterial(i, materials[bobMesh->GetSubMesh(i)->GetMaterialIndex()]);
|
||||
{
|
||||
std::size_t matIndex = bobMesh->GetSubMesh(i)->GetMaterialIndex();
|
||||
if (materials[matIndex])
|
||||
bobModel->SetMaterial(i, materials[matIndex]);
|
||||
}
|
||||
|
||||
/*for (std::size_t y = 0; y < 10; ++y)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ namespace Nz
|
|||
using Dependencies = TypeList<Renderer>;
|
||||
|
||||
struct Config;
|
||||
struct DefaultMaterials;
|
||||
struct DefaultTextures;
|
||||
|
||||
Graphics(Config config);
|
||||
|
|
@ -38,6 +39,7 @@ namespace Nz
|
|||
|
||||
inline const std::shared_ptr<RenderPipeline>& GetBlitPipeline(bool transparent) const;
|
||||
inline const std::shared_ptr<RenderPipelineLayout>& GetBlitPipelineLayout() const;
|
||||
inline const DefaultMaterials& GetDefaultMaterials() const;
|
||||
inline const DefaultTextures& GetDefaultTextures() const;
|
||||
inline MaterialPassRegistry& GetMaterialPassRegistry();
|
||||
inline const MaterialPassRegistry& GetMaterialPassRegistry() const;
|
||||
|
|
@ -55,6 +57,12 @@ namespace Nz
|
|||
bool useDedicatedRenderDevice = true;
|
||||
};
|
||||
|
||||
struct DefaultMaterials
|
||||
{
|
||||
std::shared_ptr<Material> depthMaterial;
|
||||
std::shared_ptr<Material> noDepthMaterial;
|
||||
};
|
||||
|
||||
struct DefaultTextures
|
||||
{
|
||||
std::array<std::shared_ptr<Texture>, ImageTypeCount> whiteTextures;
|
||||
|
|
@ -62,6 +70,7 @@ namespace Nz
|
|||
|
||||
private:
|
||||
void BuildBlitPipeline();
|
||||
void BuildDefaultMaterials();
|
||||
void BuildDefaultTextures();
|
||||
void RegisterMaterialPasses();
|
||||
void RegisterShaderModules();
|
||||
|
|
@ -75,6 +84,7 @@ namespace Nz
|
|||
std::shared_ptr<RenderPipeline> m_blitPipeline;
|
||||
std::shared_ptr<RenderPipeline> m_blitPipelineTransparent;
|
||||
std::shared_ptr<RenderPipelineLayout> m_blitPipelineLayout;
|
||||
DefaultMaterials m_defaultMaterials;
|
||||
DefaultTextures m_defaultTextures;
|
||||
MaterialLoader m_materialLoader;
|
||||
MaterialPassRegistry m_materialPassRegistry;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,11 @@ namespace Nz
|
|||
return m_blitPipelineLayout;
|
||||
}
|
||||
|
||||
inline auto Graphics::GetDefaultMaterials() const -> const DefaultMaterials&
|
||||
{
|
||||
return m_defaultMaterials;
|
||||
}
|
||||
|
||||
inline auto Graphics::GetDefaultTextures() const -> const DefaultTextures&
|
||||
{
|
||||
return m_defaultTextures;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/Graphics.hpp>
|
||||
#include <Nazara/Graphics/BasicMaterial.hpp>
|
||||
#include <Nazara/Graphics/DepthMaterial.hpp>
|
||||
#include <Nazara/Graphics/GuillotineTextureAtlas.hpp>
|
||||
#include <Nazara/Graphics/MaterialPipeline.hpp>
|
||||
#include <Nazara/Graphics/PredefinedShaderStructs.hpp>
|
||||
|
|
@ -118,6 +120,7 @@ namespace Nz
|
|||
SelectDepthStencilFormats();
|
||||
|
||||
MaterialPipeline::Initialize();
|
||||
BuildDefaultMaterials();
|
||||
|
||||
Font::SetDefaultAtlas(std::make_shared<GuillotineTextureAtlas>(*m_renderDevice));
|
||||
|
||||
|
|
@ -156,7 +159,8 @@ namespace Nz
|
|||
m_samplerCache.reset();
|
||||
m_blitPipeline.reset();
|
||||
m_blitPipelineLayout.reset();
|
||||
m_defaultTextures.whiteTextures.fill(nullptr);
|
||||
m_defaultMaterials = DefaultMaterials{};
|
||||
m_defaultTextures = DefaultTextures{};
|
||||
}
|
||||
|
||||
void Graphics::BuildBlitPipeline()
|
||||
|
|
@ -202,6 +206,27 @@ namespace Nz
|
|||
m_blitPipelineTransparent = m_renderDevice->InstantiateRenderPipeline(std::move(pipelineInfo));
|
||||
}
|
||||
|
||||
void Graphics::BuildDefaultMaterials()
|
||||
{
|
||||
m_defaultMaterials.depthMaterial = std::make_shared<Material>();
|
||||
{
|
||||
std::shared_ptr<Nz::MaterialPass> depthPass = std::make_shared<Nz::MaterialPass>(Nz::DepthMaterial::GetSettings());
|
||||
depthPass->EnableDepthBuffer(true);
|
||||
|
||||
m_defaultMaterials.depthMaterial->AddPass("DepthPass", depthPass);
|
||||
|
||||
std::shared_ptr<Nz::MaterialPass> forwardPass = std::make_shared<Nz::MaterialPass>(Nz::BasicMaterial::GetSettings());
|
||||
forwardPass->EnableDepthBuffer(true);
|
||||
|
||||
m_defaultMaterials.depthMaterial->AddPass("ForwardPass", forwardPass);
|
||||
}
|
||||
|
||||
m_defaultMaterials.noDepthMaterial = std::make_shared<Material>();
|
||||
{
|
||||
m_defaultMaterials.noDepthMaterial->AddPass("ForwardPass", std::make_shared<Nz::MaterialPass>(Nz::BasicMaterial::GetSettings()));
|
||||
}
|
||||
}
|
||||
|
||||
void Graphics::BuildDefaultTextures()
|
||||
{
|
||||
// White texture 2D
|
||||
|
|
|
|||
|
|
@ -17,11 +17,13 @@ namespace Nz
|
|||
Model::Model(std::shared_ptr<GraphicalMesh> graphicalMesh, const Boxf& aabb) :
|
||||
m_graphicalMesh(std::move(graphicalMesh))
|
||||
{
|
||||
Graphics* graphics = Graphics::Instance();
|
||||
|
||||
m_submeshes.reserve(m_graphicalMesh->GetSubMeshCount());
|
||||
for (std::size_t i = 0; i < m_graphicalMesh->GetSubMeshCount(); ++i)
|
||||
{
|
||||
auto& subMeshData = m_submeshes.emplace_back();
|
||||
//subMeshData.material = DefaultMaterial; //< TODO
|
||||
subMeshData.material = graphics->GetDefaultMaterials().depthMaterial;
|
||||
subMeshData.vertexBufferData = {
|
||||
{
|
||||
0,
|
||||
|
|
|
|||
Loading…
Reference in New Issue