Skip to content

fix(element): cull screen-space text by content bounds#8934

Merged
willeastcott merged 1 commit into
mainfrom
fix-masked-text-overflow-culling
Jun 19, 2026
Merged

fix(element): cull screen-space text by content bounds#8934
willeastcott merged 1 commit into
mainfrom
fix-masked-text-overflow-culling

Conversation

@willeastcott

Copy link
Copy Markdown
Contributor

Fixes #4615.

Screen-space UI elements are frustum-culled via ElementComponent.isVisibleForCamera, which tested the element's anchored box. A text element's wrapped glyphs can overflow that box, so masked (or off-screen) text whose box fell outside the clip region was culled even though its glyphs were still on screen — the text rendered as nothing at runtime, while still showing in the Editor (edit-mode culling differs).

This culls text against its rendered content bounds instead: the box is expanded by the horizontal/vertical overflow (text.width/heightcalculatedWidth/Height), distributed according to the text alignment. Over-estimation is the safe direction — worst case it renders an element that the stencil then clips; it never wrongly culls.

The corner-building logic in screenCorners is extracted into a shared _calcScreenCorners helper used by both paths.

Testing

  • Added a regression test (Masked text is not culled when its wrapped content overflows the element box) — fails on main, passes here.
  • All existing element tests pass; verified visually against the reported repro project (text now renders and is correctly clipped to the mask).

🤖 Generated with Claude Code

Screen-space elements are culled via isVisibleForCamera, which tested the
element's anchored box. Wrapped text can overflow that box, so masked (or
off-screen) text whose box fell outside the clip region was culled even when
its glyphs were still on screen, rendering as nothing.

Cull text against its rendered content bounds instead: expand the box by the
horizontal/vertical overflow, distributed according to the text alignment.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@willeastcott willeastcott self-assigned this Jun 19, 2026
@willeastcott willeastcott added the area: ui UI related issue label Jun 19, 2026
@github-actions

Copy link
Copy Markdown

Build size report

This PR changes the size of the minified bundles.

Bundle Minified Gzip Brotli
playcanvas.min.js 2287.8 KB (+0.2 KB, +0.01%) 586.7 KB (+0.1 KB, +0.02%) 455.9 KB (−0.1 KB, −0.02%)
playcanvas.min.mjs 2285.2 KB (+0.2 KB, +0.01%) 585.8 KB (+0.1 KB, +0.02%) 455.7 KB (+0.0 KB, +0.01%)

@willeastcott willeastcott merged commit 8c8a73d into main Jun 19, 2026
10 checks passed
@willeastcott willeastcott deleted the fix-masked-text-overflow-culling branch June 19, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ui UI related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Masked text renders differently between Editor view and Runtime

1 participant