Skip to content

Commit

Permalink
fix: when UseStencilOutsideScreen = true, objects inside SoftMask
Browse files Browse the repository at this point in the history
… are not batched in the editor

close #188
  • Loading branch information
mob-sakai committed Sep 4, 2024
1 parent ea783a6 commit 8b93959
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions Runtime/SoftMaskable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,42 +103,20 @@ Material IMaterialModifier.GetModifiedMaterial(Material baseMaterial)
RecalculateStencilIfNeeded();
_softMaskDepth = _softMask ? _softMask.softMaskDepth : -1;

var useStencil = UISoftMaskProjectSettings.useStencilOutsideScreen;
var localId = 0u;
#if UNITY_EDITOR
if (useStencil)
{
if (_softMask && _softMaskDepth < 0)
{
MaterialRepository.Release(ref _maskableMaterial);
return baseMaterial;
}

if (!_softMask && (!TryGetComponent(out _softMask) || !_softMask.SoftMaskingEnabled()))
{
MaterialRepository.Release(ref _maskableMaterial);
return baseMaterial;
}

localId = (uint)GetInstanceID() + (UISoftMaskProjectSettings.useStencilOutsideScreen ? 1u : 0u);
}
else
#endif

if (!_softMask || _softMaskDepth < 0 || 4 <= _softMaskDepth)
{
MaterialRepository.Release(ref _maskableMaterial);
return baseMaterial;
}

Profiler.BeginSample("(SM4UI)[SoftMaskable] GetModifiedMaterial");

var isStereo = UISoftMaskProjectSettings.stereoEnabled && _graphic.canvas.IsStereoCanvas();
var useStencil = UISoftMaskProjectSettings.useStencilOutsideScreen;
var hash = new Hash128(
(uint)baseMaterial.GetInstanceID(),
(uint)_softMask.softMaskBuffer.GetInstanceID(),
(uint)_stencilBits + (isStereo ? 1 << 8 : 0u) + ((uint)_softMaskDepth << 9),
localId);
(uint)(_stencilBits + (isStereo ? 1 << 8 : 0) + (useStencil ? 1 << 9 : 0) + (_softMaskDepth << 10)),
0);
MaterialRepository.Get(hash, ref _maskableMaterial,
x => SoftMaskUtils.CreateSoftMaskable(x.baseMaterial, x.softMaskBuffer, x._softMaskDepth,
x._stencilBits, x.isStereo, UISoftMaskProjectSettings.fallbackBehavior),
Expand All @@ -147,7 +125,7 @@ Material IMaterialModifier.GetModifiedMaterial(Material baseMaterial)

#if UNITY_EDITOR
var threshold = 0f;
if (useStencil)
if (UISoftMaskProjectSettings.useStencilOutsideScreen)
{
if (TryGetComponent(out MaskingShape s) && s.maskingMethod == MaskingShape.MaskingMethod.Subtract)
{
Expand Down

0 comments on commit 8b93959

Please sign in to comment.