using UnityEngine; namespace LeTai.Asset.TranslucentImage { [CreateAssetMenu(fileName = "New Scalable Blur Config", menuName = "Translucent Image/ Scalable Blur Config", order = 100)] public class ScalableBlurConfig : BlurConfig { [SerializeField] float radius = 4; [SerializeField] int iteration = 4; [SerializeField] int maxDepth = 6; [SerializeField] float strength; /// /// Distance between the base texel and the texel to be sampled. /// public float Radius { get { return radius; } set { radius = Mathf.Max(0, value); } } /// /// Half the number of time to process the image. It is half because the real number of iteration must alway be even. Using half also make calculation simpler /// /// /// Must be non-negative /// public int Iteration { get { return iteration; } set { iteration = Mathf.Max(0, value); } } /// /// Clamp the minimum size of the intermediate texture. Reduce flickering and blur /// /// /// Must larger than 0 /// public int MaxDepth { get { return maxDepth; } set { maxDepth = Mathf.Max(1, value); } } /// /// User friendly property to control the amount of blur /// /// /// Must be non-negative /// public float Strength { get { return strength = Radius * Mathf.Pow(2, Iteration); } set { strength = Mathf.Max(0, value); SetAdvancedFieldFromSimple(); } } /// /// Calculate size and iteration from strength /// protected virtual void SetAdvancedFieldFromSimple() { var iterationPower = Mathf.Pow(2, Iteration); Radius = strength / iterationPower; while (Radius < 1 && Iteration > 0) { Iteration--; Radius *= 2; } while (Radius > iterationPower) { Radius /= 2; Iteration++; } } } }