You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
lowp vec4 outline(sampler2D tex, int radius, mediump vec2 texCoord, mediump vec2 texSize, mediump vec4 colour)
{
float angle = 0.0;
float outlineAlpha = 0.0;
for (int i = 0; i < SAMPLES; i++)
{
angle += 1.0 / (float(SAMPLES) / 2.0) * PI;
// todo: might need to adjust step samples amount to fill the inner side.
// but it will cause lots of performance issue if make step samples larger.
// so should find a better algorithm to fill inner colour.
for (int j = 1; j <= STEP_SAMPLES; j++)
{
vec2 testPoint = texCoord - vec2(sin(angle), cos(angle)) * (float(radius) * (1.0 / j)) / texSize;
float sampledAlpha = texture2D(tex, testPoint).a;
outlineAlpha = max(outlineAlpha, sampledAlpha);
}
}
mediump vec4 ogCol = texture2D(tex, texCoord);
vec4 outlineCol = mix(vec4(0.0), colour, outlineAlpha);
return mix(outlineCol, ogCol, ogCol.a);
}
Here's the shader and it can see that sin(angle), cos(angle)) runs lots of time on every frame (maybe run draw_width * draw_height * SAMPLES(2) * STEP_SAMPLES(128) times in each frame)
Maybe it can be calculated at the beginning.
Not really sure has someting like void init(void) before void main(void) and only run one time.
The text was updated successfully, but these errors were encountered:
also should think another issue:
should outline be transparent if source is transparent image also?
Because it might be faster if not doing the remaining work if already get the colour from texture2D.
Also there's another things i cannot understand
How did osu-framework can make outline-link effect with sh_Blur.ts
Here's the demo:
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Testing;
using osuTK;
using osuTK.Graphics;
namespace osu.Framework.Tests.Visual
{
public class OutlineTestScene : TestScene
{
[Test]
public void Test()
{
AddStep("Apply shader", () =>
{
Add(new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Red
});
Add(new SpriteText
{
Text = "Outlined Text",
Font = new FontUsage(size: 72),
}.WithEffect(new OutlineEffect
{
BlurSigma = new Vector2(5f),
Strength = 100f,
Colour = Color4.Blue,
PadExtent = true,
}));
});
}
}
}
Here's the shader and it can see that
sin(angle), cos(angle))
runs lots of time on every frame (maybe rundraw_width
*draw_height
*SAMPLES(2)
*STEP_SAMPLES(128)
times in each frame)Maybe it can be calculated at the beginning.
Not really sure has someting like
void init(void)
beforevoid main(void)
and only run one time.The text was updated successfully, but these errors were encountered: