Add BlurScaleWithSize to BlurPanel for resolution-independent blur

This commit is contained in:
Wojtek Figat
2023-02-07 14:13:02 +01:00
parent d92da5ceba
commit 0366de36ce

View File

@@ -11,9 +11,15 @@ namespace FlaxEngine.GUI
/// <summary>
/// Gets or sets the blur strength. Defines how blurry the background is. Larger numbers increase blur, resulting in a larger runtime cost on the GPU.
/// </summary>
[EditorOrder(0), Limit(0, 100, 0.0f), Tooltip("Blur strength defines how blurry the background is. Larger numbers increase blur, resulting in a larger runtime cost on the GPU.")]
[EditorOrder(0), Limit(0, 100, 0.0f)]
public float BlurStrength { get; set; }
/// <summary>
/// If checked, the blur strength will be scaled with the control size, which makes it resolution-independent.
/// </summary>
[EditorOrder(10)]
public bool BlurScaleWithSize { get; set; } = false;
/// <summary>
/// Initializes a new instance of the <see cref="BlurPanel"/> class.
/// </summary>
@@ -27,10 +33,13 @@ namespace FlaxEngine.GUI
{
base.Draw();
float strength = BlurStrength;
var size = Size;
var strength = BlurStrength;
if (BlurScaleWithSize)
strength *= size.MinValue / 1000.0f;
if (strength > Mathf.Epsilon)
{
Render2D.DrawBlur(new Rectangle(Float2.Zero, Size), strength);
Render2D.DrawBlur(new Rectangle(Float2.Zero, size), strength);
}
}
}