From b1e2bccd05615df26d2cf69494430f72c6314a45 Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Tue, 29 Jun 2021 19:55:57 +0900 Subject: [PATCH] fix: only for children option inside a scrollview Close #24 --- Scripts/Unmask.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Scripts/Unmask.cs b/Scripts/Unmask.cs index 9d77a6d..b997cfa 100644 --- a/Scripts/Unmask.cs +++ b/Scripts/Unmask.cs @@ -99,16 +99,17 @@ public Material GetModifiedMaterial(Material baseMaterial) Transform stopAfter = MaskUtilities.FindRootSortOverrideCanvas(transform); var stencilDepth = MaskUtilities.GetStencilDepth(transform, stopAfter); + var desiredStencilBit = 1 << stencilDepth; StencilMaterial.Remove(_unmaskMaterial); - _unmaskMaterial = StencilMaterial.Add(baseMaterial, (1 << stencilDepth) - 1, StencilOp.Zero, CompareFunction.Always, m_ShowUnmaskGraphic ? ColorWriteMask.All : (ColorWriteMask)0, 0, (1 << stencilDepth) - 1); + _unmaskMaterial = StencilMaterial.Add(baseMaterial, desiredStencilBit - 1, StencilOp.Invert, CompareFunction.Equal, m_ShowUnmaskGraphic ? ColorWriteMask.All : (ColorWriteMask)0, desiredStencilBit - 1, (1 << 8) - 1); // Unmask affects only for children. var canvasRenderer = graphic.canvasRenderer; if (m_OnlyForChildren) { StencilMaterial.Remove (_revertUnmaskMaterial); - _revertUnmaskMaterial = StencilMaterial.Add (baseMaterial, (1 << stencilDepth) - 1, StencilOp.Replace, CompareFunction.NotEqual, (ColorWriteMask)0); + _revertUnmaskMaterial = StencilMaterial.Add(baseMaterial, (1 << 7), StencilOp.Invert, CompareFunction.Equal, (ColorWriteMask)0, (1 << 7), (1 << 8) - 1); canvasRenderer.hasPopInstruction = true; canvasRenderer.popMaterialCount = 1; canvasRenderer.SetPopMaterial (_revertUnmaskMaterial, 0);