diff --git a/osu.Framework.Font.Tests/Visual/Shaders/CustomizedShaderTestScene.cs b/osu.Framework.Font.Tests/Visual/Shaders/CustomizedShaderTestScene.cs index 35c2bbd..3a378e1 100644 --- a/osu.Framework.Font.Tests/Visual/Shaders/CustomizedShaderTestScene.cs +++ b/osu.Framework.Font.Tests/Visual/Shaders/CustomizedShaderTestScene.cs @@ -153,5 +153,27 @@ public void TestRepeatMovingBackgroundShaderSpeed(float xSpeed, float ySpeed) }; }); } + + [TestCase(0)] + [TestCase(0.5f)] + [TestCase(1f)] + [TestCase(-1)] // invalid + [TestCase(3)] // invalid + public void TestRepeatMovingBackgroundShaderMix(float mix) + { + AddStep("Apply shader", () => + { + ShaderContainer.Shaders = new[] + { + GetShaderByType().With(s => + { + s.Texture = textures.Get("sample-texture"); + s.TextureDisplaySize = new Vector2(30); + s.Speed = new Vector2(1); + s.Mix = mix; + }) + }; + }); + } } } diff --git a/osu.Framework.Font/Graphics/Shaders/RepeatMovingBackgroundShader.cs b/osu.Framework.Font/Graphics/Shaders/RepeatMovingBackgroundShader.cs index 05f0771..ab0a21a 100644 --- a/osu.Framework.Font/Graphics/Shaders/RepeatMovingBackgroundShader.cs +++ b/osu.Framework.Font/Graphics/Shaders/RepeatMovingBackgroundShader.cs @@ -1,6 +1,7 @@ // Copyright (c) andy840119 . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using osu.Framework.Graphics.OpenGL.Buffers; using osu.Framework.Graphics.Textures; using osuTK; @@ -20,6 +21,8 @@ public class RepeatMovingBackgroundShader : InternalShader, IApplicableToCurrent public Vector2 Speed { get; set; } + public float Mix { get; set; } = 1f; + public RepeatMovingBackgroundShader(IShader originShader) : base(originShader) { @@ -52,6 +55,9 @@ public override void ApplyValue(FrameBuffer current) var speed = Speed; GetUniform("g_Speed").UpdateValue(ref speed); + + var mix = Math.Clamp(Mix, 0, 1); + GetUniform(@"g_Mix").UpdateValue(ref mix); } public void ApplyCurrentTime(float currentTime) diff --git a/osu.Framework.Font/Resources/Shaders/sh_RepeatMovingBackground.fs b/osu.Framework.Font/Resources/Shaders/sh_RepeatMovingBackground.fs index 006fc71..1a044eb 100644 --- a/osu.Framework.Font/Resources/Shaders/sh_RepeatMovingBackground.fs +++ b/osu.Framework.Font/Resources/Shaders/sh_RepeatMovingBackground.fs @@ -14,6 +14,7 @@ uniform vec2 g_DisplaySize; uniform vec2 g_DisplayBorder; uniform vec2 g_Speed; uniform float g_Time; +uniform float g_Mix; void main(void) { // calculate how many times texture should be repeated. @@ -28,5 +29,7 @@ void main(void) { vec2 fixedTexCoord = repeatTexCoord * g_RepeatSampleSize + g_RepeatSampleCoord; // get point colour from sample. - gl_FragColor = v_Colour * texture2D(g_RepeatSample, fixedTexCoord); + vec4 texColor = texture2D(m_Sampler, v_TexCoord); + vec4 repeatSampleColor = v_Colour * vec4(texture2D(g_RepeatSample, fixedTexCoord).xyz, texColor.a); + gl_FragColor = mix(texColor, repeatSampleColor, g_Mix); }