From aa6645c8e956be6abfffb58b43e67f479c45f962 Mon Sep 17 00:00:00 2001 From: deathride58 Date: Wed, 3 Jan 2024 04:07:02 -0500 Subject: [PATCH] Blindness rework - damaged eyes are now a stylized simulation of legal blindness (#23212) * blindness rework - damaged eyes now simulate legal blindness * hEY THATS FOR DEMONSTRATION PURPOSES ONLY AAA * attributions * makes eyeclosecomponent adminbus compatible * useshader(null) --- Content.Client/Eye/Blinding/BlindOverlay.cs | 4 +- .../Eye/Blinding/BlurryVisionOverlay.cs | 75 ++++++++-- Content.Client/Options/UI/Tabs/MiscTab.xaml | 4 + .../Options/UI/Tabs/MiscTab.xaml.cs | 4 + .../EyeProtection/EyeProtectionSystem.cs | 2 +- Content.Shared/CCVar/CCVars.cs | 12 ++ Content.Shared/Examine/ExamineSystemShared.cs | 4 +- .../Blinding/Components/BlindableComponent.cs | 2 +- .../Components/BlurryVisionComponent.cs | 9 +- .../Components/EyeClosingComponent.cs | 50 +++++++ .../Components/VisionCorrectionComponent.cs | 11 +- .../Eye/Blinding/Systems/BlindableSystem.cs | 50 ++++--- .../Eye/Blinding/Systems/BlindfoldSystem.cs | 6 +- .../Blinding/Systems/BlurryVisionSystem.cs | 39 +++-- .../Eye/Blinding/Systems/EyeClosingSystem.cs | 141 ++++++++++++++++++ .../Assorted/PermanentBlindnessSystem.cs | 37 +++-- Resources/Audio/Effects/attributions.yml | 5 + Resources/Audio/Effects/eye_close.ogg | Bin 0 -> 43044 bytes Resources/Audio/Effects/eye_open.ogg | Bin 0 -> 46932 bytes .../en-US/escape-menu/ui/options-menu.ftl | 2 + Resources/Locale/en-US/traits/traits.ftl | 4 +- Resources/Prototypes/Actions/types.yml | 12 ++ Resources/Prototypes/Shaders/shaders.yml | 12 ++ .../Textures/Interface/Actions/eyeclose.png | Bin 0 -> 9317 bytes .../Textures/Interface/Actions/eyeopen.png | Bin 0 -> 9062 bytes .../Textures/Interface/Actions/meta.json | 8 +- Resources/Textures/Shaders/cataracts.swsl | 76 ++++++++++ Resources/Textures/Shaders/circle_mask.swsl | 28 ++-- 28 files changed, 508 insertions(+), 89 deletions(-) create mode 100644 Content.Shared/Eye/Blinding/Components/EyeClosingComponent.cs create mode 100644 Content.Shared/Eye/Blinding/Systems/EyeClosingSystem.cs create mode 100644 Resources/Audio/Effects/eye_close.ogg create mode 100644 Resources/Audio/Effects/eye_open.ogg create mode 100644 Resources/Textures/Interface/Actions/eyeclose.png create mode 100644 Resources/Textures/Interface/Actions/eyeopen.png create mode 100644 Resources/Textures/Shaders/cataracts.swsl diff --git a/Content.Client/Eye/Blinding/BlindOverlay.cs b/Content.Client/Eye/Blinding/BlindOverlay.cs index 1730db59c6..0e380a515f 100644 --- a/Content.Client/Eye/Blinding/BlindOverlay.cs +++ b/Content.Client/Eye/Blinding/BlindOverlay.cs @@ -82,8 +82,10 @@ namespace Content.Client.Eye.Blinding if (_entityManager.TryGetComponent(playerEntity, out var content)) { - _circleMaskShader?.SetParameter("ZOOM", content.Zoom.X); + _circleMaskShader?.SetParameter("Zoom", content.Zoom.X); } + + _circleMaskShader?.SetParameter("SCREEN_TEXTURE", ScreenTexture); _greyscaleShader?.SetParameter("SCREEN_TEXTURE", ScreenTexture); var worldHandle = args.WorldHandle; diff --git a/Content.Client/Eye/Blinding/BlurryVisionOverlay.cs b/Content.Client/Eye/Blinding/BlurryVisionOverlay.cs index 7d0e7916da..b56b091309 100644 --- a/Content.Client/Eye/Blinding/BlurryVisionOverlay.cs +++ b/Content.Client/Eye/Blinding/BlurryVisionOverlay.cs @@ -1,9 +1,10 @@ using Robust.Client.Graphics; using Robust.Client.Player; +using Content.Shared.CCVar; using Robust.Shared.Enums; using Robust.Shared.Prototypes; -using Content.Shared.Eye.Blinding; using Content.Shared.Eye.Blinding.Components; +using Robust.Shared.Configuration; namespace Content.Client.Eye.Blinding { @@ -11,24 +12,45 @@ namespace Content.Client.Eye.Blinding { [Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IPlayerManager _playerManager = default!; + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [Dependency] private readonly IConfigurationManager _configManager = default!; + public override bool RequestScreenTexture => true; public override OverlaySpace Space => OverlaySpace.WorldSpace; + private readonly ShaderInstance _cataractsShader; + private readonly ShaderInstance _circleMaskShader; private float _magnitude; + private float _correctionPower = 2.0f; + + private const float Distortion_Pow = 2.0f; // Exponent for the distortion effect + private const float Cloudiness_Pow = 1.0f; // Exponent for the cloudiness effect + + private const float NoMotion_Radius = 30.0f; // Base radius for the nomotion variant at its full strength + private const float NoMotion_Pow = 0.2f; // Exponent for the nomotion variant's gradient + private const float NoMotion_Max = 8.0f; // Max value for the nomotion variant's gradient + private const float NoMotion_Mult = 0.75f; // Multiplier for the nomotion variant public BlurryVisionOverlay() { IoCManager.InjectDependencies(this); + _cataractsShader = _prototypeManager.Index("Cataracts").InstanceUnique(); + _circleMaskShader = _prototypeManager.Index("CircleMask").InstanceUnique(); + + _circleMaskShader.SetParameter("CircleMinDist", 0.0f); + _circleMaskShader.SetParameter("CirclePow", NoMotion_Pow); + _circleMaskShader.SetParameter("CircleMax", NoMotion_Max); + _circleMaskShader.SetParameter("CircleMult", NoMotion_Mult); } protected override bool BeforeDraw(in OverlayDrawArgs args) { - if (!_entityManager.TryGetComponent(_playerManager.LocalPlayer?.ControlledEntity, out EyeComponent? eyeComp)) + if (!_entityManager.TryGetComponent(_playerManager.LocalSession?.AttachedEntity, out EyeComponent? eyeComp)) return false; if (args.Viewport.Eye != eyeComp.Eye) return false; - var playerEntity = _playerManager.LocalPlayer?.ControlledEntity; + var playerEntity = _playerManager.LocalSession?.AttachedEntity; if (playerEntity == null) return false; @@ -44,21 +66,52 @@ namespace Content.Client.Eye.Blinding return false; _magnitude = blurComp.Magnitude; + _correctionPower = blurComp.CorrectionPower; return true; } protected override void Draw(in OverlayDrawArgs args) { - // TODO make this better. - // This is a really shitty effect. - // Maybe gradually shrink the view-size? - // Make the effect only apply to the edge of the viewport? - // Actually make it blurry?? - var opacity = 1f * _magnitude / BlurryVisionComponent.MaxMagnitude; + if (ScreenTexture == null) + return; + + var playerEntity = _playerManager.LocalSession?.AttachedEntity; + var worldHandle = args.WorldHandle; var viewport = args.WorldBounds; - worldHandle.SetTransform(Matrix3.Identity); - worldHandle.DrawRect(viewport, Color.Black.WithAlpha(opacity)); + var strength = (float) Math.Pow(Math.Min(_magnitude / BlurryVisionComponent.MaxMagnitude, 1.0f), _correctionPower); + + var zoom = 1.0f; + if (_entityManager.TryGetComponent(playerEntity, out var eyeComponent)) + { + zoom = eyeComponent.Zoom.X; + } + + // While the cataracts shader is designed to be tame enough to keep motion sickness at bay, the general waviness means that those who are particularly sensitive to motion sickness will probably hurl. + // So the reasonable alternative here is to replace it with a static effect! Specifically, one that replicates the blindness effect seen across most SS13 servers. + if (_configManager.GetCVar(CCVars.ReducedMotion)) + { + _circleMaskShader.SetParameter("SCREEN_TEXTURE", ScreenTexture); + _circleMaskShader.SetParameter("Zoom", zoom); + _circleMaskShader.SetParameter("CircleRadius", NoMotion_Radius / strength); + + worldHandle.UseShader(_circleMaskShader); + worldHandle.DrawRect(viewport, Color.White); + worldHandle.UseShader(null); + return; + } + + _cataractsShader.SetParameter("SCREEN_TEXTURE", ScreenTexture); + _cataractsShader.SetParameter("LIGHT_TEXTURE", args.Viewport.LightRenderTarget.Texture); // this is a little hacky but we spent way longer than we'd like to admit trying to do this a cleaner way to no avail + + _cataractsShader.SetParameter("Zoom", zoom); + + _cataractsShader.SetParameter("DistortionScalar", (float) Math.Pow(strength, Distortion_Pow)); + _cataractsShader.SetParameter("CloudinessScalar", (float) Math.Pow(strength, Cloudiness_Pow)); + + worldHandle.UseShader(_cataractsShader); + worldHandle.DrawRect(viewport, Color.White); + worldHandle.UseShader(null); } } } diff --git a/Content.Client/Options/UI/Tabs/MiscTab.xaml b/Content.Client/Options/UI/Tabs/MiscTab.xaml index 34712e5e2f..e37333b0e4 100644 --- a/Content.Client/Options/UI/Tabs/MiscTab.xaml +++ b/Content.Client/Options/UI/Tabs/MiscTab.xaml @@ -18,6 +18,10 @@ +