/** * Copyright(c) Live2D Inc. All rights reserved. * * Use of this source code is governed by the Live2D Open Software license * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. */ using UnityEngine; namespace Live2D.Cubism.Rendering.Masking { /// /// Holds info used for masking. /// public struct CubismMaskTransform { #region Conversion /// /// backing field. /// private static int _uniqueId; /// /// HACK Prevents dynamic batching of s that are masked. /// /// /// As Unity transforms vertex positions into world space on dynamic batching, and masking relies on vertex positions to be in local space, /// masking isn't compatible with dynamic batching. /// /// Unity exposes a shader tag for disabling dynamic batching ("DynamicBatching"), but this would make it necessary for creating separate shaders... /// private static int UniqueId { get { // We just have to make sure consecutive drawables with the same mask aren't batched; having more than 1024 cases in a row seems pretty rare, so... if (_uniqueId > 1024) { _uniqueId = 0; } return (++_uniqueId); } } /// /// Converts a to a . /// /// Value to convert. public static implicit operator Vector4(CubismMaskTransform value) { return new Vector4 { x = value.Offset.x, y = value.Offset.y, z = value.Scale, w = UniqueId }; } #endregion /// /// Offset in model space. /// public Vector2 Offset; /// /// Scale in model space. /// public float Scale; } }