diff --git a/src/assets/invalid.png b/src/assets/invalid.png new file mode 100644 index 0000000..e8b9008 --- /dev/null +++ b/src/assets/invalid.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a98a975d0a53739ffcb54c387359b098ef601c1b5b8dcb4457e52ca4a1c7814d +size 193 diff --git a/src/engine/assets/material/Material.cpp b/src/engine/assets/material/Material.cpp index 669a679..000f882 100644 --- a/src/engine/assets/material/Material.cpp +++ b/src/engine/assets/material/Material.cpp @@ -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 ); diff --git a/src/engine/assets/material/Material.hpp b/src/engine/assets/material/Material.hpp index 3fa0d9b..aa2ec4b 100644 --- a/src/engine/assets/material/Material.hpp +++ b/src/engine/assets/material/Material.hpp @@ -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(); diff --git a/src/engine/assets/model/builders/SceneBuilder.cpp b/src/engine/assets/model/builders/SceneBuilder.cpp index 4c3c2f0..f87e7ad 100644 --- a/src/engine/assets/model/builders/SceneBuilder.cpp +++ b/src/engine/assets/model/builders/SceneBuilder.cpp @@ -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 }; diff --git a/src/engine/assets/texture/Texture.cpp b/src/engine/assets/texture/Texture.cpp index 44cbc9b..870981b 100644 --- a/src/engine/assets/texture/Texture.cpp +++ b/src/engine/assets/texture/Texture.cpp @@ -4,12 +4,9 @@ #include "Texture.hpp" -#include - #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;