Skip to content

Commit

Permalink
toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
Not Quite Hadouken committed Feb 1, 2025
1 parent 52b9c9c commit f53350d
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Resources/Shaders/Internal/light_shared.swsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ uniform highp float lightRange;
uniform highp float lightPower;
uniform highp float lightSoftness;
uniform highp float lightIndex;
uniform int useNormals;
uniform highp float globalRotation;
uniform highp float maskRotation;
uniform sampler2D shadowMap;
Expand Down Expand Up @@ -65,6 +66,11 @@ void fragment()
val *= lightPower;
val *= mask;

COLOR = vec4(lightColor.xyz, val * occlusion);

if (useNormals == 0)
return;

// how this works
// globalRotation: rotation of the eye plus rotation of the light minus rotation of the map
// eyeCenter: center of the eye plus offset
Expand Down Expand Up @@ -100,6 +106,6 @@ void fragment()
if (run <= 0)
discard;

COLOR = vec4(lightColor.xyz, val * occlusion * run);
COLOR *= vec4(1, 1, 1, run);
}

12 changes: 12 additions & 0 deletions Robust.Client/Console/Commands/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,18 @@ public override void Execute(IConsoleShell shell, string argStr, string[] args)
}
}

internal sealed class ToggleNormals : LocalizedCommands
{
[Dependency] private readonly ILightManager _light = default!;

public override string Command => "togglenormals";

public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
_light.DrawNormals = !_light.DrawNormals;
}
}

internal sealed class ChunkInfoCommand : LocalizedEntityCommands
{
[Dependency] private readonly IMapManager _map = default!;
Expand Down
3 changes: 3 additions & 0 deletions Robust.Client/Graphics/Clyde/Clyde.GridRendering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ internal partial class Clyde

private void _drawGrids(Viewport viewport, Box2 worldAABB, Box2Rotated worldBounds, IEye eye, bool normal = false)
{
if (normal && (!_lightManager.Enabled || !_lightManager.DrawLighting || !_lightManager.DrawNormals))
return;

var mapId = eye.Position.MapId;
if (!_mapManager.MapExists(mapId))
{
Expand Down
3 changes: 3 additions & 0 deletions Robust.Client/Graphics/Clyde/Clyde.HLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ private List<Overlay> GetOverlaysForSpace(OverlaySpace space)

private void DrawEntities(Viewport viewport, Box2Rotated worldBounds, Box2 worldAABB, IEye eye, bool normal = false)
{
if (normal && (!_lightManager.Enabled || !_lightManager.DrawLighting || !_lightManager.DrawNormals))
return;

var mapId = eye.Position.MapId;
if (mapId == MapId.Nullspace)
return;
Expand Down
1 change: 1 addition & 0 deletions Robust.Client/Graphics/Clyde/Clyde.LightRendering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ private void DrawLightsAndFov(Viewport viewport, Box2Rotated worldBounds, Box2 w

lightShader.SetUniformMaybe("eyeZoom", eye.Zoom / viewport.RenderScale);
lightShader.SetUniformMaybe("eyeCenter", eye.Position.Position + eye.Offset);
lightShader.SetUniformMaybe("useNormals", _lightManager.DrawNormals ? (int)1 : (int)0); // me when shaders do not support boolean values

var offset = new Vector2(component.Radius, component.Radius);

Expand Down
4 changes: 4 additions & 0 deletions Robust.Client/Graphics/Lighting/ILightManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public interface ILightManager
/// </summary>
bool DrawLighting { get; set; }
/// <summary>
/// Enables/disables rendering with normals instead of rendering flatly.
/// </summary>
bool DrawNormals { get; set; }
/// <summary>
/// This is useful to prevent players messing with lighting setup when they shouldn't.
/// </summary>
bool LockConsoleAccess { get; set; }
Expand Down
1 change: 1 addition & 0 deletions Robust.Client/Graphics/Lighting/LightManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public sealed class LightManager : ILightManager
public bool DrawShadows { get; set; } = true;
public bool DrawHardFov { get; set; } = true;
public bool DrawLighting { get; set; } = true;
public bool DrawNormals { get; set; } = true;
public bool LockConsoleAccess { get; set; } = false;
public Color AmbientLightColor { get; set; } = Color.FromSrgb(Color.Black);
}
Expand Down

0 comments on commit f53350d

Please sign in to comment.