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)
This commit is contained in:
@@ -82,8 +82,10 @@ namespace Content.Client.Eye.Blinding
|
||||
|
||||
if (_entityManager.TryGetComponent<EyeComponent>(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;
|
||||
|
||||
@@ -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<ShaderPrototype>("Cataracts").InstanceUnique();
|
||||
_circleMaskShader = _prototypeManager.Index<ShaderPrototype>("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<EyeComponent>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
<Control MinSize="4 0" />
|
||||
<OptionButton Name="HudLayoutOption" />
|
||||
</BoxContainer>
|
||||
<Label Text="{Loc 'ui-options-general-accessibility'}"
|
||||
FontColorOverride="{xNamespace:Static s:StyleNano.NanoGold}"
|
||||
StyleClasses="LabelKeyText"/>
|
||||
<CheckBox Name="ReducedMotionCheckBox" Text="{Loc 'ui-options-reduced-motion'}" />
|
||||
<Label Text="{Loc 'ui-options-general-discord'}"
|
||||
FontColorOverride="{xNamespace:Static s:StyleNano.NanoGold}"
|
||||
StyleClasses="LabelKeyText"/>
|
||||
|
||||
@@ -62,6 +62,7 @@ namespace Content.Client.Options.UI.Tabs
|
||||
OpaqueStorageWindowCheckBox.OnToggled += OnCheckBoxToggled;
|
||||
FancySpeechBubblesCheckBox.OnToggled += OnCheckBoxToggled;
|
||||
FancyNameBackgroundsCheckBox.OnToggled += OnCheckBoxToggled;
|
||||
ReducedMotionCheckBox.OnToggled += OnCheckBoxToggled;
|
||||
// ToggleWalk.OnToggled += OnCheckBoxToggled;
|
||||
StaticStorageUI.OnToggled += OnCheckBoxToggled;
|
||||
|
||||
@@ -109,6 +110,7 @@ namespace Content.Client.Options.UI.Tabs
|
||||
_cfg.SetCVar(CCVars.LoocAboveHeadShow, ShowLoocAboveHeadCheckBox.Pressed);
|
||||
_cfg.SetCVar(CCVars.ChatEnableFancyBubbles, FancySpeechBubblesCheckBox.Pressed);
|
||||
_cfg.SetCVar(CCVars.ChatFancyNameBackground, FancyNameBackgroundsCheckBox.Pressed);
|
||||
_cfg.SetCVar(CCVars.ReducedMotion, ReducedMotionCheckBox.Pressed);
|
||||
// _cfg.SetCVar(CCVars.ToggleWalk, ToggleWalk.Pressed);
|
||||
_cfg.SetCVar(CCVars.StaticStorageUI, StaticStorageUI.Pressed);
|
||||
|
||||
@@ -132,6 +134,7 @@ namespace Content.Client.Options.UI.Tabs
|
||||
var isLoocShowSame = ShowLoocAboveHeadCheckBox.Pressed == _cfg.GetCVar(CCVars.LoocAboveHeadShow);
|
||||
var isFancyChatSame = FancySpeechBubblesCheckBox.Pressed == _cfg.GetCVar(CCVars.ChatEnableFancyBubbles);
|
||||
var isFancyBackgroundSame = FancyNameBackgroundsCheckBox.Pressed == _cfg.GetCVar(CCVars.ChatFancyNameBackground);
|
||||
var isReducedMotionSame = ReducedMotionCheckBox.Pressed == _cfg.GetCVar(CCVars.ReducedMotion);
|
||||
// var isToggleWalkSame = ToggleWalk.Pressed == _cfg.GetCVar(CCVars.ToggleWalk);
|
||||
var isStaticStorageUISame = StaticStorageUI.Pressed == _cfg.GetCVar(CCVars.StaticStorageUI);
|
||||
|
||||
@@ -144,6 +147,7 @@ namespace Content.Client.Options.UI.Tabs
|
||||
isLoocShowSame &&
|
||||
isFancyChatSame &&
|
||||
isFancyBackgroundSame &&
|
||||
isReducedMotionSame &&
|
||||
// isToggleWalkSame &&
|
||||
isStaticStorageUISame;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user