From 7f7ddb415b0a01d77bd2cfd2717ac3b3cb3cfa35 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Thu, 8 Sep 2022 08:56:57 +0200 Subject: [PATCH] Graphics: Fix TextureLoader --- examples/Showcase/main.cpp | 30 ++----------------- src/Nazara/Graphics/Formats/TextureLoader.cpp | 10 +++++-- src/Nazara/Graphics/Graphics.cpp | 3 ++ 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/examples/Showcase/main.cpp b/examples/Showcase/main.cpp index 678d16581..890947ef8 100644 --- a/examples/Showcase/main.cpp +++ b/examples/Showcase/main.cpp @@ -118,34 +118,8 @@ int main() std::string matPath; bobMesh->GetMaterialData(i).GetStringParameter(Nz::MaterialData::BaseColorTexturePath, &matPath); - std::shared_ptr bobMat = std::make_shared(); - - std::shared_ptr bobMatPass = std::make_shared(Nz::BasicMaterial::GetSettings()); - - bobMatPass->EnableDepthBuffer(true); - { - std::filesystem::path path(matPath); - //path.replace_extension(".bmp"); - - Nz::BasicMaterial basicMat(*bobMatPass); - if (matPath.find("gob") != matPath.npos) - { - bobMatPass->EnableFlag(Nz::MaterialPassFlag::SortByDistance); - - basicMat.SetAlphaMap(Nz::Texture::LoadFromFile(path, texParams)); - bobMatPass->EnableDepthWrite(false); - - bobMatPass->EnableBlending(true); - bobMatPass->SetBlendEquation(Nz::BlendEquation::Add, Nz::BlendEquation::Add); - bobMatPass->SetBlendFunc(Nz::BlendFunc::SrcAlpha, Nz::BlendFunc::InvSrcAlpha, Nz::BlendFunc::One, Nz::BlendFunc::Zero); - } - else - basicMat.SetBaseColorMap(Nz::Texture::LoadFromFile(path, texParams)); - } - - bobMat->AddPass("ForwardPass", bobMatPass); - - materials[i] = bobMat; + if (!matPath.empty()) + materials[i] = Nz::Material::LoadFromFile(matPath); } for (std::size_t i = 0; i < bobMesh->GetSubMeshCount(); ++i) diff --git a/src/Nazara/Graphics/Formats/TextureLoader.cpp b/src/Nazara/Graphics/Formats/TextureLoader.cpp index b920fbed2..310461d68 100644 --- a/src/Nazara/Graphics/Formats/TextureLoader.cpp +++ b/src/Nazara/Graphics/Formats/TextureLoader.cpp @@ -29,12 +29,15 @@ namespace Nz TextureParams texParams; texParams.renderDevice = Graphics::Instance()->GetRenderDevice(); - std::shared_ptr texture = Texture::LoadFromStream(stream, {}); + std::shared_ptr texture = Texture::LoadFromStream(stream, texParams); if (!texture) return Err(ResourceLoadingError::Unrecognized); std::shared_ptr material = std::make_shared(); + bool hasAlphaTest = false; + parameters.custom.GetBooleanParameter("EnableAlphaTest", &hasAlphaTest); + // ForwardPass { std::shared_ptr matPass; @@ -50,7 +53,7 @@ namespace Nz BasicMaterial forwardPass(*matPass); forwardPass.SetBaseColorMap(texture); - if (PixelFormatInfo::HasAlpha(texture->GetFormat())) + if (hasAlphaTest && PixelFormatInfo::HasAlpha(texture->GetFormat())) forwardPass.EnableAlphaTest(true); material->AddPass("ForwardPass", std::move(matPass)); @@ -59,8 +62,9 @@ namespace Nz // DepthPass { std::shared_ptr matPass = std::make_shared(DepthMaterial::GetSettings()); + matPass->EnableDepthBuffer(true); - if (PixelFormatInfo::HasAlpha(texture->GetFormat())) + if (hasAlphaTest && PixelFormatInfo::HasAlpha(texture->GetFormat())) { BasicMaterial depthPass(*matPass); depthPass.SetBaseColorMap(texture); diff --git a/src/Nazara/Graphics/Graphics.cpp b/src/Nazara/Graphics/Graphics.cpp index 30ed8a285..b5a16961f 100644 --- a/src/Nazara/Graphics/Graphics.cpp +++ b/src/Nazara/Graphics/Graphics.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -119,6 +120,8 @@ namespace Nz MaterialPipeline::Initialize(); Font::SetDefaultAtlas(std::make_shared(*m_renderDevice)); + + m_materialLoader.RegisterLoader(Loaders::GetMaterialLoader_Texture()); // texture to material loader } Graphics::~Graphics()