Skip to content

Commit

Permalink
Fix the pixel shader.
Browse files Browse the repository at this point in the history
Co-authored-by: WebFreak001 <[email protected]>
  • Loading branch information
andy840119 and WebFreak001 committed Mar 19, 2023
1 parent c7a32d6 commit f20da1b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
18 changes: 16 additions & 2 deletions osu.Framework.Font/Graphics/Shaders/PixelShader.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) karaoke.dev <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Runtime.InteropServices;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Shaders.Types;
using osuTK;

namespace osu.Framework.Graphics.Shaders;
Expand All @@ -12,9 +14,21 @@ public class PixelShader : InternalShader, IHasTextureSize, IHasInflationPercent

public Vector2 Size { get; set; } = new(5);

private IUniformBuffer<PixelParameters>? pixelParametersBuffer;

public override void ApplyValue(IRenderer renderer)
{
var size = Size;
GetUniform<Vector2>(@"g_Size").UpdateValue(ref size);
pixelParametersBuffer ??= renderer.CreateUniformBuffer<PixelParameters>();

pixelParametersBuffer.Data = new PixelParameters { Size = Size };

BindUniformBlock("m_PixelParameters", pixelParametersBuffer);
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
private record struct PixelParameters
{
public UniformVector2 Size;
private readonly UniformPadding8 pad1;
}
}
16 changes: 10 additions & 6 deletions osu.Framework.Font/Resources/Shaders/sh_Pixel.fs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// see the demo: https://www.geeks3d.com/20101029/shader-library-pixelation-post-processing-effect-glsl/
#include "sh_CustomizedShaderGlobalUniforms.h"
#include "sh_Utils.h"

varying mediump vec2 v_TexCoord;
layout(location = 2) in mediump vec2 v_TexCoord;

uniform lowp sampler2D m_Sampler;
layout(std140, set = 2, binding = 0) uniform m_PixelParameters
{
mediump vec2 g_Size;
};

uniform mediump vec2 g_TexSize;
uniform mediump vec2 g_Size;
uniform float g_InflationPercentage;
layout(set = 1, binding = 0) uniform lowp texture2D m_Texture;
layout(set = 1, binding = 1) uniform lowp sampler m_Sampler;

layout(location = 0) out vec4 o_Colour;

void main(void)
{
Expand All @@ -17,5 +21,5 @@ void main(void)
uv = uv * separaorParts;
uv = floor(uv);
uv = uv / separaorParts;
gl_FragColor = toSRGB(texture2D(m_Sampler, uv));
o_Colour = toSRGB(texture(sampler2D(m_Texture, m_Sampler), uv));
}

0 comments on commit f20da1b

Please sign in to comment.