Add new invalid texture/material

This commit is contained in:
2025-07-01 00:18:49 -04:00
parent 799ab9a307
commit f5603840a6
5 changed files with 39 additions and 6 deletions

BIN
src/assets/invalid.png LFS Normal file

Binary file not shown.

View File

@@ -5,6 +5,7 @@
#include "Material.hpp"
#include "EngineContext.hpp"
#include "assets/stores.hpp"
#include "engine/assets/texture/Texture.hpp"
#include "engine/descriptors/DescriptorSet.hpp"
#include "engine/utility/IDPool.hpp"
@@ -52,6 +53,19 @@ namespace fgl::engine
return data;
}
MaterialProperties::MaterialProperties()
{
Sampler sampler {};
std::shared_ptr< Texture > texture { getTextureStore().load( "assets/invalid.png", std::move( sampler ) ) };
//Prepare the texture into the global system
Texture::getDescriptorSet().bindTexture( 0, texture );
Texture::getDescriptorSet().update();
if ( !this->pbr.color_tex ) this->pbr.color_tex = texture;
}
Material::Material() : m_id( material_id_counter.getID() )
{
auto& descriptor_set { getDescriptorSet() };
@@ -85,6 +99,16 @@ namespace fgl::engine
return std::shared_ptr< Material >( new Material() );
}
std::shared_ptr< Material > Material::createNullMaterial()
{
//TODO: Make this a special material that will be rendered properly inside of the editor to represent no material was set
auto mat { std::shared_ptr< Material >( new Material() ) };
mat->update();
return mat;
}
Material::~Material()
{
log::debug( "Destroyed material {}", m_id );

View File

@@ -44,7 +44,7 @@ namespace fgl::engine
{
struct
{
std::shared_ptr< Texture > color_tex;
std::shared_ptr< Texture > color_tex {};
glm::vec4 color_factors { 0.0f };
std::shared_ptr< Texture > metallic_roughness_tex;
@@ -72,6 +72,8 @@ namespace fgl::engine
void writeData( DeviceMaterialData& data ) const;
DeviceMaterialData data() const;
MaterialProperties();
};
using MaterialID = std::uint32_t;
@@ -168,6 +170,7 @@ namespace fgl::engine
MaterialID getID() const;
static std::shared_ptr< Material > createMaterial();
static std::shared_ptr< Material > createNullMaterial();
~Material();

View File

@@ -546,10 +546,14 @@ namespace fgl::engine
loadMaterial( const tinygltf::Primitive& prim, const tinygltf::Model& root )
{
const auto& material_id { prim.material };
const auto& gltf_material { root.materials[ material_id ] };
// No material
if ( material_id == -1 ) return Material::createNullMaterial();
auto material { Material::createMaterial() };
const auto& gltf_material { root.materials[ material_id ] };
{
const auto& metallic_roughness { gltf_material.pbrMetallicRoughness };
const auto& pbr_tex_id { metallic_roughness.baseColorTexture.index };

View File

@@ -4,12 +4,9 @@
#include "Texture.hpp"
#include <initializer_list>
#include "engine/FrameInfo.hpp"
#include "engine/assets/image/Image.hpp"
#include "engine/assets/image/ImageView.hpp"
#include "engine/assets/transfer/TransferManager.hpp"
#include "engine/debug/logging/logging.hpp"
#include "engine/descriptors/DescriptorSet.hpp"
#include "engine/math/noise/perlin/generator.hpp"
@@ -32,7 +29,9 @@ namespace fgl::engine
loadTexture( const std::filesystem::path& path, Sampler&& sampler, vk::Format format = vk::Format::eUndefined )
{
ZoneScoped;
if ( !std::filesystem::exists( path ) ) throw std::runtime_error( "Failed to open file: " + path.string() );
if ( !std::filesystem::exists( path ) )
throw std::
runtime_error( std::format( "Failed to open file: {}", std::filesystem::absolute( path ).string() ) );
//TODO: More robust image loading. I should be checking what channels images have and what they are using for their bits per channel.
if ( format == vk::Format::eUndefined ) format = vk::Format::eR8G8B8A8Unorm;