From 56cfde3a5ca1ad46015cdf2d81979b6c6b55dd93 Mon Sep 17 00:00:00 2001 From: cow-neaz Date: Mon, 4 Jul 2022 22:35:22 +0300 Subject: [PATCH] Fix Basic Universal compressing with normal maps. --- modules/basis_universal/register_types.cpp | 55 ++++++++++++---------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/modules/basis_universal/register_types.cpp b/modules/basis_universal/register_types.cpp index 3eb0dc96311..86f3385ae33 100644 --- a/modules/basis_universal/register_types.cpp +++ b/modules/basis_universal/register_types.cpp @@ -58,32 +58,7 @@ static Vector basis_universal_packer(const Ref &p_image, Image:: if (image->get_format() != Image::FORMAT_RGBA8) { image->convert(Image::FORMAT_RGBA8); } - if (!image->has_mipmaps()) { - basisu::image buimg(image->get_width(), image->get_height()); - Vector vec = image->get_data(); - const uint8_t *r = vec.ptr(); - memcpy(buimg.get_ptr(), r, vec.size()); - params.m_source_images.push_back(buimg); - } else { - { - Ref base_image = image->get_image_from_mipmap(0); - Vector image_vec = base_image->get_data(); - basisu::image buimg_image(base_image->get_width(), base_image->get_height()); - const uint8_t *r = image_vec.ptr(); - memcpy(buimg_image.get_ptr(), r, image_vec.size()); - params.m_source_images.push_back(buimg_image); - } - basisu::vector images; - for (int32_t mip_map_i = 1; mip_map_i <= image->get_mipmap_count(); mip_map_i++) { - Ref mip_map = image->get_image_from_mipmap(mip_map_i); - Vector mip_map_vec = mip_map->get_data(); - basisu::image buimg_mipmap(mip_map->get_width(), mip_map->get_height()); - const uint8_t *r = mip_map_vec.ptr(); - memcpy(buimg_mipmap.get_ptr(), r, mip_map_vec.size()); - images.push_back(buimg_mipmap); - } - params.m_source_mipmap_images.push_back(images); - } + params.m_uastc = true; params.m_quality_level = basisu::BASISU_QUALITY_MIN; @@ -117,6 +92,7 @@ static Vector basis_universal_packer(const Ref &p_image, Image:: } break; case Image::USED_CHANNELS_RG: { #ifdef USE_RG_AS_RGBA + params.m_force_alpha = true; image->convert_rg_to_ra_rgba8(); decompress_format = BASIS_DECOMPRESS_RG_AS_RA; #else @@ -133,6 +109,33 @@ static Vector basis_universal_packer(const Ref &p_image, Image:: } break; } + if (!image->has_mipmaps()) { + basisu::image buimg(image->get_width(), image->get_height()); + Vector vec = image->get_data(); + const uint8_t *r = vec.ptr(); + memcpy(buimg.get_ptr(), r, vec.size()); + params.m_source_images.push_back(buimg); + } else { + { + Ref base_image = image->get_image_from_mipmap(0); + Vector image_vec = base_image->get_data(); + basisu::image buimg_image(base_image->get_width(), base_image->get_height()); + const uint8_t *r = image_vec.ptr(); + memcpy(buimg_image.get_ptr(), r, image_vec.size()); + params.m_source_images.push_back(buimg_image); + } + basisu::vector images; + for (int32_t mip_map_i = 1; mip_map_i <= image->get_mipmap_count(); mip_map_i++) { + Ref mip_map = image->get_image_from_mipmap(mip_map_i); + Vector mip_map_vec = mip_map->get_data(); + basisu::image buimg_mipmap(mip_map->get_width(), mip_map->get_height()); + const uint8_t *r = mip_map_vec.ptr(); + memcpy(buimg_mipmap.get_ptr(), r, mip_map_vec.size()); + images.push_back(buimg_mipmap); + } + params.m_source_mipmap_images.push_back(images); + } + basisu::basis_compressor c; c.init(params);