-
-
Notifications
You must be signed in to change notification settings - Fork 20
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 #594 from LumpBloom7/NoteShader
Use custom shader for LanedNotes
- Loading branch information
Showing
16 changed files
with
420 additions
and
118 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
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
157 changes: 157 additions & 0 deletions
157
osu.Game.Rulesets.Sentakki/Objects/Drawables/Pieces/LaneNoteVisual.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,157 @@ | ||
using System.Runtime.InteropServices; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Rendering; | ||
using osu.Framework.Graphics.Shaders; | ||
using osu.Framework.Graphics.Shaders.Types; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Game.Rulesets.Objects.Drawables; | ||
using osuTK; | ||
|
||
namespace osu.Game.Rulesets.Sentakki.Objects.Drawables.Pieces; | ||
|
||
public enum NoteShape | ||
{ | ||
Ring, | ||
Hex, | ||
Star | ||
} | ||
|
||
public partial class LaneNoteVisual : Sprite, ITexturedShaderDrawable | ||
{ | ||
public NoteShape Shape { get; init; } = NoteShape.Ring; | ||
private float thickness = 0.25f; | ||
public float Thickness | ||
{ | ||
get => thickness; | ||
set | ||
{ | ||
if (thickness == value) | ||
return; | ||
thickness = value; | ||
Invalidate(Invalidation.DrawNode); | ||
} | ||
} | ||
|
||
private float shadowRadius = 15f / 105f; | ||
public float ShadowRadius | ||
{ | ||
get => shadowRadius; | ||
set | ||
{ | ||
if (shadowRadius == value) | ||
return; | ||
shadowRadius = value; | ||
Invalidate(Invalidation.DrawNode); | ||
} | ||
} | ||
|
||
private bool glow; | ||
public bool Glow | ||
{ | ||
get => glow; | ||
set | ||
{ | ||
if (glow == value) | ||
return; | ||
glow = value; | ||
Invalidate(Invalidation.DrawNode); | ||
} | ||
} | ||
|
||
public new IShader TextureShader { get; private set; } = null!; | ||
|
||
protected override DrawNode CreateDrawNode() => new LaneNoteVisualDrawNode(this); | ||
|
||
private BindableBool exBindable = new BindableBool(); | ||
|
||
private string fragmentShaderFor(NoteShape shape) | ||
{ | ||
switch (shape) | ||
{ | ||
case NoteShape.Ring: | ||
default: | ||
return "ringNote"; | ||
case NoteShape.Hex: | ||
return "hexNote"; | ||
case NoteShape.Star: | ||
return "starNote"; | ||
} | ||
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(ShaderManager shaders, IRenderer renderer, DrawableHitObject? hitObject) | ||
{ | ||
TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, fragmentShaderFor(Shape)); | ||
Texture = renderer.WhitePixel; | ||
|
||
if (hitObject is null) | ||
return; | ||
|
||
// Bind exnote | ||
exBindable.BindTo(((DrawableSentakkiHitObject)hitObject).ExBindable); | ||
exBindable.BindValueChanged(b => Glow = b.NewValue, true); | ||
} | ||
|
||
private partial class LaneNoteVisualDrawNode : SpriteDrawNode | ||
{ | ||
protected new LaneNoteVisual Source => (LaneNoteVisual)base.Source; | ||
protected override bool CanDrawOpaqueInterior => false; | ||
private IUniformBuffer<ShapeParameters>? shapeParameters; | ||
|
||
private float thickness; | ||
private Vector2 size; | ||
private bool glow; | ||
private float shadowRadius; | ||
|
||
public LaneNoteVisualDrawNode(LaneNoteVisual source) | ||
: base(source) | ||
{ | ||
} | ||
|
||
public override void ApplyState() | ||
{ | ||
base.ApplyState(); | ||
thickness = Source.Thickness; | ||
size = Source.DrawSize; | ||
shadowRadius = Source.shadowRadius; | ||
glow = Source.Glow; | ||
} | ||
|
||
protected override void BindUniformResources(IShader shader, IRenderer renderer) | ||
{ | ||
base.BindUniformResources(shader, renderer); | ||
|
||
shapeParameters ??= renderer.CreateUniformBuffer<ShapeParameters>(); | ||
|
||
shapeParameters.Data = shapeParameters.Data with | ||
{ | ||
Thickness = thickness, | ||
Size = size, | ||
ShadowRadius = shadowRadius, | ||
Glow = glow, | ||
}; | ||
|
||
shader.BindUniformBlock("m_shapeParameters", shapeParameters); | ||
} | ||
|
||
protected override void Dispose(bool isDisposing) | ||
{ | ||
base.Dispose(isDisposing); | ||
shapeParameters?.Dispose(); | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential, Pack = 1)] | ||
private record struct ShapeParameters | ||
{ | ||
public UniformFloat Thickness; | ||
public UniformPadding4 _; | ||
public UniformVector2 Size; | ||
public UniformFloat ShadowRadius; | ||
public UniformBool Glow; | ||
|
||
public UniformPadding8 __; | ||
} | ||
} | ||
} |
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
67 changes: 0 additions & 67 deletions
67
osu.Game.Rulesets.Sentakki/Objects/Drawables/Pieces/ShadowPiece.cs
This file was deleted.
Oops, something went wrong.
35 changes: 8 additions & 27 deletions
35
osu.Game.Rulesets.Sentakki/Objects/Drawables/Pieces/Slides/StarPiece.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 |
---|---|---|
@@ -1,51 +1,32 @@ | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Framework.Graphics.Textures; | ||
using osu.Game.Rulesets.Objects.Drawables; | ||
using osuTK.Graphics; | ||
|
||
namespace osu.Game.Rulesets.Sentakki.Objects.Drawables.Pieces.Slides | ||
{ | ||
public partial class StarPiece : CompositeDrawable | ||
{ | ||
private Sprite glowTexture = null!; | ||
|
||
private Bindable<bool> ExBindable = new Bindable<bool>(); | ||
|
||
private const float base_circle_size = 75; | ||
private const float drawable_size = base_circle_size + 30; // 30 units for shadow | ||
public StarPiece() | ||
{ | ||
Anchor = Anchor.Centre; | ||
Origin = Anchor.Centre; | ||
Padding = new MarginPadding(-drawable_size / 2); | ||
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(TextureStore textures, DrawableHitObject? hitObject) | ||
private void load() | ||
{ | ||
AddRangeInternal(new Drawable[]{ | ||
glowTexture = new Sprite | ||
{ | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
Texture = textures.Get("starGlow"), | ||
Colour = Color4.Black | ||
}, | ||
new Sprite | ||
{ | ||
new LaneNoteVisual{ | ||
RelativeSizeAxes = Axes.Both, | ||
|
||
Shape = NoteShape.Star, | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
Texture = textures.Get("star"), | ||
} | ||
}); | ||
|
||
if (hitObject is null) | ||
return; | ||
|
||
// Bind exnote | ||
ExBindable.BindTo(((DrawableSentakkiHitObject)hitObject).ExBindable); | ||
ExBindable.BindValueChanged(v => glowTexture.Colour = v.NewValue ? Color4.White : Color4.Black, true); | ||
} | ||
} | ||
} |
Oops, something went wrong.