From 3e5c270f95c67fef61fffc372a1cc8ef43ba1d61 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 24 Oct 2021 23:27:19 +0800 Subject: [PATCH] Add border property. --- .../Shaders/CustomizedShaderTestScene.cs | 22 ++++++++++++++++++- .../Shaders/RepeatMovingBackgroundShader.cs | 6 +++-- .../Shaders/sh_RepeatMovingBackground.fs | 5 +++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/osu.Framework.Font.Tests/Visual/Shaders/CustomizedShaderTestScene.cs b/osu.Framework.Font.Tests/Visual/Shaders/CustomizedShaderTestScene.cs index d290c59..d1cec3d 100644 --- a/osu.Framework.Font.Tests/Visual/Shaders/CustomizedShaderTestScene.cs +++ b/osu.Framework.Font.Tests/Visual/Shaders/CustomizedShaderTestScene.cs @@ -99,7 +99,7 @@ public void TestPixelShader(float x, float y) [TestCase("sample-texture", 10, 10)] [TestCase("sample-texture", 30, 30)] [TestCase("sample-texture", 5, 20)] - public void TestRepeatMovingBackgroundShader(string textureName, float width, float height) + public void TestRepeatMovingBackgroundShaderDisplaySize(string textureName, float width, float height) { AddStep("Apply shader", () => { @@ -113,5 +113,25 @@ public void TestRepeatMovingBackgroundShader(string textureName, float width, fl }; }); } + + [TestCase("sample-texture", 0, 0)] + [TestCase("sample-texture", 10, 10)] + [TestCase("sample-texture", 5, 20)] + [TestCase("sample-texture", 30, 30)] + public void TestRepeatMovingBackgroundShaderBorder(string textureName, float width, float height) + { + AddStep("Apply shader", () => + { + ShaderContainer.Shaders = new[] + { + GetShaderByType().With(s => + { + s.Texture = textures.Get(textureName); + s.TextureDisplaySize = new Vector2(30); + s.TextureDisplayBorder = new Vector2(width, height); + }) + }; + }); + } } } diff --git a/osu.Framework.Font/Graphics/Shaders/RepeatMovingBackgroundShader.cs b/osu.Framework.Font/Graphics/Shaders/RepeatMovingBackgroundShader.cs index 1f26a02..b60741b 100644 --- a/osu.Framework.Font/Graphics/Shaders/RepeatMovingBackgroundShader.cs +++ b/osu.Framework.Font/Graphics/Shaders/RepeatMovingBackgroundShader.cs @@ -16,6 +16,8 @@ public class RepeatMovingBackgroundShader : InternalShader public Vector2 TextureDisplaySize { get; set; } = new Vector2(10); + public Vector2 TextureDisplayBorder { get; set; } + public RepeatMovingBackgroundShader(IShader originShader) : base(originShader) { @@ -43,8 +45,8 @@ public override void ApplyValue(FrameBuffer current) var textureDisplaySize = TextureDisplaySize; GetUniform("g_DisplaySize").UpdateValue(ref textureDisplaySize); - //var border = Border; - //GetUniform("g_Border").UpdateValue(ref border); + var textureDisplayBorder = TextureDisplayBorder; + GetUniform("g_DisplayBorder").UpdateValue(ref textureDisplayBorder); } } } diff --git a/osu.Framework.Font/Resources/Shaders/sh_RepeatMovingBackground.fs b/osu.Framework.Font/Resources/Shaders/sh_RepeatMovingBackground.fs index b4429d9..0fa8c2d 100644 --- a/osu.Framework.Font/Resources/Shaders/sh_RepeatMovingBackground.fs +++ b/osu.Framework.Font/Resources/Shaders/sh_RepeatMovingBackground.fs @@ -11,16 +11,17 @@ uniform lowp sampler2D g_RepeatSample; uniform vec2 g_RepeatSampleCoord; uniform vec2 g_RepeatSampleSize; uniform vec2 g_DisplaySize; +uniform vec2 g_DisplayBorder; uniform vec2 g_Offset; void main(void) { // calculate how many times texture should be repeated. - vec2 repeat = g_TexSize / g_DisplaySize; + vec2 repeat = g_TexSize / (g_DisplaySize + g_DisplayBorder); // get the repeat texture cooldinate. float repeatTexCoordX = mod(v_TexCoord.x * repeat.x + g_Offset.x, 1); float repeatTexCoordY = mod(v_TexCoord.y * repeat.y + g_Offset.y, 1); - vec2 repeatTexCoord = vec2(repeatTexCoordX, repeatTexCoordY); + vec2 repeatTexCoord = vec2(repeatTexCoordX, repeatTexCoordY) / g_DisplaySize * (g_DisplaySize + g_DisplayBorder); // because repeat texture will be the size of 1024*1024, so should make a conversion to get the target area of the texture. vec2 fixedTexCoord = repeatTexCoord * g_RepeatSampleSize + g_RepeatSampleCoord;