diff --git a/osu.Framework.Font/Graphics/Shaders/ShadowShader.cs b/osu.Framework.Font/Graphics/Shaders/ShadowShader.cs index 0a520f7..71cf3b8 100644 --- a/osu.Framework.Font/Graphics/Shaders/ShadowShader.cs +++ b/osu.Framework.Font/Graphics/Shaders/ShadowShader.cs @@ -2,8 +2,10 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Runtime.InteropServices; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Rendering; +using osu.Framework.Graphics.Shaders.Types; using osuTK; using osuTK.Graphics; @@ -17,13 +19,21 @@ public class ShadowShader : InternalShader, IApplicableToDrawRectangle, IHasText public Vector2 ShadowOffset { get; set; } + private IUniformBuffer? shadowParametersBuffer; + public override void ApplyValue(IRenderer renderer) { - var shadowColour = new Vector4(ShadowColour.R, ShadowColour.G, ShadowColour.B, ShadowColour.A); - GetUniform(@"g_Colour").UpdateValue(ref shadowColour); + shadowParametersBuffer ??= renderer.CreateUniformBuffer(); + var shadowColour = new Vector4(ShadowColour.R, ShadowColour.G, ShadowColour.B, ShadowColour.A); var shadowOffset = new Vector2(-ShadowOffset.X, ShadowOffset.Y); - GetUniform(@"g_Offset").UpdateValue(ref shadowOffset); + shadowParametersBuffer.Data = new ShadowParameters + { + Colour = shadowColour, + Offset = shadowOffset, + }; + + BindUniformBlock("m_ShadowParameters", shadowParametersBuffer); } public RectangleF ComputeDrawRectangle(RectangleF originDrawRectangle) @@ -34,4 +44,12 @@ public RectangleF ComputeDrawRectangle(RectangleF originDrawRectangle) Top = Math.Max(-ShadowOffset.Y, 0), Bottom = Math.Max(ShadowOffset.Y, 0), }); + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + private record struct ShadowParameters + { + public UniformVector4 Colour; + public UniformVector2 Offset; + private UniformPadding8 pad1; + } } diff --git a/osu.Framework.Font/Resources/Shaders/sh_Shadow.fs b/osu.Framework.Font/Resources/Shaders/sh_Shadow.fs index a82b882..d150a29 100644 --- a/osu.Framework.Font/Resources/Shaders/sh_Shadow.fs +++ b/osu.Framework.Font/Resources/Shaders/sh_Shadow.fs @@ -1,22 +1,27 @@ +#include "sh_CustomizedShaderGlobalUniforms.h" #include "sh_Utils.h" -varying mediump vec2 v_TexCoord; +layout(location = 2) in highp vec2 v_TexCoord; -uniform lowp sampler2D m_Sampler; +layout(std140, set = 2, binding = 0) uniform m_ShadowParameters +{ + mediump vec4 g_Colour; + mediump vec2 g_Offset; +}; + +layout(set = 1, binding = 0) uniform lowp texture2D m_Texture; +layout(set = 1, binding = 1) uniform lowp sampler m_Sampler; -uniform mediump vec2 g_TexSize; -uniform vec4 g_Colour; -uniform vec2 g_Offset; -uniform float g_InflationPercentage; +layout(location = 0) out vec4 o_Colour; -lowp vec4 shadow(sampler2D tex, mediump vec2 texCoord, mediump vec2 texSize, mediump vec4 colour, mediump vec2 offset) +lowp vec4 shadow(texture2D tex, mediump vec2 texCoord, mediump vec2 texSize, mediump vec4 colour, mediump vec2 offset) { - return texture2D(tex, texCoord + offset / texSize).a * colour; + return texture(sampler2D(tex, m_Sampler), texCoord + offset / texSize).a * colour; } void main(void) { - lowp vec4 texture = toSRGB(texture2D(m_Sampler, v_TexCoord)); - lowp vec4 shadow = shadow(m_Sampler, v_TexCoord, g_TexSize, g_Colour, g_Offset * g_InflationPercentage); - gl_FragColor = mix(shadow, texture, texture.a); + lowp vec4 texture = toSRGB(texture(sampler2D(m_Texture, m_Sampler), v_TexCoord)); + lowp vec4 shadow = shadow(m_Texture, v_TexCoord, g_TexSize, g_Colour, g_Offset * g_InflationPercentage); + o_Colour = mix(shadow, texture, texture.a); } \ No newline at end of file