Files
sbox-public/engine/Sandbox.Engine/Systems/UI/Render/PanelRenderer.Outline.cs
Matt Stevens a7a30ec6c7 Deferred UI batching and blendmode fixes (#4563)
* Deferred UI batching: collect everything first, sort by z, pass, blend mode (things that break batches) and flush as normal

  Before: https://files.facepunch.com/matt/1b2211b1/Discord_9fs860ZoeI.png
  After: https://files.facepunch.com/matt/1b2211b1/sbox_4vRV3zteqM.png
* Various blend mode fixes with the new UI batcher
* OverrideBlendMode in descriptors was ignored
* Panel.Draw.Text was missing PremultiplyAlpha = true
* UIBatcher flushes batch when blend mode changes (this is a bit wanky)
* ui_cssbox_batched.shader did not handle premultiplied backgrounds
* handle z-depth properly for text

---------

Co-authored-by: antopilo <mail@antopilo.dev>
2026-04-22 20:35:05 +01:00

38 lines
1.0 KiB
C#

namespace Sandbox.UI;
partial class PanelRenderer
{
internal void AddOutlineDescriptor( Panel panel, ref RenderState state, RenderLayer target )
{
ThreadSafe.AssertIsMainThread();
var style = panel.ComputedStyle;
if ( style == null ) return;
var outlineColor = style.OutlineColor.Value;
if ( outlineColor.a <= 0 ) return;
var rect = panel.Box.Rect;
var size = (rect.Width + rect.Height) * 0.5f;
var outlineWidth = style.OutlineWidth.Value.GetPixels( size );
if ( outlineWidth <= 0 ) return;
var opacity = state.RenderOpacity;
var color = outlineColor;
color.a *= opacity;
target.AddOutline( new OutlineDrawDescriptor( rect, color, outlineWidth )
{
BorderRadius = new Vector4(
style.BorderTopLeftRadius.Value.GetPixels( size ),
style.BorderTopRightRadius.Value.GetPixels( size ),
style.BorderBottomLeftRadius.Value.GetPixels( size ),
style.BorderBottomRightRadius.Value.GetPixels( size )
),
Offset = style.OutlineOffset.Value.GetPixels( size ),
OverrideBlendMode = OverrideBlendMode,
} );
}
}