Skip to content

Commit 902f075

Browse files
gimhaelillwieckz
authored andcommitted
Make top mip-level renormalization an opt-out option
- Make -renormalize work on the top mip-level too. Some tools scale the vectors in normalmaps to maximum length for increased precision, but that breaks reconstruction of the z part in DXN compressed normal maps. Passing -renormalize on compression fixes those textures now. - Make top mip-level renormalization an opt-out option Users can use -renormalize -rtopmip
1 parent c1d8e8d commit 902f075

File tree

5 files changed

+10
-1
lines changed

5 files changed

+10
-1
lines changed

crnlib/crn_mipmapped_texture.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ class mipmapped_texture {
223223
m_wrapping(false),
224224
m_srgb(false),
225225
m_renormalize(false),
226+
m_rtopmip(false),
226227
m_filter_scale(.9f),
227228
m_gamma(1.75f), // or 2.2f
228229
m_multithreaded(true) {
@@ -232,6 +233,7 @@ class mipmapped_texture {
232233
bool m_wrapping;
233234
bool m_srgb;
234235
bool m_renormalize;
236+
bool m_rtopmip;
235237
float m_filter_scale;
236238
float m_gamma;
237239
bool m_multithreaded;

crnlib/crn_texture_comp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ bool create_texture_mipmaps(mipmapped_texture& work_tex, const crn_comp_params&
374374
new_width = math::clamp<int>(new_width, 1, cCRNMaxLevelResolution);
375375
new_height = math::clamp<int>(new_height, 1, cCRNMaxLevelResolution);
376376

377-
if ((new_width != (int)work_tex.get_width()) || (new_height != (int)work_tex.get_height())) {
377+
if ((new_width != (int)work_tex.get_width()) || (new_height != (int)work_tex.get_height()) || (mipmap_params.m_renormalize == true && mipmap_params.m_rtopmip == true)) {
378378
console::info("Resampling input texture to %ux%u", new_width, new_height);
379379

380380
const char* pFilter = crn_get_mip_filter_name(mipmap_params.m_filter);

crnlib/crn_texture_conversion.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ static void print_mipmap_params(const crn_mipmap_params& mipmap_params) {
346346
console::debug("Gamma filtering: %u, Gamma: %2.2f", mipmap_params.m_gamma_filtering, mipmap_params.m_gamma);
347347
console::debug(" Blurriness: %2.2f", mipmap_params.m_blurriness);
348348
console::debug(" Renormalize: %u", mipmap_params.m_renormalize);
349+
console::debug("Renorm. top mip: %u", mipmap_params.m_rtopmip);
349350
console::debug(" Tiled: %u", mipmap_params.m_tiled);
350351
console::debug(" Max Levels: %u", mipmap_params.m_max_levels);
351352
console::debug(" Min level size: %u", mipmap_params.m_min_mip_size);

crunch/crunch.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class crunch {
140140
console::printf("-blurriness # - Scale filter kernel, >1=blur, <1=sharpen, .01-8, default=.9");
141141
console::printf("-wrap - Assume texture is tiled when filtering, default=clamping");
142142
console::printf("-renormalize - Renormalize filtered normal map texels, default=disabled");
143+
console::printf("-rtopmip - Renormalize on the top mip-level too, default=disabled");
143144
console::printf("-maxmips # - Limit number of generated texture mipmap levels, 1-16, default=16");
144145
console::printf("-minmipsize # - Smallest allowable mipmap resolution, default=1");
145146

@@ -208,6 +209,7 @@ class crunch {
208209
{"blurriness", 1, false},
209210
{"wrap", 0, false},
210211
{"renormalize", 0, false},
212+
{ "rtopmip", 0, false },
211213
{"noprogress", 0, false},
212214
{"paramdebug", 0, false},
213215
{"debug", 0, false},
@@ -700,6 +702,7 @@ class crunch {
700702
mip_params.m_blurriness = m_params.get_value_as_float("blurriness", 0, mip_params.m_blurriness, .01f, 8.0f);
701703

702704
mip_params.m_renormalize = m_params.get_value_as_bool("renormalize", 0, mip_params.m_renormalize != 0);
705+
mip_params.m_rtopmip = m_params.get_value_as_bool("rtopmip", 0, mip_params.m_rtopmip != 0);
703706
mip_params.m_tiled = m_params.get_value_as_bool("wrap");
704707

705708
mip_params.m_max_levels = m_params.get_value_as_int("maxmips", 0, cCRNMaxLevels, 1, cCRNMaxLevels);

inc/crnlib.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ struct crn_mipmap_params {
415415
// Default "blurriness" factor of .9 actually sharpens the output a little.
416416
m_blurriness = .9f;
417417
m_renormalize = false;
418+
m_rtopmip = false;
418419
m_tiled = false;
419420
m_max_levels = cCRNMaxLevels;
420421
m_min_mip_size = 1;
@@ -448,6 +449,7 @@ struct crn_mipmap_params {
448449
CRNLIB_COMP(m_gamma);
449450
CRNLIB_COMP(m_blurriness);
450451
CRNLIB_COMP(m_renormalize);
452+
CRNLIB_COMP(m_rtopmip);
451453
CRNLIB_COMP(m_tiled);
452454
CRNLIB_COMP(m_max_levels);
453455
CRNLIB_COMP(m_min_mip_size);
@@ -478,6 +480,7 @@ struct crn_mipmap_params {
478480
crn_uint32 m_min_mip_size;
479481

480482
crn_bool m_renormalize;
483+
crn_bool m_rtopmip;
481484
crn_bool m_tiled;
482485

483486
crn_scale_mode m_scale_mode;

0 commit comments

Comments
 (0)