From aa2cd07b24d16c089e18a99796d8616ef76be987 Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Sun, 4 Feb 2024 20:12:40 -0500 Subject: [PATCH] Harpy Ultravision trait TODO: Optional trait that disables it --- .../DeltaV/Overlays/UltraVisionOverlay.cs | 44 ++++++++++++++++++ .../DeltaV/Overlays/UltraVisionSystem.cs | 46 +++++++++++++++++++ .../DeltaV/Abilities/UltraVisionComponent.cs | 8 ++++ .../Locale/en-US/deltav/traits/traits.ftl | 4 +- .../DeltaV/Entities/Mobs/Species/harpy.yml | 1 + .../Prototypes/DeltaV/Shaders/birdvision.yml | 4 ++ .../Prototypes/DeltaV/Traits/altvision.yml | 6 +++ .../Textures/DeltaV/Shaders/ultravision.swsl | 14 ++++++ 8 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 Content.Client/DeltaV/Overlays/UltraVisionOverlay.cs create mode 100644 Content.Client/DeltaV/Overlays/UltraVisionSystem.cs create mode 100644 Content.Shared/DeltaV/Abilities/UltraVisionComponent.cs create mode 100644 Resources/Prototypes/DeltaV/Shaders/birdvision.yml create mode 100644 Resources/Prototypes/DeltaV/Traits/altvision.yml create mode 100644 Resources/Textures/DeltaV/Shaders/ultravision.swsl diff --git a/Content.Client/DeltaV/Overlays/UltraVisionOverlay.cs b/Content.Client/DeltaV/Overlays/UltraVisionOverlay.cs new file mode 100644 index 00000000000..73c05e052b6 --- /dev/null +++ b/Content.Client/DeltaV/Overlays/UltraVisionOverlay.cs @@ -0,0 +1,44 @@ +using Robust.Client.Graphics; +using Robust.Client.Player; +using Robust.Shared.Enums; +using Robust.Shared.Prototypes; +using Content.Shared.Abilities; + +namespace Content.Client.DeltaV.Overlays; + +public sealed partial class UltraVisionOverlay : Overlay +{ + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [Dependency] private readonly IPlayerManager _playerManager = default!; + [Dependency] IEntityManager _entityManager = default!; + + + public override bool RequestScreenTexture => true; + public override OverlaySpace Space => OverlaySpace.WorldSpace; + private readonly ShaderInstance _ultraVisionShader; + + public UltraVisionOverlay() + { + IoCManager.InjectDependencies(this); + _ultraVisionShader = _prototypeManager.Index("UltraVision").Instance().Duplicate(); + } + + protected override void Draw(in OverlayDrawArgs args) + { + if (ScreenTexture == null) + return; + if (_playerManager.LocalPlayer?.ControlledEntity is not {Valid: true} player) + return; + if (!_entityManager.HasComponent(player)) + return; + + _ultraVisionShader?.SetParameter("SCREEN_TEXTURE", ScreenTexture); + + + var worldHandle = args.WorldHandle; + var viewport = args.WorldBounds; + worldHandle.SetTransform(Matrix3.Identity); + worldHandle.UseShader(_ultraVisionShader); + worldHandle.DrawRect(viewport, Color.White); + } +} diff --git a/Content.Client/DeltaV/Overlays/UltraVisionSystem.cs b/Content.Client/DeltaV/Overlays/UltraVisionSystem.cs new file mode 100644 index 00000000000..81cbfaa893f --- /dev/null +++ b/Content.Client/DeltaV/Overlays/UltraVisionSystem.cs @@ -0,0 +1,46 @@ +using Content.Shared.Abilities; +using Robust.Client.GameObjects; +using Robust.Client.Graphics; +using Robust.Client.Player; + +namespace Content.Client.DeltaV.Overlays; + +public sealed partial class UltraVisionSystem : EntitySystem +{ + [Dependency] private readonly IPlayerManager _player = default!; + [Dependency] private readonly IOverlayManager _overlayMan = default!; + + private UltraVisionOverlay _overlay = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnUltraVisionInit); + SubscribeLocalEvent(OnUltraVisionShutdown); + + _player.LocalPlayerAttached += OnAttachedChanged; + _player.LocalPlayerDetached += OnAttachedChanged; + + _overlay = new(); + } + + private void OnAttachedChanged(EntityUid uid) + { + _overlayMan.AddOverlay(_overlay); + } + + private void OnUltraVisionInit(EntityUid uid, UltraVisionComponent component, ComponentInit args) + { + if (_player.LocalPlayer?.ControlledEntity == uid) + _overlayMan.AddOverlay(_overlay); + } + + private void OnUltraVisionShutdown(EntityUid uid, UltraVisionComponent component, ComponentShutdown args) + { + if (_player.LocalPlayer?.ControlledEntity == uid) + { + _overlayMan.RemoveOverlay(_overlay); + } + } +} diff --git a/Content.Shared/DeltaV/Abilities/UltraVisionComponent.cs b/Content.Shared/DeltaV/Abilities/UltraVisionComponent.cs new file mode 100644 index 00000000000..5f631c54f25 --- /dev/null +++ b/Content.Shared/DeltaV/Abilities/UltraVisionComponent.cs @@ -0,0 +1,8 @@ +using Robust.Shared.GameStates; +namespace Content.Shared.Abilities; + +[RegisterComponent] +[NetworkedComponent] + +public sealed partial class UltraVisionComponent : Component +{} diff --git a/Resources/Locale/en-US/deltav/traits/traits.ftl b/Resources/Locale/en-US/deltav/traits/traits.ftl index 4bcbbc21bdf..7688903b4e3 100644 --- a/Resources/Locale/en-US/deltav/traits/traits.ftl +++ b/Resources/Locale/en-US/deltav/traits/traits.ftl @@ -1,2 +1,4 @@ trait-scottish-accent-name = Scottish Accent -trait-scottish-accent-desc = Fer tha folk who come frae Hielan clan. \ No newline at end of file +trait-scottish-accent-desc = Fer tha folk who come frae Hielan clan. +trait-ultravision-desc = Whether through custom bionic eyes, random mutation, + or being a Harpy, you perceive the world with ultraviolet light. diff --git a/Resources/Prototypes/DeltaV/Entities/Mobs/Species/harpy.yml b/Resources/Prototypes/DeltaV/Entities/Mobs/Species/harpy.yml index 4f27d5b83c8..1f836063c5e 100644 --- a/Resources/Prototypes/DeltaV/Entities/Mobs/Species/harpy.yml +++ b/Resources/Prototypes/DeltaV/Entities/Mobs/Species/harpy.yml @@ -125,6 +125,7 @@ - type: Inventory speciesId: harpy - type: HarpyVisuals + - type: UltraVision - type: entity save: false diff --git a/Resources/Prototypes/DeltaV/Shaders/birdvision.yml b/Resources/Prototypes/DeltaV/Shaders/birdvision.yml new file mode 100644 index 00000000000..43dc7ae2485 --- /dev/null +++ b/Resources/Prototypes/DeltaV/Shaders/birdvision.yml @@ -0,0 +1,4 @@ +- type: shader + id: UltraVision + kind: source + path: "/Textures/DeltaV/Shaders/ultravision.swsl" diff --git a/Resources/Prototypes/DeltaV/Traits/altvision.yml b/Resources/Prototypes/DeltaV/Traits/altvision.yml new file mode 100644 index 00000000000..f07fdc3e33a --- /dev/null +++ b/Resources/Prototypes/DeltaV/Traits/altvision.yml @@ -0,0 +1,6 @@ +- type: trait + id: UltraVision + name: Ultraviolet Vision + description: trait-ultravision-desc + components: + - type: UltraVision diff --git a/Resources/Textures/DeltaV/Shaders/ultravision.swsl b/Resources/Textures/DeltaV/Shaders/ultravision.swsl new file mode 100644 index 00000000000..a0dccaf2459 --- /dev/null +++ b/Resources/Textures/DeltaV/Shaders/ultravision.swsl @@ -0,0 +1,14 @@ +uniform sampler2D SCREEN_TEXTURE; + +void fragment() { + highp vec4 color = zTextureSpec(SCREEN_TEXTURE, UV); + + highp mat3 m = mat3( + vec3(0.000,1.000,0.000), + vec3(0.000,0.000,1.000), + vec3(-0.165,0.165,1.000) + ); + highp vec3 result = color.rgb * m; + + COLOR = vec4(result, 1); +}