Graphics: Fix TextureLoader

This commit is contained in:
SirLynix 2022-09-08 08:56:57 +02:00
parent 72d908817d
commit 7f7ddb415b
3 changed files with 12 additions and 31 deletions

View File

@ -118,34 +118,8 @@ int main()
std::string matPath;
bobMesh->GetMaterialData(i).GetStringParameter(Nz::MaterialData::BaseColorTexturePath, &matPath);
std::shared_ptr<Nz::Material> bobMat = std::make_shared<Nz::Material>();
std::shared_ptr<Nz::MaterialPass> bobMatPass = std::make_shared<Nz::MaterialPass>(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)

View File

@ -29,12 +29,15 @@ namespace Nz
TextureParams texParams;
texParams.renderDevice = Graphics::Instance()->GetRenderDevice();
std::shared_ptr<Texture> texture = Texture::LoadFromStream(stream, {});
std::shared_ptr<Texture> texture = Texture::LoadFromStream(stream, texParams);
if (!texture)
return Err(ResourceLoadingError::Unrecognized);
std::shared_ptr<Material> material = std::make_shared<Material>();
bool hasAlphaTest = false;
parameters.custom.GetBooleanParameter("EnableAlphaTest", &hasAlphaTest);
// ForwardPass
{
std::shared_ptr<MaterialPass> 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<MaterialPass> matPass = std::make_shared<MaterialPass>(DepthMaterial::GetSettings());
matPass->EnableDepthBuffer(true);
if (PixelFormatInfo::HasAlpha(texture->GetFormat()))
if (hasAlphaTest && PixelFormatInfo::HasAlpha(texture->GetFormat()))
{
BasicMaterial depthPass(*matPass);
depthPass.SetBaseColorMap(texture);

View File

@ -6,6 +6,7 @@
#include <Nazara/Graphics/GuillotineTextureAtlas.hpp>
#include <Nazara/Graphics/MaterialPipeline.hpp>
#include <Nazara/Graphics/PredefinedShaderStructs.hpp>
#include <Nazara/Graphics/Formats/TextureLoader.hpp>
#include <Nazara/Utility/Font.hpp>
#include <NZSL/Ast/AstSerializer.hpp>
#include <NZSL/Ast/Module.hpp>
@ -119,6 +120,8 @@ namespace Nz
MaterialPipeline::Initialize();
Font::SetDefaultAtlas(std::make_shared<GuillotineTextureAtlas>(*m_renderDevice));
m_materialLoader.RegisterLoader(Loaders::GetMaterialLoader_Texture()); // texture to material loader
}
Graphics::~Graphics()