diff --git a/fluXis.Game/Graphics/Shaders/Pixelate/PixelateContainer.cs b/fluXis.Game/Graphics/Shaders/Pixelate/PixelateContainer.cs deleted file mode 100644 index 3656a3b8..00000000 --- a/fluXis.Game/Graphics/Shaders/Pixelate/PixelateContainer.cs +++ /dev/null @@ -1,11 +0,0 @@ -using fluXis.Game.Map.Structures.Events; -using osu.Framework.Graphics; - -namespace fluXis.Game.Graphics.Shaders.Pixelate; - -public partial class PixelateContainer : ShaderContainer -{ - protected override string FragmentShader => "Pixelate"; - public override ShaderType Type => ShaderType.Pixelate; - protected override DrawNode CreateShaderDrawNode() => new PixelateContainerDrawNode(this, SharedData); -} diff --git a/fluXis.Game/Graphics/Shaders/Pixelate/PixelateDrawNode.cs b/fluXis.Game/Graphics/Shaders/Pixelate/PixelateDrawNode.cs deleted file mode 100644 index e1119083..00000000 --- a/fluXis.Game/Graphics/Shaders/Pixelate/PixelateDrawNode.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System.Runtime.InteropServices; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Colour; -using osu.Framework.Graphics.Primitives; -using osu.Framework.Graphics.Rendering; -using osu.Framework.Graphics.Shaders.Types; -using osuTK.Graphics; - -namespace fluXis.Game.Graphics.Shaders.Pixelate; - -public partial class PixelateContainer -{ - private class PixelateContainerDrawNode : ShaderDrawNode - { - private float strength; - private IUniformBuffer parametersBuffer; - - public PixelateContainerDrawNode(PixelateContainer source, BufferedDrawNodeSharedData sharedData) - : base(source, sharedData) - { - } - - public override void ApplyState() - { - base.ApplyState(); - - strength = Source.Strength; - } - - protected override void PopulateContents(IRenderer renderer) - { - base.PopulateContents(renderer); - - if (strength > 0) - drawFrameBuffer(renderer); - } - - private void drawFrameBuffer(IRenderer renderer) - { - parametersBuffer ??= renderer.CreateUniformBuffer(); - - IFrameBuffer current = SharedData.CurrentEffectBuffer; - IFrameBuffer target = SharedData.GetNextEffectBuffer(); - - renderer.SetBlend(BlendingParameters.None); - - using (BindFrameBuffer(target)) - { - parametersBuffer.Data = parametersBuffer.Data with - { - TexSize = current.Size, - Strength = strength - }; - - Shader.BindUniformBlock("m_PixelateParameters", parametersBuffer); - Shader.Bind(); - renderer.DrawFrameBuffer(current, new RectangleF(0, 0, current.Texture.Width, current.Texture.Height), ColourInfo.SingleColour(Color4.White)); - Shader.Unbind(); - } - } - - protected override void Dispose(bool isDisposing) - { - base.Dispose(isDisposing); - parametersBuffer?.Dispose(); - } - - [StructLayout(LayoutKind.Sequential, Pack = 1)] - private record struct PixelateParameters - { - public UniformVector2 TexSize; - public UniformFloat Strength; - private readonly UniformPadding4 pad1; - } - } -} diff --git a/fluXis.Game/Map/Structures/Events/ShaderEvent.cs b/fluXis.Game/Map/Structures/Events/ShaderEvent.cs index 7e876b8b..d2f92e57 100644 --- a/fluXis.Game/Map/Structures/Events/ShaderEvent.cs +++ b/fluXis.Game/Map/Structures/Events/ShaderEvent.cs @@ -70,6 +70,5 @@ public enum ShaderType Vignette, Retro, HueShift, - Pixelate, Glitch } diff --git a/fluXis.Game/Screens/Edit/Tabs/Design/DesignContainer.cs b/fluXis.Game/Screens/Edit/Tabs/Design/DesignContainer.cs index 936cf33e..40a6710c 100644 --- a/fluXis.Game/Screens/Edit/Tabs/Design/DesignContainer.cs +++ b/fluXis.Game/Screens/Edit/Tabs/Design/DesignContainer.cs @@ -12,7 +12,6 @@ using fluXis.Game.Graphics.Shaders.Retro; using fluXis.Game.Graphics.Shaders.Vignette; using fluXis.Game.Graphics.Shaders.HueShift; -using fluXis.Game.Graphics.Shaders.Pixelate; using fluXis.Game.Graphics.Sprites; using fluXis.Game.Map.Structures.Events; using fluXis.Game.Screens.Edit.Tabs.Design.Effects; @@ -112,7 +111,6 @@ private ShaderStackContainer createShaderStack() ShaderType.Vignette => new VignetteContainer(), ShaderType.Retro => new RetroContainer(), ShaderType.HueShift => new HueShiftContainer(), - ShaderType.Pixelate => new PixelateContainer(), ShaderType.Glitch => new GlitchContainer(), _ => null }; diff --git a/fluXis.Game/Screens/Edit/Tabs/Design/Points/Entries/ShaderEntry.cs b/fluXis.Game/Screens/Edit/Tabs/Design/Points/Entries/ShaderEntry.cs index aa2301ad..b126aab6 100644 --- a/fluXis.Game/Screens/Edit/Tabs/Design/Points/Entries/ShaderEntry.cs +++ b/fluXis.Game/Screens/Edit/Tabs/Design/Points/Entries/ShaderEntry.cs @@ -242,7 +242,6 @@ protected override IEnumerable CreateSettings() case ShaderType.Vignette: case ShaderType.Retro: case ShaderType.HueShift: - case ShaderType.Pixelate: default: // default shader settings settings.AddRange(new Drawable[] { diff --git a/fluXis.Game/Screens/Gameplay/GameplayScreen.cs b/fluXis.Game/Screens/Gameplay/GameplayScreen.cs index 81f20fe8..4099b681 100644 --- a/fluXis.Game/Screens/Gameplay/GameplayScreen.cs +++ b/fluXis.Game/Screens/Gameplay/GameplayScreen.cs @@ -21,7 +21,6 @@ using fluXis.Game.Graphics.Shaders.Retro; using fluXis.Game.Graphics.Shaders.Vignette; using fluXis.Game.Graphics.Shaders.HueShift; -using fluXis.Game.Graphics.Shaders.Pixelate; using fluXis.Game.Graphics.Shaders.Glitch; using fluXis.Game.Input; using fluXis.Game.Map; @@ -333,7 +332,6 @@ private ShaderStackContainer buildShaders() ShaderType.Vignette => new VignetteContainer(), ShaderType.Retro => new RetroContainer(), ShaderType.HueShift => new HueShiftContainer(), - ShaderType.Pixelate => new PixelateContainer(), ShaderType.Glitch => new GlitchContainer(), _ => null }; diff --git a/fluXis.Resources/Shaders/sh_Mosaic.fs b/fluXis.Resources/Shaders/sh_Mosaic.fs index 60f2a935..20a0f1ad 100644 --- a/fluXis.Resources/Shaders/sh_Mosaic.fs +++ b/fluXis.Resources/Shaders/sh_Mosaic.fs @@ -1,7 +1,7 @@ -layout(std140, set = 0, binding = 0) uniform m_MosaicParameters +layout(std140, set = 0, binding = 0) uniform m_PixelateParameters { vec2 g_TexSize; - float g_Strength; // 0 means no effect, 1 means 1x1 pixel blocks + float g_Strength; }; layout(set = 1, binding = 0) uniform texture2D m_Texture; @@ -11,7 +11,10 @@ layout(location = 0) out vec4 o_Colour; void main(void) { vec2 uv = gl_FragCoord.xy / g_TexSize; - float blockSize = g_TexSize.x * (1.0 - g_Strength); - vec2 blockPos = floor(uv * blockSize) / blockSize; - o_Colour = texture(sampler2D(m_Texture, m_Sampler), blockPos); + + float pixelSizeFactor = mix(1.0, min(g_TexSize.x, g_TexSize.y), 1.0 - g_Strength); + vec2 pixelSize = vec2(pixelSizeFactor, pixelSizeFactor * (g_TexSize.y / g_TexSize.x)); + vec2 pixelatedUV = (floor(uv * pixelSize) + 0.5) / pixelSize; + + o_Colour = textureLod(sampler2D(m_Texture, m_Sampler), pixelatedUV, 0.0); } diff --git a/fluXis.Resources/Shaders/sh_Pixelate.fs b/fluXis.Resources/Shaders/sh_Pixelate.fs deleted file mode 100644 index 20a0f1ad..00000000 --- a/fluXis.Resources/Shaders/sh_Pixelate.fs +++ /dev/null @@ -1,20 +0,0 @@ -layout(std140, set = 0, binding = 0) uniform m_PixelateParameters -{ - vec2 g_TexSize; - float g_Strength; -}; - -layout(set = 1, binding = 0) uniform texture2D m_Texture; -layout(set = 1, binding = 1) uniform sampler m_Sampler; - -layout(location = 0) out vec4 o_Colour; - -void main(void) { - vec2 uv = gl_FragCoord.xy / g_TexSize; - - float pixelSizeFactor = mix(1.0, min(g_TexSize.x, g_TexSize.y), 1.0 - g_Strength); - vec2 pixelSize = vec2(pixelSizeFactor, pixelSizeFactor * (g_TexSize.y / g_TexSize.x)); - vec2 pixelatedUV = (floor(uv * pixelSize) + 0.5) / pixelSize; - - o_Colour = textureLod(sampler2D(m_Texture, m_Sampler), pixelatedUV, 0.0); -}