* Implements a Dynamic Lighting System on maps. * Edit: the night should be a little bit brighter and blue now. * Major edit: everything must be done on the client side now, with certain datafield replicated. Changes were outlined in the salvage to accommodate the new lighting system. * Edit: The offset is now serverside, this makes the time accurate in all situations. * Removing ununsed import * Minor tweaks * Tweak in time precision * Minor tweak + Unused import removed * Edit: apparently RealTime is better for what I'm looking for * Fix: Now the time is calculated correctly. * Minor tweaks * Adds condition for when the light should be updated * Add planet lighting * she * close-ish * c * bittersweat * Fixes * Revert "Merge branch '22719' into 2024-09-29-planet-lighting" This reverts commit 9f2785bb16aee47d794aa3eed8ae15004f97fc35, reversing changes made to 19649c07a5fb625423e08fc18d91c9cb101daa86. * Europa and day-night * weh * rooves working * Clean * Remove Europa * Fixes * fix * Update * Fix caves * Update for engine * Add sun shadows (planet lighting v2) For now mostly targeting walls and having the shadows change over time. Got the basic proof-of-concept working just needs a hell of a lot of polish. * Documentation * a * Fixes * Move blur to an overlay * Slughands * Fixes * Remove v2 work * Finalise --------- Co-authored-by: DoutorWhite <thedoctorwhite@gmail.com>
101 lines
3.4 KiB
C#
101 lines
3.4 KiB
C#
using System.Numerics;
|
|
using Content.Shared.Light.Components;
|
|
using Content.Shared.Maps;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Shared.Enums;
|
|
using Robust.Shared.Map.Components;
|
|
|
|
namespace Content.Client.Light;
|
|
|
|
public sealed class RoofOverlay : Overlay
|
|
{
|
|
private readonly IEntityManager _entManager;
|
|
[Dependency] private readonly IOverlayManager _overlay = default!;
|
|
|
|
private readonly EntityLookupSystem _lookup;
|
|
private readonly SharedMapSystem _mapSystem;
|
|
private readonly SharedTransformSystem _xformSystem;
|
|
|
|
private readonly HashSet<Entity<OccluderComponent>> _occluders = new();
|
|
|
|
public override OverlaySpace Space => OverlaySpace.BeforeLighting;
|
|
|
|
public const int ContentZIndex = BeforeLightTargetOverlay.ContentZIndex + 1;
|
|
|
|
public RoofOverlay(IEntityManager entManager)
|
|
{
|
|
_entManager = entManager;
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
_lookup = _entManager.System<EntityLookupSystem>();
|
|
_mapSystem = _entManager.System<SharedMapSystem>();
|
|
_xformSystem = _entManager.System<SharedTransformSystem>();
|
|
|
|
ZIndex = ContentZIndex;
|
|
}
|
|
|
|
protected override void Draw(in OverlayDrawArgs args)
|
|
{
|
|
if (args.Viewport.Eye == null)
|
|
return;
|
|
|
|
var mapEnt = _mapSystem.GetMap(args.MapId);
|
|
|
|
if (!_entManager.TryGetComponent(mapEnt, out RoofComponent? roofComp) ||
|
|
!_entManager.TryGetComponent(mapEnt, out MapGridComponent? grid))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var viewport = args.Viewport;
|
|
var eye = args.Viewport.Eye;
|
|
|
|
var worldHandle = args.WorldHandle;
|
|
var lightoverlay = _overlay.GetOverlay<BeforeLightTargetOverlay>();
|
|
var bounds = lightoverlay.EnlargedBounds;
|
|
var target = lightoverlay.EnlargedLightTarget;
|
|
|
|
worldHandle.RenderInRenderTarget(target,
|
|
() =>
|
|
{
|
|
var invMatrix = target.GetWorldToLocalMatrix(eye, viewport.RenderScale / 2f);
|
|
|
|
var gridMatrix = _xformSystem.GetWorldMatrix(mapEnt);
|
|
var matty = Matrix3x2.Multiply(gridMatrix, invMatrix);
|
|
|
|
worldHandle.SetTransform(matty);
|
|
|
|
var tileEnumerator = _mapSystem.GetTilesEnumerator(mapEnt, grid, bounds);
|
|
|
|
// Due to stencilling we essentially draw on unrooved tiles
|
|
while (tileEnumerator.MoveNext(out var tileRef))
|
|
{
|
|
if ((tileRef.Tile.Flags & (byte) TileFlag.Roof) == 0x0)
|
|
{
|
|
// Check if the tile is occluded in which case hide it anyway.
|
|
// This is to avoid lit walls bleeding over to unlit tiles.
|
|
_occluders.Clear();
|
|
_lookup.GetLocalEntitiesIntersecting(mapEnt, tileRef.GridIndices, _occluders);
|
|
var found = false;
|
|
|
|
foreach (var occluder in _occluders)
|
|
{
|
|
if (!occluder.Comp.Enabled)
|
|
continue;
|
|
|
|
found = true;
|
|
break;
|
|
}
|
|
|
|
if (!found)
|
|
continue;
|
|
}
|
|
|
|
var local = _lookup.GetLocalBounds(tileRef, grid.TileSize);
|
|
worldHandle.DrawRect(local, roofComp.Color);
|
|
}
|
|
|
|
}, null);
|
|
}
|
|
}
|