Skip to content

Commit

Permalink
Merge pull request #96 from tylersfoot/main
Browse files Browse the repository at this point in the history
Add new shaders + clean up code
  • Loading branch information
flustix authored Oct 27, 2024
2 parents 6ef8dfb + 7f0e396 commit b817644
Show file tree
Hide file tree
Showing 25 changed files with 692 additions and 79 deletions.
14 changes: 10 additions & 4 deletions fluXis.Game/Graphics/Shaders/Bloom/BloomDrawNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public partial class BloomContainer
{
private class BloomContainerDrawNode : ShaderDrawNode<BloomContainer>
{
private IUniformBuffer<BlurParameters> blurParametersBuffer;
private float strength;
private IUniformBuffer<BlurParameters> parametersBuffer;

private int radius;

Expand Down Expand Up @@ -52,7 +52,7 @@ protected override void PopulateContents(IRenderer renderer)

private void drawFrameBuffer(IRenderer renderer, int kernelRadius, float sigma, int rotation)
{
blurParametersBuffer ??= renderer.CreateUniformBuffer<BlurParameters>();
parametersBuffer ??= renderer.CreateUniformBuffer<BlurParameters>();

IFrameBuffer current = SharedData.CurrentEffectBuffer;
IFrameBuffer target = SharedData.GetNextEffectBuffer();
Expand All @@ -61,21 +61,27 @@ private void drawFrameBuffer(IRenderer renderer, int kernelRadius, float sigma,
{
float radians = float.DegreesToRadians(rotation);

blurParametersBuffer.Data = blurParametersBuffer.Data with
parametersBuffer.Data = parametersBuffer.Data with
{
Radius = kernelRadius,
Sigma = sigma,
TexSize = current.Size,
Direction = new Vector2(MathF.Cos(radians), MathF.Sin(radians))
};

Shader.BindUniformBlock("m_BlurParameters", blurParametersBuffer);
Shader.BindUniformBlock("m_BlurParameters", 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 BlurParameters
{
Expand Down
17 changes: 8 additions & 9 deletions fluXis.Game/Graphics/Shaders/Chromatic/ChromaticDrawNote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class ChromaticContainer
private class ChromaticContainerDrawNode : ShaderDrawNode<ChromaticContainer>
{
private float strength;
private IUniformBuffer<ChromaticParameters> chromaticParametersBuffer;
private IUniformBuffer<ChromaticParameters> parametersBuffer;

public ChromaticContainerDrawNode(ChromaticContainer source, BufferedDrawNodeSharedData sharedData)
: base(source, sharedData)
Expand All @@ -32,12 +32,12 @@ protected override void PopulateContents(IRenderer renderer)
base.PopulateContents(renderer);

if (strength > 0)
drawFrameBuffer(renderer, strength);
drawFrameBuffer(renderer);
}

private void drawFrameBuffer(IRenderer renderer, float strength)
private void drawFrameBuffer(IRenderer renderer)
{
chromaticParametersBuffer ??= renderer.CreateUniformBuffer<ChromaticParameters>();
parametersBuffer ??= renderer.CreateUniformBuffer<ChromaticParameters>();

IFrameBuffer current = SharedData.CurrentEffectBuffer;
IFrameBuffer target = SharedData.GetNextEffectBuffer();
Expand All @@ -46,13 +46,13 @@ private void drawFrameBuffer(IRenderer renderer, float strength)

using (BindFrameBuffer(target))
{
chromaticParametersBuffer.Data = chromaticParametersBuffer.Data with
parametersBuffer.Data = parametersBuffer.Data with
{
TexSize = current.Size,
Radius = strength
};

Shader.BindUniformBlock("m_ChromaticParameters", chromaticParametersBuffer);
Shader.BindUniformBlock("m_ChromaticParameters", parametersBuffer);
Shader.Bind();
renderer.DrawFrameBuffer(current, new RectangleF(0, 0, current.Texture.Width, current.Texture.Height), ColourInfo.SingleColour(Color4.White));
Shader.Unbind();
Expand All @@ -62,16 +62,15 @@ private void drawFrameBuffer(IRenderer renderer, float strength)
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
chromaticParametersBuffer?.Dispose();
parametersBuffer?.Dispose();
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
private record struct ChromaticParameters
{
public UniformVector2 TexSize;
public UniformFloat Radius;
private readonly UniformPadding8 pad1;
private readonly UniformPadding12 pad2;
private readonly UniformPadding4 pad1;
}
}
}
11 changes: 11 additions & 0 deletions fluXis.Game/Graphics/Shaders/Glitch/GlitchContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using fluXis.Game.Map.Structures.Events;
using osu.Framework.Graphics;

namespace fluXis.Game.Graphics.Shaders.Glitch;

public partial class GlitchContainer : ShaderContainer
{
protected override string FragmentShader => "Glitch";
public override ShaderType Type => ShaderType.Glitch;
protected override DrawNode CreateShaderDrawNode() => new GlitchContainerDrawNode(this, SharedData);
}
86 changes: 86 additions & 0 deletions fluXis.Game/Graphics/Shaders/Glitch/GlitchDrawNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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.Glitch;

public partial class GlitchContainer
{
private class GlitchContainerDrawNode : ShaderDrawNode<GlitchContainer>
{
private float strength; // x strength
private float strength2; // y strength
private float strength3; // glitch block size
private IUniformBuffer<GlitchParameters> parametersBuffer;

public GlitchContainerDrawNode(GlitchContainer source, BufferedDrawNodeSharedData sharedData)
: base(source, sharedData)
{
}

public override void ApplyState()
{
base.ApplyState();

strength = Source.Strength / 10f;
strength2 = Source.Strength2 / 10f;
strength3 = Source.Strength3;
}

protected override void PopulateContents(IRenderer renderer)
{
base.PopulateContents(renderer);

if (strength > 0 || strength2 > 0)
drawFrameBuffer(renderer);
}

private void drawFrameBuffer(IRenderer renderer)
{
parametersBuffer ??= renderer.CreateUniformBuffer<GlitchParameters>();

IFrameBuffer current = SharedData.CurrentEffectBuffer;
IFrameBuffer target = SharedData.GetNextEffectBuffer();

renderer.SetBlend(BlendingParameters.None);

using (BindFrameBuffer(target))
{
parametersBuffer.Data = parametersBuffer.Data with
{
TexSize = current.Size,
StrengthX = strength,
StrengthY = strength2,
BlockSize = strength3,
Time = (float)Source.Time.Current % 10000f
};

Shader.BindUniformBlock("m_GlitchParameters", 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 GlitchParameters
{
public UniformVector2 TexSize;
public UniformFloat StrengthX;
public UniformFloat StrengthY;
public UniformFloat BlockSize;
public UniformFloat Time;
private readonly UniformPadding8 pad1;
}
}
}
24 changes: 16 additions & 8 deletions fluXis.Game/Graphics/Shaders/Greyscale/GreyscaleDrawNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,32 @@ public partial class GreyscaleContainer
{
private class GreyscaleDrawNode : ShaderDrawNode<GreyscaleContainer>
{
private IUniformBuffer<GreyscaleParameters> parameters;
private float strength;
private IUniformBuffer<GreyscaleParameters> parametersBuffer;

public GreyscaleDrawNode(ShaderContainer source, BufferedDrawNodeSharedData sharedData)
: base(source, sharedData)
{
}

public override void ApplyState()
{
base.ApplyState();

strength = Source.Strength;
}

protected override void PopulateContents(IRenderer renderer)
{
base.PopulateContents(renderer);
drawFrameBuffer(renderer);

if (strength > 0)
drawFrameBuffer(renderer);
}

private void drawFrameBuffer(IRenderer renderer)
{
parameters ??= renderer.CreateUniformBuffer<GreyscaleParameters>();
parametersBuffer ??= renderer.CreateUniformBuffer<GreyscaleParameters>();

IFrameBuffer current = SharedData.CurrentEffectBuffer;
IFrameBuffer target = SharedData.GetNextEffectBuffer();
Expand All @@ -36,13 +46,13 @@ private void drawFrameBuffer(IRenderer renderer)

using (BindFrameBuffer(target))
{
parameters.Data = parameters.Data with
parametersBuffer.Data = parametersBuffer.Data with
{
TexSize = current.Size,
Strength = Source.Strength
};

Shader.BindUniformBlock("m_GreyscaleParameters", parameters);
Shader.BindUniformBlock("m_GreyscaleParameters", parametersBuffer);
Shader.Bind();
renderer.DrawFrameBuffer(current, new RectangleF(0, 0, current.Texture.Width, current.Texture.Height), ColourInfo.SingleColour(Color4.White));
Shader.Unbind();
Expand All @@ -52,7 +62,7 @@ private void drawFrameBuffer(IRenderer renderer)
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
parameters?.Dispose();
parametersBuffer?.Dispose();
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
Expand All @@ -61,8 +71,6 @@ private record struct GreyscaleParameters
public UniformVector2 TexSize;
public UniformFloat Strength;
private readonly UniformPadding4 pad1;
private readonly UniformPadding4 pad2;
private readonly UniformPadding12 pad3;
}
}
}
11 changes: 11 additions & 0 deletions fluXis.Game/Graphics/Shaders/HueShift/HueShiftContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using fluXis.Game.Map.Structures.Events;
using osu.Framework.Graphics;

namespace fluXis.Game.Graphics.Shaders.HueShift;

public partial class HueShiftContainer : ShaderContainer
{
protected override string FragmentShader => "HueShift";
public override ShaderType Type => ShaderType.HueShift;
protected override DrawNode CreateShaderDrawNode() => new HueShiftContainerDrawNode(this, SharedData);
}
76 changes: 76 additions & 0 deletions fluXis.Game/Graphics/Shaders/HueShift/HueShiftDrawNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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.HueShift;

public partial class HueShiftContainer
{
private class HueShiftContainerDrawNode : ShaderDrawNode<HueShiftContainer>
{
private float strength;
private IUniformBuffer<HueShiftParameters> parametersBuffer;

public HueShiftContainerDrawNode(HueShiftContainer 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<HueShiftParameters>();

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_HueShiftParameters", 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 HueShiftParameters
{
public UniformVector2 TexSize;
public UniformFloat Strength;
private readonly UniformPadding4 pad1;
}
}
}
7 changes: 3 additions & 4 deletions fluXis.Game/Graphics/Shaders/Invert/InvertDrawNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ protected override void PopulateContents(IRenderer renderer)
base.PopulateContents(renderer);

if (strength > 0)
drawFrameBuffer(renderer, strength);
drawFrameBuffer(renderer);
}

private void drawFrameBuffer(IRenderer renderer, float strength)
private void drawFrameBuffer(IRenderer renderer)
{
invertParametersBuffer ??= renderer.CreateUniformBuffer<InvertParameters>();

Expand Down Expand Up @@ -70,8 +70,7 @@ private record struct InvertParameters
{
public UniformVector2 TexSize;
public UniformFloat Strength;
private readonly UniformPadding8 pad1;
private readonly UniformPadding12 pad2;
private readonly UniformPadding4 pad1;
}
}
}
Loading

0 comments on commit b817644

Please sign in to comment.