Шейдер ударной волны для взрывов (#633)
* Adds shock wave shader (#2631) Co-authored-by: DOOM <N/A> Co-authored-by: Whisper <121047731+QuietlyWhisper@users.noreply.github.com> * add explosive shockwave * add shockwave to fireball * wd edit * cleanup * remove exgreande beeping sound --------- Co-authored-by: Vero <73014819+vero5123@users.noreply.github.com> Co-authored-by: Whisper <121047731+QuietlyWhisper@users.noreply.github.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using Content.Client._White.Chat;
|
||||
using Content.Client._White.JoinQueue;
|
||||
using Content.Client._White.Jukebox;
|
||||
using Content.Client._White.Overlays;
|
||||
using Content.Client._White.Reputation;
|
||||
using Content.Client._White.Sponsors;
|
||||
using Content.Client._White.Stalin;
|
||||
@@ -10,7 +9,6 @@ using Content.Client.Administration.Managers;
|
||||
using Content.Client.Changelog;
|
||||
using Content.Client.Chat.Managers;
|
||||
using Content.Client.Eui;
|
||||
using Content.Client.Flash;
|
||||
using Content.Client.Fullscreen;
|
||||
using Content.Client.GhostKick;
|
||||
using Content.Client.Guidebook;
|
||||
@@ -26,6 +24,7 @@ using Content.Client.Radiation.Overlays;
|
||||
using Content.Client.Replay;
|
||||
using Content.Client.Screenshot;
|
||||
using Content.Client.Singularity;
|
||||
using Content.Client._White.Explosion;
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Client.Viewport;
|
||||
using Content.Client.Voting;
|
||||
@@ -179,6 +178,7 @@ namespace Content.Client.Entry
|
||||
_parallaxManager.LoadDefaultParallax();
|
||||
|
||||
_overlayManager.AddOverlay(new SingularityOverlay());
|
||||
_overlayManager.AddOverlay(new ExplosionShockWaveOverlay());
|
||||
_overlayManager.AddOverlay(new RadiationPulseOverlay());
|
||||
// _overlayManager.AddOverlay(new GrainOverlay());
|
||||
// _overlayManager.AddOverlay(new AtmOverlay());
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Prototypes;
|
||||
using System.Numerics;
|
||||
using Content.Shared._White.Explosion;
|
||||
|
||||
namespace Content.Client._White.Explosion;
|
||||
|
||||
public sealed class ExplosionShockWaveOverlay : Overlay, IEntityEventSubscriber
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
private SharedTransformSystem? _xformSystem;
|
||||
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpace;
|
||||
public override bool RequestScreenTexture => true;
|
||||
|
||||
private readonly ShaderInstance _shader;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum number of distortions that can be shown on screen at a time.
|
||||
/// </summary>
|
||||
public const int MaxCount = 30;
|
||||
|
||||
public ExplosionShockWaveOverlay()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
_shader = _prototypeManager.Index<ShaderPrototype>("ShockWave").Instance().Duplicate();
|
||||
}
|
||||
|
||||
private readonly Vector2[] _positions = new Vector2[MaxCount];
|
||||
private readonly float[] _falloffPower = new float[MaxCount];
|
||||
private readonly float[] _sharpness = new float[MaxCount];
|
||||
private readonly float[] _width = new float[MaxCount];
|
||||
private int _count;
|
||||
protected override bool BeforeDraw(in OverlayDrawArgs args)
|
||||
{
|
||||
if (args.Viewport.Eye == null || _xformSystem is null && !_entMan.TrySystem(out _xformSystem))
|
||||
return false;
|
||||
|
||||
var query = _entMan.EntityQueryEnumerator<ExplosionShockWaveComponent, TransformComponent>();
|
||||
|
||||
_count = 0;
|
||||
|
||||
while (query.MoveNext(out var uid, out var distortion, out var xform))
|
||||
{
|
||||
if (xform.MapID != args.MapId)
|
||||
continue;
|
||||
|
||||
var mapPos = _xformSystem.GetWorldPosition(uid);
|
||||
|
||||
var tempCoords = args.Viewport.WorldToLocal(mapPos);
|
||||
|
||||
// normalized coords, 0 - 1 plane. This is pure hell, we subtract 1 because fragment calculates from the bottom and local goes from the top of the viewport
|
||||
tempCoords.Y = 1 - (tempCoords.Y / args.Viewport.Size.Y);
|
||||
tempCoords.X /= args.Viewport.Size.X;
|
||||
|
||||
_positions[_count] = tempCoords;
|
||||
_falloffPower[_count] = distortion.FalloffPower;
|
||||
_sharpness[_count] = distortion.Sharpness;
|
||||
_width[_count] = distortion.Width;
|
||||
_count++;
|
||||
|
||||
if (_count == MaxCount)
|
||||
break;
|
||||
}
|
||||
|
||||
return _count > 0;
|
||||
}
|
||||
|
||||
protected override void Draw(in OverlayDrawArgs args)
|
||||
{
|
||||
if (ScreenTexture == null || args.Viewport.Eye == null)
|
||||
return;
|
||||
|
||||
_shader?.SetParameter("renderScale", args.Viewport.RenderScale * args.Viewport.Eye.Scale);
|
||||
_shader?.SetParameter("count", _count);
|
||||
_shader?.SetParameter("position", _positions);
|
||||
_shader?.SetParameter("falloffPower", _falloffPower);
|
||||
_shader?.SetParameter("sharpness", _sharpness);
|
||||
_shader?.SetParameter("width", _width);
|
||||
_shader?.SetParameter("SCREEN_TEXTURE", ScreenTexture);
|
||||
|
||||
var worldHandle = args.WorldHandle;
|
||||
worldHandle.UseShader(_shader);
|
||||
worldHandle.DrawRect(args.WorldAABB, Color.White);
|
||||
worldHandle.UseShader(null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user