Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Astc normal maps #493

Merged
merged 36 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
cbddc69
Add first implementation of normal map support
wasimabbas-arm Oct 14, 2021
8e9e39f
Fix astc normal mode and add tests
wasimabbas-arm Oct 19, 2021
96364e0
Update docs
abbaswasim Nov 9, 2021
c989580
Update reference images
abbaswasim Nov 15, 2021
bcebc17
Update reference generator script
abbaswasim Nov 15, 2021
e381b43
Add error message when normal mode is used with non-linear textures
abbaswasim Nov 15, 2021
17799dd
Update docs
abbaswasim Nov 15, 2021
2b63d44
Fix astc normal map tests
abbaswasim Nov 26, 2021
1618ca4
Fix some typos
abbaswasim Nov 29, 2021
a90bb69
Add blank line
abbaswasim Nov 30, 2021
22d0dd1
Add Iron_Bars_001_normal and move normal mode swizzle selection to to…
abbaswasim Dec 17, 2021
ca2d9a2
Rename Iron_Bars_001_normal to be more explicit that its not normalized
abbaswasim Dec 21, 2021
dadacb2
Add normalize option
abbaswasim Dec 21, 2021
f054401
Add normalize support
abbaswasim Dec 21, 2021
9636d90
Add normal map .png versions
abbaswasim Dec 21, 2021
4c00a18
Normal map support for different types (uint8, uint16, float32 etc, f…
abbaswasim Dec 23, 2021
1376f77
Change basisu::clamp to cclamp
abbaswasim Dec 29, 2021
d92aa03
Minor documentation changes, remove separateRGToRGBA_A from basis opt…
abbaswasim Feb 4, 2022
0140218
Add normalisation tests
abbaswasim Feb 7, 2022
4ec4dac
Add normal_mode tests for uastc and etc1s
abbaswasim Feb 7, 2022
07b9a46
Corrects documentation
abbaswasim Feb 7, 2022
4c52f30
Corrects documentation
abbaswasim Feb 7, 2022
b43c1df
Remove useless messages from astc-encode
abbaswasim Feb 7, 2022
812bd2b
Change unittests.cpp to image_unittests.cc
abbaswasim Feb 8, 2022
a3f67c4
Add --normalize to normal tests
abbaswasim Feb 8, 2022
edc6b73
Fix writerScParams issues, now correctly encodes encoder params
abbaswasim Feb 8, 2022
dc29f3d
Change golden images after writerScParams bug fix
abbaswasim Feb 8, 2022
7e1384b
Merge branch 'KhronosGroup:master' into astc_normal_maps
wasimabbas-arm Feb 8, 2022
c44f03f
Add space after @b
abbaswasim Feb 8, 2022
a883d71
Fix normalize and normal_mode documentation
abbaswasim Feb 9, 2022
e6d7458
Allow inputSwizzle to be set for normal maps.
abbaswasim Feb 9, 2022
b85772a
Move normal mode swizzle selection to astc_encode and basis_encode
abbaswasim Feb 9, 2022
04f9cb5
Update reference images
abbaswasim Feb 9, 2022
d10c7ce
Fix inputSwizzle and normalSwizzle
abbaswasim Feb 15, 2022
3939a12
Refactor and formating fixes
abbaswasim Feb 15, 2022
2bba286
Limit etc1s test to apple
abbaswasim Feb 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions include/ktx.h
Original file line number Diff line number Diff line change
Expand Up @@ -1301,12 +1301,8 @@ typedef struct ktxBasisParams {
selector RDO, no endpoint RDO). Only valid for linear textures.
*/
ktx_bool_t separateRGToRGB_A;
/*!< Separates the input R and G channels to RGB and A (for tangent
space XY normal maps). Equivalent to @c inputSwizzle "rrrg".
Separation is the default for 2 component textures. If both this
and inputSwizzle are set, the latter wins therefore set
@c inputSwizzle to change the default for 2 component
textures.
/*!< @deprecated. This was and is a no-op. 2-component inputs have always been
automatically separated using an "rrrg" inputSwizzle. @sa inputSwizzle and normalMode.
*/
ktx_bool_t preSwizzle;
/*!< If the texture has @c KTXswizzle metadata, apply it before
Expand Down
15 changes: 2 additions & 13 deletions lib/astc_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ static ktxAstcParams
astcDefaultOptions() {
ktxAstcParams params{};
params.structSize = sizeof(params);
params.verbose = false;
params.threadCount = 1;
params.blockDimension = KTX_PACK_ASTC_BLOCK_DIMENSION_6x6;
params.mode = KTX_PACK_ASTC_ENCODER_MODE_LDR;
Expand Down Expand Up @@ -619,18 +618,14 @@ ktxTexture2_CompressAstcEx(ktxTexture2* This, ktxAstcParams* params) {
quality, flags,
&astc_config);

if (astc_error != ASTCENC_SUCCESS) {
std::cout << "ASTC config init failed with error " << astcenc_get_error_string(astc_error) << std::endl;
if (astc_error != ASTCENC_SUCCESS)
return KTX_INVALID_OPERATION;
}

astc_error = astcenc_context_alloc(&astc_config, threadCount,
&astc_context);

if (astc_error != ASTCENC_SUCCESS) {
std::cout << "ASTC context alloc failed with error " << astcenc_get_error_string(astc_error) << std::endl;
if (astc_error != ASTCENC_SUCCESS)
return KTX_INVALID_OPERATION;
}

// Walk in reverse on levels so we don't have to do this later
assert(prototype->dataSize && "Prototype texture size not initialized.\n");
Expand All @@ -657,12 +652,6 @@ ktxTexture2_CompressAstcEx(ktxTexture2* This, ktxAstcParams* params) {
ktx_size_t offset = ktxTexture2_levelDataOffset(This, level);

for (uint32_t image = 0; image < levelImages; image++) {
if (params->verbose)
std::cout << "ASTC compressor: compressing image " <<
(This->numLevels - level - 1) * levelImages + image + 1
<< " of " << This->numLevels * levelImages
<< std::endl;

astcenc_image *input_image = nullptr;
if (num_components == 1)
input_image = unorm8x1ArrayToImage(This->pData + offset,
Expand Down
6 changes: 0 additions & 6 deletions lib/basis_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,6 @@ static bool basisuEncoderInitialized = false;
* @exception KTX_INVALID_OPERATION
* The texture image format's component size is not 8-bits.
* @exception KTX_INVALID_OPERATION
* @c separateRGToRGB_A is specified but the texture
* has only 1 component.
* @exception KTX_INVALID_OPERATION
* Both preSwizzle and and inputSwizzle are specified
* in @a params.
* @exception KTX_OUT_OF_MEMORY Not enough memory to carry out compression.
Expand Down Expand Up @@ -426,9 +423,6 @@ ktxTexture2_CompressBasisEx(ktxTexture2* This, ktxBasisParams* params)
if (component_size != 1)
return KTX_INVALID_OPERATION; // Basis must have 8-bit components.

if (params->separateRGToRGB_A && num_components == 1)
return KTX_INVALID_OPERATION;

if (This->pData == NULL) {
result = ktxTexture2_LoadImageData(This, NULL, 0);
if (result != KTX_SUCCESS)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/testimages/astc_ldr_10x5_FlightHelmet_baseColor.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_ldr_12x10_FlightHelmet_baseColor.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_ldr_12x12_FlightHelmet_baseColor.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_ldr_4x4_FlightHelmet_baseColor.ktx2
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/testimages/astc_ldr_5x4_Iron_Bars_001_normal.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_ldr_6x5_FlightHelmet_baseColor.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_ldr_6x6_3dtex_7.ktx2
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/testimages/astc_ldr_6x6_Iron_Bars_001_normal.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_ldr_6x6_arraytex_7.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_ldr_6x6_arraytex_7_mipmap.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_ldr_6x6_posx.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_ldr_8x6_FlightHelmet_baseColor.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_ldr_8x8_FlightHelmet_baseColor.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_ldr_cubemap_6x6.ktx2
Git LFS file not shown
2 changes: 1 addition & 1 deletion tests/testimages/astc_mipmap_ldr_10x5_posx.ktx2
Git LFS file not shown
2 changes: 1 addition & 1 deletion tests/testimages/astc_mipmap_ldr_12x10_posx.ktx2
Git LFS file not shown
2 changes: 1 addition & 1 deletion tests/testimages/astc_mipmap_ldr_12x12_posx.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_mipmap_ldr_4x4_posx.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_mipmap_ldr_6x5_posx.ktx2
Git LFS file not shown
2 changes: 1 addition & 1 deletion tests/testimages/astc_mipmap_ldr_6x6_kodim17_fast.ktx2
Git LFS file not shown
2 changes: 1 addition & 1 deletion tests/testimages/astc_mipmap_ldr_6x6_kodim17_fastest.ktx2
Git LFS file not shown
2 changes: 1 addition & 1 deletion tests/testimages/astc_mipmap_ldr_6x6_kodim17_medium.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_mipmap_ldr_6x6_posx.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_mipmap_ldr_6x6_posy.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_mipmap_ldr_6x6_posz.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_mipmap_ldr_8x6_posx.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_mipmap_ldr_8x8_posx.ktx2
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testimages/astc_mipmap_ldr_cubemap_6x6.ktx2
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/testimages/etc1s_Iron_Bars_001_normal.ktx2
Git LFS file not shown
5 changes: 5 additions & 0 deletions tests/testimages/genref
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ $toktx --nowarn --t2 --test --input_swizzle 0rr1 --target_type RGBA cyan_rgba_re
$toktx --nowarn --t2 --test --input_swizzle 0rr1 --target_type RGBA --bcmp cyan_rgb_reference_basis.ktx2 ../srcimages/level0.ppm
$toktx --nowarn --t2 --test --input_swizzle 0rr1 --target_type RGBA --uastc -- cyan_rgb_reference_uastc.ktx2 ../srcimages/level0.ppm

$toktx --nowarn --t2 --test --assign_oetf linear --normalize --normal_mode --encode uastc uastc_Iron_Bars_001_normal.ktx2 ../srcimages/Iron_Bars/Iron_Bars_001_normal_unnormalized.png
$toktx --nowarn --t2 --test --assign_oetf linear --normalize --normal_mode --encode etc1s etc1s_Iron_Bars_001_normal.ktx2 ../srcimages/Iron_Bars/Iron_Bars_001_normal_unnormalized.png

# ... and additional files for the load tests.

$toktx --lower_left_maps_to_s0t0 rgb-reference-metadata.ktx ../srcimages/rgb.ppm
Expand Down Expand Up @@ -122,6 +125,8 @@ $toktx --test --encode astc --astc_blk_d 10x5 astc_ldr_10x5_FlightHelmet_baseC
$toktx --test --encode astc --astc_blk_d 8x8 astc_ldr_8x8_FlightHelmet_baseColor.ktx2 ../srcimages/FlightHelmet_baseColor.png
$toktx --test --encode astc --astc_blk_d 12x10 astc_ldr_12x10_FlightHelmet_baseColor.ktx2 ../srcimages/FlightHelmet_baseColor.png
$toktx --test --encode astc --astc_blk_d 12x12 astc_ldr_12x12_FlightHelmet_baseColor.ktx2 ../srcimages/FlightHelmet_baseColor.png
$toktx --test --assign_oetf linear --normalize --normal_mode --encode astc --astc_blk_d 6x6 astc_ldr_6x6_Iron_Bars_001_normal.ktx2 ../srcimages/Iron_Bars/Iron_Bars_001_normal_unnormalized.png
$toktx --test --assign_oetf linear --normalize --normal_mode --encode astc --astc_blk_d 5x4 astc_ldr_5x4_Iron_Bars_001_normal.ktx2 ../srcimages/Iron_Bars/Iron_Bars_001_normal_unnormalized.png

$toktx --test --layers 7 --encode astc --astc_blk_d 6x6 astc_ldr_6x6_arraytex_7.ktx2 ../srcimages/red16.png ../srcimages/orange16.png ../srcimages/yellow16.png ../srcimages/green16.png ../srcimages/blue16.png ../srcimages/indigo16.png ../srcimages/violet16.png
$toktx --test --layers 7 --encode astc --astc_blk_d 6x6 --genmipmap astc_ldr_6x6_arraytex_7_mipmap.ktx2 ../srcimages/red16.png ../srcimages/orange16.png ../srcimages/yellow16.png ../srcimages/green16.png ../srcimages/blue16.png ../srcimages/indigo16.png ../srcimages/violet16.png
Expand Down
3 changes: 3 additions & 0 deletions tests/testimages/uastc_Iron_Bars_001_normal.ktx2
Git LFS file not shown
2 changes: 2 additions & 0 deletions tests/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_subdirectory(streamtests)

add_executable( unittests
unittests/unittests.cc
unittests/image_unittests.cc
unittests/wthelper.h
)

Expand All @@ -23,6 +24,7 @@ target_include_directories(
PRIVATE
$<TARGET_PROPERTY:ktx,INCLUDE_DIRECTORIES>
${PROJECT_SOURCE_DIR}/lib
${PROJECT_SOURCE_DIR}/tools
)

target_link_libraries(
Expand Down
4 changes: 4 additions & 0 deletions tests/toktx-tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ gencmpktx( swizzle_r_to_gb_convert_to_rgba_u cyan_rgba_reference_u.ktx2 ../srcim
gencmpktx( swizzle_r_to_gb_convert_to_rgba_basis cyan_rgb_reference_basis.ktx2 ../srcimages/level0.ppm "--nowarn --t2 --test --input_swizzle 0rr1 --target_type RGBA --bcmp" "" "" )
gencmpktx( swizzle_r_to_gb_convert_to_rgba_uastc cyan_rgb_reference_uastc.ktx2 ../srcimages/level0.ppm "--nowarn --t2 --test --input_swizzle 0rr1 --target_type RGBA --uastc --" "" "" )

gencmpktx( uastc_Iron_Bars_001_normal uastc_Iron_Bars_001_normal.ktx2 ../srcimages/Iron_Bars/Iron_Bars_001_normal_unnormalized.png "--test --assign_oetf linear --normalize --normal_mode --encode uastc" "" "")
gencmpktx( etc1s_Iron_Bars_001_normal etc1s_Iron_Bars_001_normal.ktx2 ../srcimages/Iron_Bars/Iron_Bars_001_normal_unnormalized.png "--test --assign_oetf linear --normalize --normal_mode --encode etc1s" "" "")

gencmpktx( gAMA_chunk_png g03n2c08.ktx2 ../srcimages/g03n2c08.png "--test --t2" "" "" )
gencmpktx( cHRM_chunk_png ccwn2c08.ktx2 ../srcimages/ccwn2c08.png "--test --t2" "" "" )
Expand Down Expand Up @@ -238,6 +240,8 @@ gencmpktx( astc_ldr_10x5_FlightHelmet_baseColor astc_ldr_10x5_FlightHelmet_bas
gencmpktx( astc_ldr_8x8_FlightHelmet_baseColor astc_ldr_8x8_FlightHelmet_baseColor.ktx2 ../srcimages/FlightHelmet_baseColor.png "--test --encode astc --astc_blk_d 8x8" "" "")
gencmpktx( astc_ldr_12x10_FlightHelmet_baseColor astc_ldr_12x10_FlightHelmet_baseColor.ktx2 ../srcimages/FlightHelmet_baseColor.png "--test --encode astc --astc_blk_d 12x10" "" "")
gencmpktx( astc_ldr_12x12_FlightHelmet_baseColor astc_ldr_12x12_FlightHelmet_baseColor.ktx2 ../srcimages/FlightHelmet_baseColor.png "--test --encode astc --astc_blk_d 12x12" "" "")
gencmpktx( astc_ldr_6x6_Iron_Bars_001_normal astc_ldr_6x6_Iron_Bars_001_normal.ktx2 ../srcimages/Iron_Bars/Iron_Bars_001_normal_unnormalized.png "--test --assign_oetf linear --normalize --normal_mode --encode astc --astc_blk_d 6x6" "" "")
gencmpktx( astc_ldr_5x4_Iron_Bars_001_normal astc_ldr_5x4_Iron_Bars_001_normal.ktx2 ../srcimages/Iron_Bars/Iron_Bars_001_normal_unnormalized.png "--test --assign_oetf linear --normalize --normal_mode --encode astc --astc_blk_d 5x4" "" "")

gencmpktx( astc_ldr_6x6_arraytex_7 astc_ldr_6x6_arraytex_7.ktx2 "../srcimages/red16.png ../srcimages/orange16.png ../srcimages/yellow16.png ../srcimages/green16.png ../srcimages/blue16.png ../srcimages/indigo16.png ../srcimages/violet16.png" "--test --layers 7 --encode astc --astc_blk_d 6x6" "" "")
gencmpktx( astc_ldr_6x6_arraytex_7_mipmap astc_ldr_6x6_arraytex_7_mipmap.ktx2 "../srcimages/red16.png ../srcimages/orange16.png ../srcimages/yellow16.png ../srcimages/green16.png ../srcimages/blue16.png ../srcimages/indigo16.png ../srcimages/violet16.png" "--test --layers 7 --encode astc --astc_blk_d 6x6 --genmipmap" "" "")
Expand Down
Loading