Skip to content

Commit

Permalink
[temp] got the idea why cannot make blur effect.
Browse files Browse the repository at this point in the history
This shit shader should run twice.
  • Loading branch information
andy840119 committed Apr 16, 2022
1 parent 030bb8f commit 5ef92e8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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", () =>
Expand All @@ -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);
})
};
});
Expand Down
17 changes: 12 additions & 5 deletions osu.Framework.Font/Resources/Shaders/sh_DefaultKaraokeLyric.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}

0 comments on commit 5ef92e8

Please sign in to comment.