mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 03:23:03 +08:00
split shader, remove unnecessary clutter and fix some bugs
This commit is contained in:
parent
023924396d
commit
7d2958b7b0
@ -1,12 +1,12 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Rulesets.Catch.Objects;
|
||||
using osu.Game.Rulesets.Catch.UI;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Rulesets.Catch.Mods
|
||||
{
|
||||
@ -33,30 +33,16 @@ namespace osu.Game.Rulesets.Catch.Mods
|
||||
public CatchFlashlight(CatchPlayfield playfield)
|
||||
{
|
||||
this.playfield = playfield;
|
||||
MousePosWrapper.CircularFlashlightSize = getSizeFor(0);
|
||||
MousePosWrapper.Rectangular = false;
|
||||
FlashlightSize = new Vector2(0, getSizeFor(0));
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
MousePosWrapper.FlashlightPosition = (playfield.CatcherArea.MovableCatcher.ScreenSpaceDrawQuad.TopLeft + playfield.CatcherArea.MovableCatcher.ScreenSpaceDrawQuad.TopRight) / 2;
|
||||
MousePosWrapper.FlashlightPositionChanged = true;
|
||||
}
|
||||
var catcher = playfield.CatcherArea.MovableCatcher;
|
||||
|
||||
[UsedImplicitly]
|
||||
private float flashlightSize
|
||||
{
|
||||
set
|
||||
{
|
||||
if (MousePosWrapper.CircularFlashlightSize == value) return;
|
||||
|
||||
MousePosWrapper.CircularFlashlightSize = value;
|
||||
MousePosWrapper.CircularFlashlightSizeChanged = true;
|
||||
}
|
||||
|
||||
get => MousePosWrapper.CircularFlashlightSize;
|
||||
FlashlightPosition = catcher.ToSpaceOfOtherDrawable(catcher.Position, this);
|
||||
}
|
||||
|
||||
private float getSizeFor(int combo)
|
||||
@ -71,8 +57,10 @@ namespace osu.Game.Rulesets.Catch.Mods
|
||||
|
||||
protected override void OnComboChange(int newCombo)
|
||||
{
|
||||
this.TransformTo(nameof(flashlightSize), getSizeFor(newCombo), FLASHLIGHT_FADE_DURATION);
|
||||
this.TransformTo(nameof(FlashlightSize), new Vector2(0, getSizeFor(newCombo)), FLASHLIGHT_FADE_DURATION);
|
||||
}
|
||||
|
||||
protected override string FragmentShader => "CircularFlashlight";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,7 @@ namespace osu.Game.Rulesets.Mania.Mods
|
||||
{
|
||||
public ManiaFlashlight()
|
||||
{
|
||||
MousePosWrapper.Rectangular = true;
|
||||
MousePosWrapper.RectangularFlashlightSize = new Vector2(0, default_flashlight_size);
|
||||
FlashlightSize = new Vector2(0, default_flashlight_size);
|
||||
}
|
||||
|
||||
public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
|
||||
@ -32,11 +31,9 @@ namespace osu.Game.Rulesets.Mania.Mods
|
||||
{
|
||||
Schedule(() =>
|
||||
{
|
||||
MousePosWrapper.RectangularFlashlightSize.X = DrawWidth;
|
||||
MousePosWrapper.RectangularFlashlightSizeChanged = true;
|
||||
FlashlightSize = new Vector2(DrawWidth, FlashlightSize.Y);
|
||||
|
||||
MousePosWrapper.FlashlightPosition = ScreenSpaceDrawQuad.Centre;
|
||||
MousePosWrapper.FlashlightPositionChanged = true;
|
||||
FlashlightPosition = DrawPosition + DrawSize / 2;
|
||||
});
|
||||
}
|
||||
|
||||
@ -47,13 +44,13 @@ namespace osu.Game.Rulesets.Mania.Mods
|
||||
{
|
||||
}
|
||||
|
||||
protected override string FragmentShader => "RectangularFlashlight";
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
MousePosWrapper.RectangularFlashlightSize.X = DrawWidth;
|
||||
MousePosWrapper.RectangularFlashlightSizeChanged = true;
|
||||
FlashlightSize = new Vector2(DrawWidth, FlashlightSize.Y);
|
||||
|
||||
MousePosWrapper.FlashlightPosition = ScreenSpaceDrawQuad.Centre;
|
||||
MousePosWrapper.FlashlightPositionChanged = true;
|
||||
FlashlightPosition = DrawPosition + DrawSize / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Mods
|
||||
{
|
||||
@ -22,31 +22,15 @@ namespace osu.Game.Rulesets.Osu.Mods
|
||||
{
|
||||
public OsuFlashlight()
|
||||
{
|
||||
MousePosWrapper.CircularFlashlightSize = getSizeFor(0);
|
||||
MousePosWrapper.Rectangular = false;
|
||||
FlashlightSize = new Vector2(0, getSizeFor(0));
|
||||
}
|
||||
|
||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||
{
|
||||
MousePosWrapper.FlashlightPosition = e.ScreenSpaceMousePosition;
|
||||
MousePosWrapper.FlashlightPositionChanged = true;
|
||||
FlashlightPosition = e.MousePosition;
|
||||
return base.OnMouseMove(e);
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
private float flashlightSize
|
||||
{
|
||||
set
|
||||
{
|
||||
if (MousePosWrapper.CircularFlashlightSize == value) return;
|
||||
|
||||
MousePosWrapper.CircularFlashlightSize = value;
|
||||
MousePosWrapper.CircularFlashlightSizeChanged = true;
|
||||
}
|
||||
|
||||
get => MousePosWrapper.CircularFlashlightSize;
|
||||
}
|
||||
|
||||
private float getSizeFor(int combo)
|
||||
{
|
||||
if (combo > 200)
|
||||
@ -59,8 +43,10 @@ namespace osu.Game.Rulesets.Osu.Mods
|
||||
|
||||
protected override void OnComboChange(int newCombo)
|
||||
{
|
||||
this.TransformTo(nameof(flashlightSize), getSizeFor(newCombo), FLASHLIGHT_FADE_DURATION);
|
||||
this.TransformTo(nameof(FlashlightSize), new Vector2(0, getSizeFor(newCombo)), FLASHLIGHT_FADE_DURATION);
|
||||
}
|
||||
|
||||
protected override string FragmentShader => "CircularFlashlight";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Taiko.Objects;
|
||||
using osu.Game.Rulesets.Taiko.UI;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Rulesets.Taiko.Mods
|
||||
{
|
||||
@ -34,22 +33,7 @@ namespace osu.Game.Rulesets.Taiko.Mods
|
||||
public TaikoFlashlight(TaikoPlayfield taikoPlayfield)
|
||||
{
|
||||
this.taikoPlayfield = taikoPlayfield;
|
||||
MousePosWrapper.CircularFlashlightSize = getSizeFor(0);
|
||||
MousePosWrapper.Rectangular = false;
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
private float flashlightSize
|
||||
{
|
||||
set
|
||||
{
|
||||
if (MousePosWrapper.CircularFlashlightSize == value) return;
|
||||
|
||||
MousePosWrapper.CircularFlashlightSize = value;
|
||||
MousePosWrapper.CircularFlashlightSizeChanged = true;
|
||||
}
|
||||
|
||||
get => MousePosWrapper.CircularFlashlightSize;
|
||||
FlashlightSize = new Vector2(0, getSizeFor(0));
|
||||
}
|
||||
|
||||
private float getSizeFor(int combo)
|
||||
@ -64,17 +48,18 @@ namespace osu.Game.Rulesets.Taiko.Mods
|
||||
|
||||
protected override void OnComboChange(int newCombo)
|
||||
{
|
||||
this.TransformTo(nameof(flashlightSize), getSizeFor(newCombo), FLASHLIGHT_FADE_DURATION);
|
||||
this.TransformTo(nameof(FlashlightSize), new Vector2(0, getSizeFor(newCombo)), FLASHLIGHT_FADE_DURATION);
|
||||
}
|
||||
|
||||
protected override string FragmentShader => "CircularFlashlight";
|
||||
|
||||
public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
|
||||
{
|
||||
if ((invalidation & Invalidation.DrawSize) > 0)
|
||||
{
|
||||
Schedule(() =>
|
||||
{
|
||||
MousePosWrapper.FlashlightPosition = taikoPlayfield.HitExplosionContainer.ScreenSpaceDrawQuad.Centre;
|
||||
MousePosWrapper.FlashlightPositionChanged = true;
|
||||
FlashlightPosition = taikoPlayfield.HitTarget.ToSpaceOfOtherDrawable(taikoPlayfield.HitTarget.OriginPosition, this);
|
||||
});
|
||||
}
|
||||
|
||||
@ -85,8 +70,7 @@ namespace osu.Game.Rulesets.Taiko.Mods
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
MousePosWrapper.FlashlightPosition = taikoPlayfield.HitExplosionContainer.ScreenSpaceDrawQuad.Centre;
|
||||
MousePosWrapper.FlashlightPositionChanged = true;
|
||||
FlashlightPosition = taikoPlayfield.HitTarget.ToSpaceOfOtherDrawable(taikoPlayfield.HitTarget.OriginPosition, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,9 +43,10 @@ namespace osu.Game.Rulesets.Taiko.UI
|
||||
|
||||
protected override SpeedChangeVisualisationMethod VisualisationMethod => SpeedChangeVisualisationMethod.Overlapping;
|
||||
|
||||
internal readonly Container<HitExplosion> HitExplosionContainer;
|
||||
private readonly Container<HitExplosion> hitExplosionContainer;
|
||||
private readonly Container<KiaiHitExplosion> kiaiExplosionContainer;
|
||||
private readonly JudgementContainer<DrawableTaikoJudgement> judgementContainer;
|
||||
internal readonly HitTarget HitTarget;
|
||||
|
||||
private readonly Container topLevelHitContainer;
|
||||
|
||||
@ -103,13 +104,13 @@ namespace osu.Game.Rulesets.Taiko.UI
|
||||
Masking = true,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
HitExplosionContainer = new Container<HitExplosion>
|
||||
hitExplosionContainer = new Container<HitExplosion>
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
FillMode = FillMode.Fit,
|
||||
Blending = BlendingMode.Additive,
|
||||
},
|
||||
new HitTarget
|
||||
HitTarget = new HitTarget
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.Centre,
|
||||
@ -243,7 +244,7 @@ namespace osu.Game.Rulesets.Taiko.UI
|
||||
{
|
||||
case TaikoStrongJudgement _:
|
||||
if (result.IsHit)
|
||||
HitExplosionContainer.Children.FirstOrDefault(e => e.JudgedObject == ((DrawableStrongNestedHit)judgedObject).MainObject)?.VisualiseSecondHit();
|
||||
hitExplosionContainer.Children.FirstOrDefault(e => e.JudgedObject == ((DrawableStrongNestedHit)judgedObject).MainObject)?.VisualiseSecondHit();
|
||||
break;
|
||||
default:
|
||||
judgementContainer.Add(new DrawableTaikoJudgement(result, judgedObject)
|
||||
@ -259,7 +260,7 @@ namespace osu.Game.Rulesets.Taiko.UI
|
||||
|
||||
bool isRim = judgedObject.HitObject is RimHit;
|
||||
|
||||
HitExplosionContainer.Add(new HitExplosion(judgedObject, isRim));
|
||||
hitExplosionContainer.Add(new HitExplosion(judgedObject, isRim));
|
||||
|
||||
if (judgedObject.HitObject.Kiai)
|
||||
kiaiExplosionContainer.Add(new KiaiHitExplosion(judgedObject, isRim));
|
||||
|
@ -55,7 +55,6 @@ namespace osu.Game.Rulesets.Mods
|
||||
{
|
||||
internal BindableInt Combo;
|
||||
private Shader shader;
|
||||
protected readonly FlashlightUniformWrapper MousePosWrapper = new FlashlightUniformWrapper();
|
||||
|
||||
protected override DrawNode CreateDrawNode() => new FlashlightDrawNode();
|
||||
|
||||
@ -71,13 +70,14 @@ namespace osu.Game.Rulesets.Mods
|
||||
|
||||
flashNode.Shader = shader;
|
||||
flashNode.ScreenSpaceDrawQuad = ScreenSpaceDrawQuad;
|
||||
flashNode.MousePosWrapper = MousePosWrapper;
|
||||
flashNode.MousePosWrapper.FlashlightPosition = Vector2Extensions.Transform(FlashlightPosition, DrawInfo.Matrix);
|
||||
flashNode.MousePosWrapper.FlashlightSize = Vector2Extensions.Transform(FlashlightSize, DrawInfo.Matrix);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(ShaderManager shaderManager)
|
||||
{
|
||||
shader = shaderManager.Load("PositionAndColour", "Flashlight");
|
||||
shader = shaderManager.Load("PositionAndColour", FragmentShader);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
@ -90,27 +90,48 @@ namespace osu.Game.Rulesets.Mods
|
||||
|
||||
foreach (var breakPeriod in Breaks)
|
||||
{
|
||||
if (breakPeriod.Duration < FLASHLIGHT_FADE_DURATION * 2) continue;
|
||||
|
||||
this.Delay(breakPeriod.StartTime + FLASHLIGHT_FADE_DURATION).FadeOutFromOne(FLASHLIGHT_FADE_DURATION);
|
||||
this.Delay(breakPeriod.EndTime - FLASHLIGHT_FADE_DURATION).FadeInFromZero(FLASHLIGHT_FADE_DURATION);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void OnComboChange(int newCombo);
|
||||
|
||||
protected abstract string FragmentShader { get; }
|
||||
|
||||
private Vector2 flashlightPosition;
|
||||
protected Vector2 FlashlightPosition
|
||||
{
|
||||
get => flashlightPosition;
|
||||
set
|
||||
{
|
||||
if (flashlightPosition == value) return;
|
||||
|
||||
flashlightPosition = value;
|
||||
Invalidate(Invalidation.DrawNode);
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2 flashlightSize;
|
||||
protected Vector2 FlashlightSize
|
||||
{
|
||||
get => flashlightSize;
|
||||
set
|
||||
{
|
||||
if (flashlightSize == value) return;
|
||||
|
||||
flashlightSize = value;
|
||||
Invalidate(Invalidation.DrawNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class FlashlightUniformWrapper
|
||||
public struct FlashlightUniformWrapper
|
||||
{
|
||||
public bool Rectangular;
|
||||
public bool RectangularChanged = true;
|
||||
|
||||
public Vector2 FlashlightPosition;
|
||||
public bool FlashlightPositionChanged = true;
|
||||
|
||||
public float CircularFlashlightSize;
|
||||
public bool CircularFlashlightSizeChanged = true;
|
||||
|
||||
public Vector2 RectangularFlashlightSize;
|
||||
public bool RectangularFlashlightSizeChanged = true;
|
||||
public Vector2 FlashlightSize;
|
||||
}
|
||||
|
||||
private class FlashlightDrawNode : DrawNode
|
||||
@ -125,29 +146,8 @@ namespace osu.Game.Rulesets.Mods
|
||||
|
||||
Shader.Bind();
|
||||
|
||||
if (MousePosWrapper.RectangularChanged)
|
||||
{
|
||||
Shader.GetUniform<bool>("rectangular").UpdateValue(ref MousePosWrapper.Rectangular);
|
||||
MousePosWrapper.RectangularChanged = false;
|
||||
}
|
||||
|
||||
if (MousePosWrapper.FlashlightPositionChanged)
|
||||
{
|
||||
Shader.GetUniform<Vector2>("flashlightPos").UpdateValue(ref MousePosWrapper.FlashlightPosition);
|
||||
MousePosWrapper.FlashlightPositionChanged = false;
|
||||
}
|
||||
|
||||
if (MousePosWrapper.CircularFlashlightSizeChanged)
|
||||
{
|
||||
Shader.GetUniform<float>("circularFlashlightSize").UpdateValue(ref MousePosWrapper.CircularFlashlightSize);
|
||||
MousePosWrapper.CircularFlashlightSizeChanged = false;
|
||||
}
|
||||
|
||||
if (MousePosWrapper.RectangularFlashlightSizeChanged)
|
||||
{
|
||||
Shader.GetUniform<Vector2>("rectangularFlashlightSize").UpdateValue(ref MousePosWrapper.RectangularFlashlightSize);
|
||||
MousePosWrapper.RectangularFlashlightSizeChanged = false;
|
||||
}
|
||||
Shader.GetUniform<Vector2>("flashlightPos").UpdateValue(ref MousePosWrapper.FlashlightPosition);
|
||||
Shader.GetUniform<Vector2>("flashlightSize").UpdateValue(ref MousePosWrapper.FlashlightSize);
|
||||
|
||||
Texture.WhitePixel.DrawQuad(ScreenSpaceDrawQuad, DrawColourInfo.Colour, vertexAction: vertexAction);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user