Replace ChronoshiftPaletteEffect with a post-processing shader.
This commit is contained in:
@@ -101,7 +101,7 @@ namespace OpenRA.Mods.Cnc.Activities
|
|||||||
|
|
||||||
// Trigger screen desaturate effect
|
// Trigger screen desaturate effect
|
||||||
if (screenFlash)
|
if (screenFlash)
|
||||||
foreach (var a in self.World.ActorsWithTrait<ChronoshiftPaletteEffect>())
|
foreach (var a in self.World.ActorsWithTrait<ChronoshiftPostProcessEffect>())
|
||||||
a.Trait.Enable();
|
a.Trait.Enable();
|
||||||
|
|
||||||
if (teleporter != null && self != teleporter && !teleporter.Disposed)
|
if (teleporter != null && self != teleporter && !teleporter.Disposed)
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
TriggerVortex();
|
TriggerVortex();
|
||||||
|
|
||||||
// Trigger screen desaturate effect
|
// Trigger screen desaturate effect
|
||||||
foreach (var cpa in self.World.ActorsWithTrait<ChronoshiftPaletteEffect>())
|
foreach (var cpa in self.World.ActorsWithTrait<ChronoshiftPostProcessEffect>())
|
||||||
cpa.Trait.Enable();
|
cpa.Trait.Enable();
|
||||||
|
|
||||||
Game.Sound.Play(SoundType.World, info.ChronoshiftSound, self.CenterPosition);
|
Game.Sound.Play(SoundType.World, info.ChronoshiftSound, self.CenterPosition);
|
||||||
|
|||||||
@@ -9,29 +9,29 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Cnc.Traits
|
namespace OpenRA.Mods.Cnc.Traits
|
||||||
{
|
{
|
||||||
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
|
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
|
||||||
[Desc("Apply palette full screen rotations during chronoshifts. Add this to the world actor.")]
|
[Desc("Apply palette full screen rotations during chronoshifts. Add this to the world actor.")]
|
||||||
public class ChronoshiftPaletteEffectInfo : TraitInfo
|
public class ChronoshiftPostProcessEffectInfo : TraitInfo
|
||||||
{
|
{
|
||||||
[Desc("Measured in ticks.")]
|
[Desc("Measured in ticks.")]
|
||||||
public readonly int ChronoEffectLength = 60;
|
public readonly int ChronoEffectLength = 60;
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new ChronoshiftPaletteEffect(this); }
|
public override object Create(ActorInitializer init) { return new ChronoshiftPostProcessEffect(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ChronoshiftPaletteEffect : IPaletteModifier, ITick
|
public class ChronoshiftPostProcessEffect : RenderPostProcessPassBase, ITick
|
||||||
{
|
{
|
||||||
readonly ChronoshiftPaletteEffectInfo info;
|
readonly ChronoshiftPostProcessEffectInfo info;
|
||||||
int remainingFrames;
|
int remainingFrames;
|
||||||
|
|
||||||
public ChronoshiftPaletteEffect(ChronoshiftPaletteEffectInfo info)
|
public ChronoshiftPostProcessEffect(ChronoshiftPostProcessEffectInfo info)
|
||||||
|
: base("chronoshift", PostProcessPassType.AfterWorld)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
@@ -47,23 +47,10 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
remainingFrames--;
|
remainingFrames--;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IPaletteModifier.AdjustPalette(IReadOnlyDictionary<string, MutablePalette> palettes)
|
protected override bool Enabled => remainingFrames > 0;
|
||||||
|
protected override void PrepareRender(WorldRenderer wr, IShader shader)
|
||||||
{
|
{
|
||||||
if (remainingFrames == 0)
|
shader.SetVec("Blend", (float)remainingFrames / info.ChronoEffectLength);
|
||||||
return;
|
|
||||||
|
|
||||||
var frac = (float)remainingFrames / info.ChronoEffectLength;
|
|
||||||
|
|
||||||
foreach (var pal in palettes)
|
|
||||||
{
|
|
||||||
for (var x = 0; x < Palette.Size; x++)
|
|
||||||
{
|
|
||||||
var orig = pal.Value.GetColor(x);
|
|
||||||
var lum = (int)(255 * orig.GetBrightness());
|
|
||||||
var desat = Color.FromArgb(orig.A, lum, lum, lum);
|
|
||||||
pal.Value.SetColor(x, Exts.ColorLerp(frac, orig, desat));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,11 +18,13 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
|
|||||||
public override string Name => "Replace palette modifiers with post-processing shaders.";
|
public override string Name => "Replace palette modifiers with post-processing shaders.";
|
||||||
|
|
||||||
public override string Description =>
|
public override string Description =>
|
||||||
"MenuPaletteEffect is renamed to MenuPostProcessEffect.";
|
"MenuPaletteEffect is renamed to MenuPostProcessEffect.\n" +
|
||||||
|
"ChronoshiftPaletteEffect is renamed to ChronoshiftPostProcessEffect.";
|
||||||
|
|
||||||
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNodeBuilder actorNode)
|
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNodeBuilder actorNode)
|
||||||
{
|
{
|
||||||
actorNode.RenameChildrenMatching("MenuPaletteEffect", "MenuPostProcessEffect");
|
actorNode.RenameChildrenMatching("MenuPaletteEffect", "MenuPostProcessEffect");
|
||||||
|
actorNode.RenameChildrenMatching("ChronoshiftPaletteEffect", "ChronoshiftPostProcessEffect");
|
||||||
|
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|||||||
31
glsl/postprocess_chronoshift.frag
Normal file
31
glsl/postprocess_chronoshift.frag
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#version {VERSION}
|
||||||
|
#ifdef GL_ES
|
||||||
|
precision mediump float;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uniform float Blend;
|
||||||
|
uniform sampler2D WorldTexture;
|
||||||
|
|
||||||
|
#if __VERSION__ == 120
|
||||||
|
uniform vec2 WorldTextureSize;
|
||||||
|
#else
|
||||||
|
out vec4 fragColor;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
float lum = 0.5 * (min(c.r, min(c.g, c.b)) + max(c.r, max(c.g, c.b)));
|
||||||
|
c = vec4(lum, lum, lum, c.a) * Blend + c * (1.0 - Blend);
|
||||||
|
|
||||||
|
#if __VERSION__ == 120
|
||||||
|
gl_FragColor = c;
|
||||||
|
#else
|
||||||
|
fragColor = c;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@@ -22,7 +22,7 @@ World:
|
|||||||
ClearNoSmudges: 100
|
ClearNoSmudges: 100
|
||||||
|
|
||||||
^Palettes:
|
^Palettes:
|
||||||
-ChronoshiftPaletteEffect:
|
-ChronoshiftPostProcessEffect:
|
||||||
|
|
||||||
# Used in ChronoEffect.
|
# Used in ChronoEffect.
|
||||||
1TNK:
|
1TNK:
|
||||||
|
|||||||
@@ -99,7 +99,7 @@
|
|||||||
RotationBase: 32
|
RotationBase: 32
|
||||||
LightPaletteRotator:
|
LightPaletteRotator:
|
||||||
ExcludePalettes: terrain, effect, desert
|
ExcludePalettes: terrain, effect, desert
|
||||||
ChronoshiftPaletteEffect:
|
ChronoshiftPostProcessEffect:
|
||||||
FlashPaletteEffect@NUKE:
|
FlashPaletteEffect@NUKE:
|
||||||
Type: Nuke
|
Type: Nuke
|
||||||
IndexedPalette@CIV2:
|
IndexedPalette@CIV2:
|
||||||
|
|||||||
Reference in New Issue
Block a user