Alpha Mask Helpers
GetAlphaMaskTexture
GetAlphaMaskTexturepublic Texture2D GetAlphaMaskTexture()
=> m_MeshRenderer && m_MeshRenderer.sharedMaterial
? m_MeshRenderer.sharedMaterial.mainTexture as Texture2D
: null;Purpose: Fetch current material’s main texture as Texture2D.
Returns: Texture2D or null
Notes: Readability is checked in SampleAlphaAt.
SampleAlphaAt
SampleAlphaAtpublic float SampleAlphaAt(Vector3 worldPos)
{
Texture2D tex = GetAlphaMaskTexture();
if (tex == null || !tex.isReadable) return -1f;
Vector2 uv = WorldToLocalUV(worldPos);
return tex.GetPixelBilinear(uv.x, uv.y).a;
}Purpose: Sample alpha on the main texture at a world position.
Parameters: worldPos
Returns: Alpha in [0,1], or -1 if texture is missing/unreadable.
Notes: Enable “Read/Write” on the texture import settings to allow sampling.
SetAlphaThreshold
SetAlphaThresholdpublic void SetAlphaThreshold(float value, bool rebuild = true)
{
alphaThreshold = Mathf.Clamp01(value);
if (rebuild) ForceRebuild();
}Purpose: Set alpha threshold (mask trimming) and optionally rebuild.
Parameters: value in [0,1], rebuild toggle.
Returns: void
Notes: Increase to trim thin/transparent edges more aggressively.
Last updated