diff --git a/runtime/RHI/Vulkan/Vulkan_FidelityFX.cpp b/runtime/RHI/Vulkan/Vulkan_FidelityFX.cpp index f55c21599..4cfc3e400 100644 --- a/runtime/RHI/Vulkan/Vulkan_FidelityFX.cpp +++ b/runtime/RHI/Vulkan/Vulkan_FidelityFX.cpp @@ -505,7 +505,7 @@ namespace Spartan const uint32_t cascade_resolution = 64; const bool sdf_center_around_camera = true; const float sdf_ray_normal_offset = 0.5f; // distance from a surface along the normal vector to offset the ray origin - below 0.5 I see artifacts - const float sdf_ray_epsilon = 0.1f; // epsilon value for ray marching to be used with brixelizer for rays + const float sdf_ray_epsilon = 0.5f; // epsilon value for ray marching to be used with brixelizer for rays const uint32_t bricks_per_update_max = 1 << 14; // maximum number of bricks to be updated const uint32_t triangle_references_max = 32 * (1 << 20); // maximum number of triangle voxel references to be stored in the update const uint32_t triangle_swap_size = 300 * (1 << 20); // size of the swap space available to be used for storing triangles in the update @@ -553,7 +553,7 @@ namespace Spartan Irradiance, // brixelizer gi Max }; - DebugMode debug_mode = DebugMode::Max; + DebugMode debug_mode = DebugMode::Max; // overwrites light_diffuse_gi render target bool debug_mode_arrow_switch = false; bool debug_mode_aabbs_and_stats = false; bool debug_mode_log_instances = false; diff --git a/runtime/Rendering/Material.cpp b/runtime/Rendering/Material.cpp index d76cef27a..2676134df 100644 --- a/runtime/Rendering/Material.cpp +++ b/runtime/Rendering/Material.cpp @@ -100,7 +100,7 @@ namespace Spartan "The dimensions must be equal" ); - // gltf stores occlusion, roughness and metalness in the same texture, as r, g, b channels respectively + // just like gltf: occlusion, roughness and metalness as r, g, b channels respectively for (size_t i = 0; i < occlusion.size(); i += 4) { output[i + 0] = occlusion[i]; @@ -335,6 +335,18 @@ namespace Spartan RHI_Texture* texture_metalness = GetTexture(MaterialTextureType::Metalness, slot); RHI_Texture* texture_height = GetTexture(MaterialTextureType::Height, slot); + RHI_Texture* reference_texture = texture_color ? texture_color : + texture_alpha_mask ? texture_alpha_mask : + texture_occlusion ? texture_occlusion : + texture_roughness ? texture_roughness : + texture_metalness ? texture_metalness : + texture_height; + + uint32_t reference_width = reference_texture ? reference_texture->GetWidth() : 1; + uint32_t reference_height = reference_texture ? reference_texture->GetHeight() : 1; + uint32_t reference_depth = reference_texture ? reference_texture->GetDepth() : 1; + uint32_t reference_mip_count = reference_texture ? reference_texture->GetMipCount() : 1; + // pack textures { // step 1: pack alpha mask into color alpha @@ -356,43 +368,35 @@ namespace Spartan // step 2: pack occlusion, roughness, metalness, and height into a single texture { // generate unique name by hashing texture IDs - size_t hash_value = 0; - if (texture_occlusion) hash_value ^= texture_occlusion->GetObjectId(); - if (texture_roughness) hash_value ^= texture_roughness->GetObjectId(); - if (texture_metalness) hash_value ^= texture_metalness->GetObjectId(); - if (texture_height) hash_value ^= texture_height->GetObjectId(); - - // fetch the packed texture that corresponds to the hash (in case it was already packed) - const string tex_name = "texture_packed_" + to_string(hash_value); - shared_ptr texture_packed = ResourceCache::GetByName(tex_name); + string tex_name; + { + uint64_t hash = 0; + hash = rhi_hash_combine(hash, static_cast(texture_occlusion ? texture_occlusion->GetObjectId() : 0)); + hash = rhi_hash_combine(hash, static_cast(texture_roughness ? texture_roughness->GetObjectId() : 0)); + hash = rhi_hash_combine(hash, static_cast(texture_metalness ? texture_metalness->GetObjectId() : 0)); + hash = rhi_hash_combine(hash, static_cast(texture_height ? texture_height->GetObjectId() : 0)); + hash = rhi_hash_combine(hash, static_cast(reference_width)); + hash = rhi_hash_combine(hash, static_cast(reference_height)); + + tex_name = "texture_packed_" + to_string(hash); + } + shared_ptr texture_packed = ResourceCache::GetByName(tex_name); if (!texture_packed) { bool textures_are_compressed = (texture_occlusion && texture_occlusion->IsCompressedFormat()) || (texture_roughness && texture_roughness->IsCompressedFormat()) || (texture_metalness && texture_metalness->IsCompressedFormat()) || (texture_height && texture_height->IsCompressedFormat()); - - RHI_Texture* texture_reference = texture_color ? texture_color : - texture_alpha_mask ? texture_alpha_mask : - texture_occlusion ? texture_occlusion : - texture_roughness ? texture_roughness : - texture_metalness ? texture_metalness : - texture_height; - - uint32_t width = texture_reference ? texture_reference->GetWidth() : 1; - uint32_t height = texture_reference ? texture_reference->GetHeight() : 1; - uint32_t depth = texture_reference ? texture_reference->GetDepth() : 1; - uint32_t mip_count = texture_reference ? texture_reference->GetMipCount() : 1; - + // create packed texture texture_packed = make_shared ( RHI_Texture_Type::Type2D, - width, - height, - depth, - mip_count, + reference_width, + reference_height, + reference_depth, + reference_mip_count, RHI_Format::R8G8B8A8_Unorm, RHI_Texture_Srv | RHI_Texture_Compress | RHI_Texture_DontPrepareForGpu, tex_name.c_str() @@ -401,7 +405,7 @@ namespace Spartan texture_packed->AllocateMip(); // create some default data to replace missing textures - const size_t texture_size = width * height * 4; + const size_t texture_size = reference_width * reference_height * 4; vector texture_one(texture_size, static_cast(255)); vector texture_zero(texture_size, static_cast(0)); vector texture_half(texture_size, static_cast(127)); @@ -452,19 +456,19 @@ namespace Spartan } } - // determine if the material is optimized - bool is_optimized = GetTexture(MaterialTextureType::Packed) != nullptr; - for (RHI_Texture* texture : m_textures) - { - if (texture && texture->IsCompressedFormat()) - { - is_optimized = true; - break; - } - } - SetProperty(MaterialProperty::Optimized, is_optimized ? 1.0f : 0.0f); - - m_resource_state = ResourceState::PreparedForGpu; + // determine if the material is optimized + bool is_optimized = GetTexture(MaterialTextureType::Packed) != nullptr; + for (RHI_Texture* texture : m_textures) + { + if (texture && texture->IsCompressedFormat()) + { + is_optimized = true; + break; + } + } + SetProperty(MaterialProperty::Optimized, is_optimized ? 1.0f : 0.0f); + + m_resource_state = ResourceState::PreparedForGpu; }); }