From 1ad054b86e0f473e0901b69d9cdf8d78e0ee1d92 Mon Sep 17 00:00:00 2001 From: Panos Karabelas Date: Wed, 13 Nov 2024 19:32:15 +0000 Subject: [PATCH] [material] some more work towards texture packing --- data/shaders/common_textures_storage.hlsl | 1 + runtime/Rendering/Material.cpp | 45 +++++++++++++++++------ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/data/shaders/common_textures_storage.hlsl b/data/shaders/common_textures_storage.hlsl index 7c15bdd07..05999c311 100644 --- a/data/shaders/common_textures_storage.hlsl +++ b/data/shaders/common_textures_storage.hlsl @@ -75,6 +75,7 @@ static const uint material_texture_index_occlusion = 4 * material_texture_type_s static const uint material_texture_index_emission = 5 * material_texture_type_slots_max; static const uint material_texture_index_height = 6 * material_texture_type_slots_max; static const uint material_texture_index_mask = 7 * material_texture_type_slots_max; +static const uint material_texture_index_packed = 8 * material_texture_type_slots_max; // easy access macro #define GET_TEXTURE(index_texture) tex_materials[pass_get_material_index() + index_texture] diff --git a/runtime/Rendering/Material.cpp b/runtime/Rendering/Material.cpp index 8d3b0eabc..ec4fc1cfe 100644 --- a/runtime/Rendering/Material.cpp +++ b/runtime/Rendering/Material.cpp @@ -25,7 +25,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "../Resource/ResourceCache.h" #include "../RHI/RHI_Texture.h" #include "../World/World.h" -#include "../Core/ThreadPool.h" SP_WARNINGS_OFF #include "../IO/pugixml.hpp" SP_WARNINGS_ON @@ -85,14 +84,13 @@ namespace Spartan namespace texture_packing { void pack_occlusion_roughness_metalness_height( - vector& occlusion, + const vector& occlusion, const vector& roughness, const vector& metalness, - const vector& height + const vector& height, + vector& output ) { - vector& output = occlusion; - size_t size = max(max(occlusion.size(), roughness.size()), max(metalness.size(), height.size())); for (size_t i = 0; i < size; i += 4) { @@ -349,16 +347,39 @@ namespace Spartan // step 2: pack occlusion, roughness, metalness, and height into a single texture { - //vector empty; - //RHI_Texture* texture = nullptr; + //// try to get the texture (in case it's already packed) + //const string tex_name = GetObjectName() + "_packed"; + //shared_ptr texture = ResourceCache::GetByName(tex_name); // - //texture_packing::pack_occlusion_roughness_metalness_height( - // texture_occlusion ? texture_occlusion->GetMip(0, 0).bytes : empty, - // texture_roughness ? texture_roughness->GetMip(0, 0).bytes : empty, - // texture_metalness ? texture_metalness->GetMip(0, 0).bytes : empty, - // texture_height ? texture_height->GetMip(0, 0).bytes : empty + //if (!texture) + //{ + // // create packed texture + // texture = make_shared + // ( + // RHI_Texture_Type::Type2D, + // texture_color->GetWidth(), + // texture_color->GetHeight(), + // texture_color->GetDepth(), + // texture_color->GetMipCount(), + // texture_color->GetFormat(), + // RHI_Texture_Srv | RHI_Texture_Compress | RHI_Texture_DontPrepareForGpu, + // "packed" // ); + // texture->AllocateMip(); + // ResourceCache::Cache(texture); + // + // // create packed data + // vector empty; + // texture_packing::pack_occlusion_roughness_metalness_height( + // texture_occlusion ? texture_occlusion->GetMip(0, 0).bytes : empty, + // texture_roughness ? texture_roughness->GetMip(0, 0).bytes : empty, + // texture_metalness ? texture_metalness->GetMip(0, 0).bytes : empty, + // texture_height ? texture_height->GetMip(0, 0).bytes : empty, + // texture->GetMip(0, 0).bytes + // ); + //} // + //// set the packed texture //SetTexture(MaterialTextureType::Packed, texture); //SetTexture(MaterialTextureType::Occlusion, nullptr); //SetTexture(MaterialTextureType::Roughness, nullptr);