3.2 KiB
3.2 KiB
Plan: Implement "Force Lossless" Format for Specific Map Types
Goal: Modify the asset processor to ensure specific map types ("NRM", "DISP") are always saved in a lossless format (PNG or EXR based on bit depth), overriding the JPG threshold and input format rules. This rule should apply to both individually processed maps and merged maps.
Steps:
-
Add Configuration Setting (
config.py):- Introduce a new list named
FORCE_LOSSLESS_MAP_TYPESinconfig.py. - Populate this list:
FORCE_LOSSLESS_MAP_TYPES = ["NRM", "DISP"].
- Introduce a new list named
-
Expose Setting in
ConfigurationClass (configuration.py):- Add a default value for
FORCE_LOSSLESS_MAP_TYPESin the_load_core_configmethod'sdefault_core_settingsdictionary. - Add a new property to the
Configurationclass to access this list:@property def force_lossless_map_types(self) -> list: """Gets the list of map types that must always be saved losslessly.""" return self._core_settings.get('FORCE_LOSSLESS_MAP_TYPES', [])
- Add a default value for
-
Modify
_process_mapsMethod (asset_processor.py):- Locate the section determining the output format (around line 805).
- Before the
if output_bit_depth == 8 and target_dim >= threshold:check (line 811), insert the new logic:- Check if the current
map_typeis inself.config.force_lossless_map_types. - If yes, determine the appropriate lossless format (
pngor configured 16-bit format likeexr) based onoutput_bit_depth, setoutput_format,output_ext,save_params, andneeds_float16accordingly, and skip the subsequentelif/elseblocks for format determination. - Use an
eliffor the existing JPG threshold check and the finalelsefor the rule-based logic, ensuring they only run ifforce_losslessis false.
- Check if the current
-
Modify
_merge_mapsMethod (asset_processor.py):- Locate the section determining the output format for the merged map (around line 1151).
- Before the
if output_bit_depth == 8 and target_dim >= threshold:check (line 1158), insert similar logic as in step 3:- Check if the
output_map_type(the type of the merged map) is inself.config.force_lossless_map_types. - If yes, determine the appropriate lossless format based on the merged map's
output_bit_depth, setoutput_format,output_ext,save_params, andneeds_float16, and skip the subsequentelif/elseblocks. - Use
elifandelsefor the existing threshold and hierarchy logic.
- Check if the
Process Flow Diagram:
graph TD
subgraph Format Determination (per resolution, _process_maps & _merge_maps)
A[Start] --> B(Get map_type / output_map_type);
B --> C{Determine output_bit_depth};
C --> D{Is map_type in FORCE_LOSSLESS_MAP_TYPES?};
D -- Yes --> E[Set format = Lossless (PNG/EXR based on bit_depth)];
D -- No --> F{Is output_bit_depth == 8 AND target_dim >= threshold?};
F -- Yes --> G[Set format = JPG];
F -- No --> H[Set format based on input/hierarchy/rules];
G --> I[Set Save Params];
H --> I;
E --> I;
I --> J[Save Image];
end