3.5 KiB
3.5 KiB
Ticket: FEAT-011 - Implement Power-of-Two Texture Resizing
Status: Open Priority: High Assignee: TBD Reporter: Roo (Architect Mode)
Description
The current asset processing pipeline resizes textures based on a target maximum dimension (e.g., 4K = 4096px) while maintaining the original aspect ratio. This results in non-power-of-two (NPOT) dimensions for non-square textures, which is suboptimal for rendering performance and compatibility with certain systems.
This feature implements a "Stretch/Squash" approach to ensure all output textures have power-of-two (POT) dimensions for each target resolution key.
Proposed Solution
-
Resizing Logic Change:
- Modify the
calculate_target_dimensionshelper function inasset_processor.py. - Step 1: Calculate intermediate dimensions (
scaled_w,scaled_h) by scaling the original image (orig_w, orig_h) to fit within the target resolution key's maximum dimension (e.g., 4096 for "4K") while maintaining the original aspect ratio (using existing logic). - Step 2: Implement a new helper function
get_nearest_pot(value: int) -> intto find the closest power-of-two value for a given integer. - Step 3: Apply
get_nearest_pot()toscaled_wto get the final target power-of-two width (pot_w). - Step 4: Apply
get_nearest_pot()toscaled_hto get the final target power-of-two height (pot_h). - Step 5: Return
(pot_w, pot_h)fromcalculate_target_dimensions. The_process_mapsfunction will then use these POT dimensions incv2.resize.
- Modify the
-
Helper Function
get_nearest_pot:- This function will take an integer
value. - It will find the powers of two immediately below (
lower_pot) and above (upper_pot) the value. - It will return the power of two that is numerically closer to the original
value. (e.g.,get_nearest_pot(1365)would return 1024, as1365 - 1024 = 341and2048 - 1365 = 683).
- This function will take an integer
-
Filename Convention:
- The original resolution tag (e.g.,
_4K,_2K) defined inconfig.pywill be kept in the output filename, even though the final dimensions are POT. This maintains consistency with the processing target.
- The original resolution tag (e.g.,
-
Metadata:
- The existing aspect ratio change metadata calculation (
_normalize_aspect_ratio_change) will remain unchanged. This metadata can be used downstream to potentially correct the aspect ratio distortion introduced by the stretch/squash resizing.
- The existing aspect ratio change metadata calculation (
Implementation Diagram
graph TD
A[Original Dimensions (W, H)] --> B{Target Resolution Key (e.g., "4K")};
B --> C{Get Max Dimension (e.g., 4096)};
A & C --> D[Calculate Scaled Dimensions (scaled_w, scaled_h) - Maintain Aspect Ratio];
D --> E[scaled_w];
D --> F[scaled_h];
E --> G[Find Nearest POT(scaled_w) -> pot_w];
F --> H[Find Nearest POT(scaled_h) -> pot_h];
G & H --> I[Final POT Dimensions (pot_w, pot_h)];
I --> J[Use (pot_w, pot_h) in cv2.resize];
Acceptance Criteria
- All textures output by the
_process_mapsfunction have power-of-two dimensions (width and height are both powers of 2). - The resizing uses the "Stretch/Squash" method based on the nearest POT value for each dimension calculated after initial aspect-preserving scaling.
- The output filename retains the original resolution key (e.g.,
_4K). - The
get_nearest_pothelper function correctly identifies the closest power of two. - The aspect ratio metadata calculation remains unchanged.