Skip to content

Commit

Permalink
add the damn shader
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Apr 16, 2022
1 parent 11710ae commit d9a886f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace osu.Framework.Graphics.Shaders
{
public class DefaultKaraokeLyricShader : InternalShader
{
public override string ShaderName => "DefaultKaraokeFont";
public override string ShaderName => "DefaultKaraokeLyric";

public Color4 Colour { get; set; }

Expand All @@ -21,6 +21,10 @@ public class DefaultKaraokeLyricShader : InternalShader

public int ShaderSize { get; set; }

public int ShaderSigma { get; set; }

public Vector2 ShaderColour { get; set; }

public override void ApplyValue(FrameBuffer current)
{
var radius = Radius;
Expand Down
44 changes: 44 additions & 0 deletions osu.Framework.Font/Resources/Shaders/sh_DefaultKaraokeLyric.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "sh_Utils.h"

#define INV_SQRT_2PI 0.39894

varying mediump vec2 v_TexCoord;

uniform lowp sampler2D m_Sampler;

uniform mediump vec2 g_TexSize;
uniform int g_Radius;

uniform mediump float g_Sigma;
uniform highp vec2 g_BlurDirection;

mediump float computeGauss(in mediump float x, in mediump float sigma)
{
return INV_SQRT_2PI * exp(-0.5*x*x / (sigma*sigma)) / sigma;
}

lowp vec4 blur(sampler2D tex, int radius, highp vec2 direction, mediump vec2 texCoord, mediump vec2 texSize, mediump float sigma)
{
mediump float factor = computeGauss(0.0, sigma);
mediump vec4 sum = texture2D(tex, texCoord) * factor;

mediump float totalFactor = factor;

for (int i = 2; i <= 200; i += 2)
{
mediump float x = float(i) - 0.5;
factor = computeGauss(x, sigma) * 2.0;
totalFactor += 2.0 * factor;
sum += texture2D(tex, texCoord + direction * x / texSize) * factor;
sum += texture2D(tex, texCoord - direction * x / texSize) * factor;
if (i >= radius)
break;
}

return toSRGB(sum / totalFactor);
}

void main(void)
{
gl_FragColor = blur(m_Sampler, g_Radius, g_BlurDirection, v_TexCoord, g_TexSize, g_Sigma);
}

0 comments on commit d9a886f

Please sign in to comment.