Skip to content

Fix soft mask parameter synchronization for stencil materials - #540

Open
le888 wants to merge 1 commit into
Unity-UI-Extensions:developmentfrom
le888:fix/softmask-stencil-material-sync
Open

le888 wants to merge 1 commit into
Unity-UI-Extensions:developmentfrom
le888:fix/softmask-stencil-material-sync

Conversation

@le888

@le888 le888 commented Nov 9, 2026

Copy link
Copy Markdown

Overview

A Graphic using SoftMaskScript beneath a parent uGUI Mask can render with stale soft-mask parameters. The CanvasRenderer may use a cached stencil material derived from the Graphic's material, while SetMask() only updates the original material. This can leave the Graphic invisible on its first display and prevent later mask parameter changes from reaching the rendered material.

Changes

  • Initialize mask parameters before assigning the new material to the Graphic.
  • Cache the Graphic and apply mask parameters to its current CanvasRenderer material when it is a separate material using the same shader.
  • Share parameter writes through ApplyMask().
  • Skip zero-sized mask rectangles to avoid division by zero during layout initialization.

Breaking Changes

None. No public API or serialized field changes.

Related Submodule Changes

None.

Testing status

No automated tests have been added. The diff is limited to Runtime/Scripts/Effects/SoftMaskScript.cs and preserves the upstream text handling and file line endings. git diff --check passes with CRLF recognized as line endings.

Manual testing status

The change addresses a first-display visibility problem encountered in a Unity 2022.3 project. I have not run a fresh Unity compilation or visual regression test for this upstream contribution. The available Unity MCP connection points to a different project, and script validation rejects the standalone package checkout because it is outside that project's Assets directory.

Suggested manual verification:

  1. Put an Image or RawImage with SoftMaskScript under an enabled parent Mask, assign an alpha mask, then display the UI for the first time.
  2. Confirm that the Graphic is visible with the expected soft clipping.
  3. Change MaskArea, AlphaMask, CutOff, HardBlend, FlipAlphaMask, and DontClipMaskScalingRect while the UI is visible; confirm that the rendered mask follows the changes.
  4. Repeat without a parent Mask, toggle the Graphic active state, and exercise a MaskArea that starts at zero size before layout gives it a nonzero size.

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.

2 participants