Skip to content

fix: align SDK7 UiBackground nine-slice with Unity behavior#2006

Draft
kuruk-mm wants to merge 2 commits into
mainfrom
fix/ui-background-nine-slice-unity-parity
Draft

fix: align SDK7 UiBackground nine-slice with Unity behavior#2006
kuruk-mm wants to merge 2 commits into
mainfrom
fix/ui-background-nine-slice-unity-parity

Conversation

@kuruk-mm
Copy link
Copy Markdown
Member

@kuruk-mm kuruk-mm commented May 9, 2026

Closes #2060

Summary

Brings the Godot port of PBUiBackground (component 1053) closer to the Unity explorer's DCLImage semantics.

The most user-visible change: nine-slice panels (e.g. HUD panel_v2.png with textureSlices: 0.18) no longer tile their edge strips and inner area — the wood frame edges and cream interior now stretch smoothly, matching Unity UI Toolkit and ending the long-standing TODO: should be TILE or STRETCH? in dcl_ui_background.rs.

What changed in lib/src/godot_classes/dcl_ui_background.rs

  • Nine-slice axis stretch: AxisStretchMode::TILE_FITSTRETCH on both axes. Matches Unity's default sliced rendering.
  • Slice clamping: opposing slices (left+right, top+bottom) are clamped to 1.0 before being applied as patch margins, mirroring Unity's DCLImage.AdjustSlices().
  • UV index convention: protobuf UVs are now interpreted as BL=uvs[0..2], TL=uvs[2..4], TR=uvs[4..6], BR=uvs[6..8] (Unity's Extensions.ToDCLUVs). This affects:
    • has_custom_uvs() axis-alignment check
    • the axis-aligned region_rect computation in STRETCH mode (also fixes a latent bug where the old 1.0 - max/min formula could produce a negative region_rect height for valid inputs)
    • the parameter packing fed to dcl_ui_background_uv.gdshader (the shader itself is unchanged; we just feed it (TL, BL) / (BR, TR) from the new index order)

What is not changed

  • The custom-UV shader's interpolation/Y-flip math is left alone. Unity's stretch mode uses custom mesh generation, while Godot uses a fragment shader; aligning the rotated/skewed UV path beyond index ordering would be a separate change.
  • Tracing/debug logs are kept as-is.

Test plan

  • Open a scene that uses Panel (uiBackground.textureMode = 'nine-slices', textureSlices: 0.18 per side, panel_v2.png) and verify the wood-frame edges no longer show repeating tiles
  • Verify panels at very small sizes (parent < texture) still render with the corners intact and no clipping regression
  • Spot-check other 9-slice users in the HUD (chat panel, dialog, settings) for stretching artifacts
  • Verify STRETCH mode (textureMode: 'stretch') with default UVs still renders the full texture
  • Verify a stretch background with axis-aligned custom UVs (e.g. a sub-region of a sprite atlas) still picks the correct region
  • (optional) Verify a stretch background with rotated UVs still renders something reasonable via the shader path

- NINE_SLICES axis stretch: TILE_FIT -> STRETCH so edges and middle
  match Unity UI Toolkit instead of tiling the source texture
- clamp opposing slices (left+right, top+bottom) to 1.0, mirroring
  Unity DCLImage.AdjustSlices
- reorder protobuf UV indices to BL/TL/TR/BR (Unity ToDCLUVs
  convention) in has_custom_uvs and the axis-aligned region_rect
  computation
- repack the custom-UV shader parameters so the existing
  dcl_ui_background_uv.gdshader keeps receiving (TL, BL) / (BR, TR)
  under the new index order
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

📦 Build Report

🤖 Android

Artifact Status
APK 📱 Download APK
AAB 📦 Download AAB
Debug Symbols 🔧 Debug Symbols

Build Status: ✅ Success

🍏 iOS

iOS builds are triggered manually. Add the build-ios label to trigger an iOS build.


🔗 Workflow Run: View logs

🔄 Updated: 2026-05-09 16:57:20 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026


🍏 iOS Build Complete

Status: Success

🔗 iOS Workflow: View build

📦 Artifacts: godot-mobile-deploy-pipeline

📍 Branch: PR-2006-fix/ui-background-nine-slice-unity-parity

🔄 Completed: 2026-05-11 00:41:30 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDK7 UiBackground nine-slice tiles instead of stretching (Unity parity gap)

1 participant