-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from tylersfoot/main
Add new shaders + clean up code
- Loading branch information
Showing
25 changed files
with
692 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
fluXis.Game/Graphics/Shaders/HueShift/HueShiftContainer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.