From 25e529e1a649954db765167c3c00af0ccaf61ca9 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 16 Apr 2022 16:09:09 +0800 Subject: [PATCH] [temp] got the idea why cannot make blur effect. This shit shader should run twice. --- .../TestSceneDefaultKaraokeLyricShader.cs | 9 +++++++-- .../Resources/Shaders/sh_DefaultKaraokeLyric.fs | 17 ++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/osu.Framework.Font.Tests/Visual/Shaders/TestSceneDefaultKaraokeLyricShader.cs b/osu.Framework.Font.Tests/Visual/Shaders/TestSceneDefaultKaraokeLyricShader.cs index 613fe55..0481740 100644 --- a/osu.Framework.Font.Tests/Visual/Shaders/TestSceneDefaultKaraokeLyricShader.cs +++ b/osu.Framework.Font.Tests/Visual/Shaders/TestSceneDefaultKaraokeLyricShader.cs @@ -5,13 +5,15 @@ using osu.Framework.Extensions; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics.Shaders; +using osuTK; namespace osu.Framework.Font.Tests.Visual.Shaders { public class TestSceneDefaultKaraokeLyricShader : TestSceneInternalShader { - [TestCase("#FFFF00", 10, "#FFFF00")] - [TestCase("#FF0000", 20, "#FFFFFF")] + [TestCase("#FFFFFF", 10, "#0000FF")] // White text with blue outline + [TestCase("#FF0000", 5, "#FFFFFF")] // Red text with white outline + [TestCase("#FF0000", 0, "#FFFFFF")] // Red text with no outline public void TestOutline(string colour, int radius, string outlineColour) { AddStep("Apply shader", () => @@ -23,6 +25,9 @@ public void TestOutline(string colour, int radius, string outlineColour) s.Colour = Color4Extensions.FromHex(colour); s.Radius = radius; s.OutlineColour = Color4Extensions.FromHex(outlineColour); + + s.ShadowSigma = 200; + s.ShadowOffset = new Vector2(0, 1); }) }; }); diff --git a/osu.Framework.Font/Resources/Shaders/sh_DefaultKaraokeLyric.fs b/osu.Framework.Font/Resources/Shaders/sh_DefaultKaraokeLyric.fs index de6652d..2176b2e 100644 --- a/osu.Framework.Font/Resources/Shaders/sh_DefaultKaraokeLyric.fs +++ b/osu.Framework.Font/Resources/Shaders/sh_DefaultKaraokeLyric.fs @@ -15,7 +15,6 @@ uniform vec4 g_OutlineColour; // shadow effect uniform mediump float g_Sigma; -uniform highp vec2 g_BlurDirection; mediump float computeGauss(in mediump float x, in mediump float sigma) { @@ -43,10 +42,18 @@ lowp vec4 blur(sampler2D tex, int radius, highp vec2 direction, mediump vec2 tex return toSRGB(sum / totalFactor); } +lowp vec4 outline() +{ + return blur(m_Sampler, g_Radius, highp vec2(1, 0), v_TexCoord, g_TexSize, g_Sigma) + + blur(m_Sampler, g_Radius, highp vec2(0, -1), v_TexCoord, g_TexSize, g_Sigma); +} + void main(void) { - mediump vec4 originTexture = texture2D(m_Sampler, v_TexCoord) * g_Colour; - lowp vec4 outline = blur(m_Sampler, g_Radius, g_BlurDirection, v_TexCoord, g_TexSize, g_Sigma) * g_OutlineColour; - lowp vec4 shadow = blur(m_Sampler, g_Radius, g_BlurDirection, v_TexCoord, g_TexSize, g_Sigma); - gl_FragColor = originTexture; + mediump vec4 originTexture = texture2D(m_Sampler, v_TexCoord).a * g_Colour; + lowp vec4 outline = outline().a * g_OutlineColour; + lowp vec4 shadow = blur(m_Sampler, g_Radius, highp vec2(0, 1), v_TexCoord, g_TexSize, g_Sigma); + + + gl_FragColor = blur(m_Sampler, g_Radius, highp vec2(0, -1), v_TexCoord, g_TexSize, g_Sigma); } \ No newline at end of file