Fix: Blindness radius when zooming (#23130)

* Fix Zoom while Blind

* Fix Zoom while Blind (ContentEyeComponent->EyeComponent)

(cherry picked from commit 345b0e6305c8deca327893cbe37b29576e6dcac8)
This commit is contained in:
Tomás Alves 2023-12-29 01:38:08 +00:00 committed by Debug
parent 5e0ddc4957
commit cdd86a8619
No known key found for this signature in database
GPG Key ID: 271270A74EF9C350
2 changed files with 20 additions and 7 deletions

View File

@ -1,9 +1,12 @@
using Content.Client.Movement.Systems;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Content.Shared.Eye.Blinding;
using Content.Shared.Eye.Blinding.Components;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Systems;
namespace Content.Client.Eye.Blinding
{
@ -11,9 +14,8 @@ namespace Content.Client.Eye.Blinding
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] IEntityManager _entityManager = default!;
[Dependency] ILightManager _lightManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly ILightManager _lightManager = default!;
public override bool RequestScreenTexture => true;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
@ -30,13 +32,13 @@ namespace Content.Client.Eye.Blinding
}
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;
@ -64,6 +66,11 @@ namespace Content.Client.Eye.Blinding
if (ScreenTexture == null)
return;
var playerEntity = _playerManager.LocalSession?.AttachedEntity;
if (playerEntity == null)
return;
if (!_blindableComponent.GraceFrame)
{
_blindableComponent.LightSetup = true; // Ok we touched the lights
@ -73,6 +80,10 @@ namespace Content.Client.Eye.Blinding
_blindableComponent.GraceFrame = false;
}
if (_entityManager.TryGetComponent<EyeComponent>(playerEntity, out var content))
{
_circleMaskShader?.SetParameter("ZOOM", content.Zoom.X);
}
_greyscaleShader?.SetParameter("SCREEN_TEXTURE", ScreenTexture);
var worldHandle = args.WorldHandle;

View File

@ -1,3 +1,5 @@
uniform highp float ZOOM;
highp vec4 circle(in highp vec2 uv, in highp vec2 pos, highp float rad, in highp vec3 color) {
highp float d = length(pos - uv) - rad;
highp float t = clamp(d, 0.0, 1.0);
@ -7,10 +9,10 @@ void fragment(){
highp vec2 uv = FRAGCOORD.xy;
highp vec2 res_xy = vec2(1.0/SCREEN_PIXEL_SIZE.x, 1.0/SCREEN_PIXEL_SIZE.y);
highp vec2 center = res_xy*0.5;
highp float radius = 0.05 * res_xy.y;
highp float radius = 0.05 * res_xy.y / ZOOM;
highp vec4 layer1 = vec4(vec3(0.0), 0.0);
highp vec4 layer2 = circle(uv, center, radius, vec3(0.0));
COLOR = mix(layer1, layer2, layer2.a);