Replace MenuPaletteEffect with a post-processing shader.
This commit is contained in:
@@ -9,9 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Primitives;
|
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
@@ -19,97 +17,56 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
|
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
|
||||||
[Desc("Fades the world from/to black at the start/end of the game, and can (optionally) desaturate the world")]
|
[Desc("Fades the world from/to black at the start/end of the game, and can (optionally) desaturate the world")]
|
||||||
public class MenuPaletteEffectInfo : TraitInfo
|
public class MenuPostProcessEffectInfo : TraitInfo
|
||||||
{
|
{
|
||||||
[Desc("Time (in ticks) to fade between states")]
|
[Desc("Time (in ticks) to fade between states")]
|
||||||
public readonly int FadeLength = 10;
|
public readonly int FadeLength = 10;
|
||||||
|
|
||||||
[Desc("Effect style to fade to during gameplay. Accepts values of None or Desaturated.")]
|
[Desc("Effect style to fade to during gameplay. Accepts values of None or Desaturated.")]
|
||||||
public readonly MenuPaletteEffect.EffectType Effect = MenuPaletteEffect.EffectType.None;
|
public readonly MenuPostProcessEffect.EffectType Effect = MenuPostProcessEffect.EffectType.None;
|
||||||
|
|
||||||
[Desc("Effect style to fade to when opening the in-game menu. Accepts values of None, Black or Desaturated.")]
|
[Desc("Effect style to fade to when opening the in-game menu. Accepts values of None, Black or Desaturated.")]
|
||||||
public readonly MenuPaletteEffect.EffectType MenuEffect = MenuPaletteEffect.EffectType.None;
|
public readonly MenuPostProcessEffect.EffectType MenuEffect = MenuPostProcessEffect.EffectType.None;
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new MenuPaletteEffect(this); }
|
public override object Create(ActorInitializer init) { return new MenuPostProcessEffect(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MenuPaletteEffect : IPaletteModifier, IRender, IWorldLoaded, INotifyGameLoaded
|
public class MenuPostProcessEffect : RenderPostProcessPassBase, IWorldLoaded, INotifyGameLoaded
|
||||||
{
|
{
|
||||||
public enum EffectType { None, Black, Desaturated }
|
public enum EffectType { None, Black, Desaturated }
|
||||||
public readonly MenuPaletteEffectInfo Info;
|
public readonly MenuPostProcessEffectInfo Info;
|
||||||
|
|
||||||
EffectType from = EffectType.Black;
|
EffectType from = EffectType.Black;
|
||||||
EffectType to = EffectType.Black;
|
EffectType to = EffectType.Black;
|
||||||
|
|
||||||
float frac = 0;
|
|
||||||
long startTime;
|
long startTime;
|
||||||
long endTime;
|
long endTime;
|
||||||
|
|
||||||
public MenuPaletteEffect(MenuPaletteEffectInfo info) { Info = info; }
|
public MenuPostProcessEffect(MenuPostProcessEffectInfo info)
|
||||||
|
: base("menufade", PostProcessPassType.AfterShroud)
|
||||||
|
{
|
||||||
|
Info = info;
|
||||||
|
}
|
||||||
|
|
||||||
public void Fade(EffectType type)
|
public void Fade(EffectType type)
|
||||||
{
|
{
|
||||||
startTime = Game.RunTime;
|
startTime = Game.RunTime;
|
||||||
endTime = startTime + Ui.Timestep * Info.FadeLength;
|
endTime = startTime + Ui.Timestep * Info.FadeLength;
|
||||||
frac = 1;
|
|
||||||
|
|
||||||
from = to;
|
from = to;
|
||||||
to = type;
|
to = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<IRenderable> IRender.Render(Actor self, WorldRenderer wr)
|
protected override bool Enabled => to != EffectType.None || endTime != 0;
|
||||||
|
protected override void PrepareRender(WorldRenderer wr, IShader shader)
|
||||||
{
|
{
|
||||||
if (endTime == 0)
|
var blend = (endTime - Game.RunTime) * 1f / (endTime - startTime);
|
||||||
yield break;
|
if (blend < 0)
|
||||||
|
blend = startTime = endTime = 0;
|
||||||
|
|
||||||
frac = (endTime - Game.RunTime) * 1f / (endTime - startTime);
|
shader.SetVec("From", (int)from);
|
||||||
if (frac < 0)
|
shader.SetVec("To", (int)to);
|
||||||
frac = startTime = endTime = 0;
|
shader.SetVec("Blend", blend);
|
||||||
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerable<Rectangle> IRender.ScreenBounds(Actor self, WorldRenderer wr)
|
|
||||||
{
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Color ColorForEffect(EffectType t, Color orig)
|
|
||||||
{
|
|
||||||
switch (t)
|
|
||||||
{
|
|
||||||
case EffectType.Black:
|
|
||||||
return Color.FromArgb(orig.A, Color.Black);
|
|
||||||
case EffectType.Desaturated:
|
|
||||||
var lum = (int)(255 * orig.GetBrightness());
|
|
||||||
return Color.FromArgb(orig.A, lum, lum, lum);
|
|
||||||
default:
|
|
||||||
case EffectType.None:
|
|
||||||
return orig;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> palettes)
|
|
||||||
{
|
|
||||||
if (to == EffectType.None && endTime == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (var pal in palettes.Values)
|
|
||||||
{
|
|
||||||
for (var x = 0; x < Palette.Size; x++)
|
|
||||||
{
|
|
||||||
var orig = pal.GetColor(x);
|
|
||||||
var t = ColorForEffect(to, orig);
|
|
||||||
|
|
||||||
if (endTime == 0)
|
|
||||||
pal.SetColor(x, t);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var f = ColorForEffect(from, orig);
|
|
||||||
pal.SetColor(x, Exts.ColorLerp(frac, t, f));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IWorldLoaded.WorldLoaded(World w, WorldRenderer wr)
|
void IWorldLoaded.WorldLoaded(World w, WorldRenderer wr)
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright (c) The OpenRA Developers and Contributors
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation, either version 3 of
|
||||||
|
* the License, or (at your option) any later version. For more
|
||||||
|
* information, see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.UpdateRules.Rules
|
||||||
|
{
|
||||||
|
public class ReplacePaletteModifiers : UpdateRule
|
||||||
|
{
|
||||||
|
public override string Name => "Replace palette modifiers with post-processing shaders.";
|
||||||
|
|
||||||
|
public override string Description =>
|
||||||
|
"MenuPaletteEffect is renamed to MenuPostProcessEffect.";
|
||||||
|
|
||||||
|
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNodeBuilder actorNode)
|
||||||
|
{
|
||||||
|
actorNode.RenameChildrenMatching("MenuPaletteEffect", "MenuPostProcessEffect");
|
||||||
|
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -110,6 +110,7 @@ namespace OpenRA.Mods.Common.UpdateRules
|
|||||||
// bleed only changes here.
|
// bleed only changes here.
|
||||||
new RemoveValidRelationsFromCapturable(),
|
new RemoveValidRelationsFromCapturable(),
|
||||||
new ExtractResourceStorageFromHarvester(),
|
new ExtractResourceStorageFromHarvester(),
|
||||||
|
new ReplacePaletteModifiers(),
|
||||||
|
|
||||||
// Execute these rules last to avoid premature yaml merge crashes.
|
// Execute these rules last to avoid premature yaml merge crashes.
|
||||||
new AbstractDocking(),
|
new AbstractDocking(),
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
readonly Action onExit;
|
readonly Action onExit;
|
||||||
readonly World world;
|
readonly World world;
|
||||||
readonly WorldRenderer worldRenderer;
|
readonly WorldRenderer worldRenderer;
|
||||||
readonly MenuPaletteEffect mpe;
|
readonly MenuPostProcessEffect mpe;
|
||||||
readonly bool isSinglePlayer;
|
readonly bool isSinglePlayer;
|
||||||
readonly bool hasError;
|
readonly bool hasError;
|
||||||
bool leaving;
|
bool leaving;
|
||||||
@@ -184,7 +184,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
isSinglePlayer = !world.LobbyInfo.GlobalSettings.Dedicated && world.LobbyInfo.NonBotClients.Count() == 1;
|
isSinglePlayer = !world.LobbyInfo.GlobalSettings.Dedicated && world.LobbyInfo.NonBotClients.Count() == 1;
|
||||||
|
|
||||||
menu = widget.Get("INGAME_MENU");
|
menu = widget.Get("INGAME_MENU");
|
||||||
mpe = world.WorldActor.TraitOrDefault<MenuPaletteEffect>();
|
mpe = world.WorldActor.TraitOrDefault<MenuPostProcessEffect>();
|
||||||
mpe?.Fade(mpe.Info.MenuEffect);
|
mpe?.Fade(mpe.Info.MenuEffect);
|
||||||
|
|
||||||
menu.Get<LabelWidget>("VERSION_LABEL").Text = modData.Manifest.Metadata.Version;
|
menu.Get<LabelWidget>("VERSION_LABEL").Text = modData.Manifest.Metadata.Version;
|
||||||
@@ -249,13 +249,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
|
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
|
||||||
var exitDelay = iop?.ExitDelay ?? 0;
|
var exitDelay = iop?.ExitDelay ?? 0;
|
||||||
var mpe = world.WorldActor.TraitOrDefault<MenuPaletteEffect>();
|
var mpe = world.WorldActor.TraitOrDefault<MenuPostProcessEffect>();
|
||||||
if (mpe != null)
|
if (mpe != null)
|
||||||
{
|
{
|
||||||
Game.RunAfterDelay(exitDelay, () =>
|
Game.RunAfterDelay(exitDelay, () =>
|
||||||
{
|
{
|
||||||
if (Game.IsCurrentWorld(world))
|
if (Game.IsCurrentWorld(world))
|
||||||
mpe.Fade(MenuPaletteEffect.EffectType.Black);
|
mpe.Fade(MenuPostProcessEffect.EffectType.Black);
|
||||||
});
|
});
|
||||||
exitDelay += 40 * mpe.Info.FadeLength;
|
exitDelay += 40 * mpe.Info.FadeLength;
|
||||||
}
|
}
|
||||||
@@ -280,7 +280,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
void CloseMenu()
|
void CloseMenu()
|
||||||
{
|
{
|
||||||
Ui.CloseWindow();
|
Ui.CloseWindow();
|
||||||
mpe?.Fade(MenuPaletteEffect.EffectType.None);
|
mpe?.Fade(MenuPostProcessEffect.EffectType.None);
|
||||||
onExit();
|
onExit();
|
||||||
Ui.ResetTooltips();
|
Ui.ResetTooltips();
|
||||||
}
|
}
|
||||||
@@ -342,7 +342,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
if (mpe != null)
|
if (mpe != null)
|
||||||
{
|
{
|
||||||
if (Game.IsCurrentWorld(world))
|
if (Game.IsCurrentWorld(world))
|
||||||
mpe.Fade(MenuPaletteEffect.EffectType.Black);
|
mpe.Fade(MenuPostProcessEffect.EffectType.Black);
|
||||||
exitDelay += 40 * mpe.Info.FadeLength;
|
exitDelay += 40 * mpe.Info.FadeLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,7 +536,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
Ui.ResetTooltips();
|
Ui.ResetTooltips();
|
||||||
void CloseMenu()
|
void CloseMenu()
|
||||||
{
|
{
|
||||||
mpe?.Fade(MenuPaletteEffect.EffectType.None);
|
mpe?.Fade(MenuPostProcessEffect.EffectType.None);
|
||||||
onExit();
|
onExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
47
glsl/postprocess_menufade.frag
Normal file
47
glsl/postprocess_menufade.frag
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#version {VERSION}
|
||||||
|
#ifdef GL_ES
|
||||||
|
precision mediump float;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uniform float From;
|
||||||
|
uniform float To;
|
||||||
|
uniform float Blend;
|
||||||
|
uniform sampler2D WorldTexture;
|
||||||
|
|
||||||
|
#if __VERSION__ == 120
|
||||||
|
uniform vec2 WorldTextureSize;
|
||||||
|
#else
|
||||||
|
out vec4 fragColor;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
vec4 ColorForEffect(float effect, vec4 c)
|
||||||
|
{
|
||||||
|
if (effect > 1.5)
|
||||||
|
{
|
||||||
|
float lum = 0.5 * (min(c.r, min(c.g, c.b)) + max(c.r, max(c.g, c.b)));
|
||||||
|
return vec4(lum, lum, lum, c.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (effect > 0.5)
|
||||||
|
{
|
||||||
|
return vec4(0, 0, 0, c.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
#if __VERSION__ == 120
|
||||||
|
vec4 c = texture2D(WorldTexture, gl_FragCoord.xy / WorldTextureSize);
|
||||||
|
#else
|
||||||
|
vec4 c = texture(WorldTexture, gl_FragCoord.xy / textureSize(WorldTexture, 0));
|
||||||
|
#endif
|
||||||
|
c = ColorForEffect(From, c) * Blend + ColorForEffect(To, c) * (1.0 - Blend);
|
||||||
|
|
||||||
|
#if __VERSION__ == 120
|
||||||
|
gl_FragColor = c;
|
||||||
|
#else
|
||||||
|
fragColor = c;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@@ -97,7 +97,7 @@
|
|||||||
PlayerColorPalette:
|
PlayerColorPalette:
|
||||||
BasePalette: terrain
|
BasePalette: terrain
|
||||||
RemapIndex: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190
|
RemapIndex: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190
|
||||||
MenuPaletteEffect:
|
MenuPostProcessEffect:
|
||||||
MenuEffect: Desaturated
|
MenuEffect: Desaturated
|
||||||
CloakPaletteEffect:
|
CloakPaletteEffect:
|
||||||
FlashPaletteEffect:
|
FlashPaletteEffect:
|
||||||
|
|||||||
@@ -84,7 +84,7 @@
|
|||||||
BaseName: cloak
|
BaseName: cloak
|
||||||
BasePalette: player
|
BasePalette: player
|
||||||
Alpha: 0.55
|
Alpha: 0.55
|
||||||
MenuPaletteEffect:
|
MenuPostProcessEffect:
|
||||||
RotationPaletteEffect@defaultwater:
|
RotationPaletteEffect@defaultwater:
|
||||||
Palettes: terrain
|
Palettes: terrain
|
||||||
ExcludeTilesets: DESERT
|
ExcludeTilesets: DESERT
|
||||||
|
|||||||
@@ -160,4 +160,4 @@
|
|||||||
BasePalette: terraindecoration
|
BasePalette: terraindecoration
|
||||||
Name: terrainalpha
|
Name: terrainalpha
|
||||||
Alpha: 0.55
|
Alpha: 0.55
|
||||||
MenuPaletteEffect:
|
MenuPostProcessEffect:
|
||||||
|
|||||||
Reference in New Issue
Block a user