Skip to content

Commit

Permalink
feat: add 'AntiAliasing' masking mode. This mode suppresses stencil-d…
Browse files Browse the repository at this point in the history
…erived mask aliasing without using RenderTexture.
  • Loading branch information
mob-sakai committed Feb 11, 2024
1 parent 76f69cf commit efb7f64
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Packages/src/Runtime/SoftMask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,30 @@ public enum DownSamplingRate
x8 = 8
}

/// <summary>
/// Masking mode.<br />
/// <b>SoftMasking</b>: Use soft masking.<br />
/// <b>AntiAliasing</b>: Use anti-aliasing.
/// </summary>
public enum MaskingMode
{
SoftMasking,
AntiAliasing,
Normal
}

public static Action<SoftMask> onRenderSoftMaskBuffer = null;
private static readonly Camera.MonoOrStereoscopicEye[] s_MonoEyes = { Camera.MonoOrStereoscopicEye.Mono };

private static readonly Camera.MonoOrStereoscopicEye[] s_StereoEyes =
{ Camera.MonoOrStereoscopicEye.Left, Camera.MonoOrStereoscopicEye.Right };

[Tooltip("Masking mode\n\n" +
"SoftMasking: Use RenderTexture as a soft mask buffer. The alpha of the masking graphic can be used.\n" +
"AntiAliasing: Suppress the jaggedness of the masking graphic. The masking graphic cannot be displayed.")]
[SerializeField]
private MaskingMode m_MaskingMode = MaskingMode.SoftMasking;

[Tooltip("Enable alpha hit test.")]
[SerializeField]
private bool m_AlphaHitTest;
Expand All @@ -47,9 +65,15 @@ public enum DownSamplingRate
[SerializeField]
private DownSamplingRate m_DownSamplingRate = DownSamplingRate.x1;

[Tooltip("The threshold for anti-alias masking.")] [SerializeField] [Range(0f, 1f)]
private float m_AntiAliasingThreshold;

[SerializeField] [Obsolete]
private float m_Softness = -1;

[SerializeField] [Obsolete]
private bool m_PartOfParent;

private CommandBuffer _cb;

private List<SoftMask> _children = ListPool<SoftMask>.Rent();
Expand All @@ -69,6 +93,25 @@ [SerializeField] [Obsolete]
private UnityAction _updateParentSoftMask;
private CanvasViewChangeTrigger _viewChangeTrigger;

/// <summary>
/// Masking mode<br />
/// <b>SoftMasking</b>: Use RenderTexture as a soft mask buffer. The alpha of the masking graphic can be used.<br />
/// <b>AntiAliasing</b>: Suppress the jaggedness of the masking graphic. The masking graphic cannot be displayed.
/// </summary>
public MaskingMode maskingMode
{
get => m_MaskingMode;
set
{
if (m_MaskingMode == value) return;

m_MaskingMode = value;
AddSoftMaskableOnChildren();
UpdateAntiAlias();
SetDirtyAndNotify();
}
}

public DownSamplingRate downSamplingRate
{
get => m_DownSamplingRate;
Expand All @@ -80,6 +123,15 @@ public DownSamplingRate downSamplingRate
}
}

/// <summary>
/// Threshold for anti-alias masking.
/// </summary>
public float antiAliasingThreshold
{
get => m_AntiAliasingThreshold;
set => m_AntiAliasingThreshold = value;
}

/// <summary>
/// Enable alpha hit test.
/// </summary>
Expand Down

0 comments on commit efb7f64

Please sign in to comment.