Skip to content

Commit

Permalink
Add before-lighting overlay rendering
Browse files Browse the repository at this point in the history
Kinda eh but need some way to draw to overlays before lighting is run and all overlays come after.
  • Loading branch information
metalgearsloth committed Sep 29, 2024
1 parent 1c3ea96 commit 1907837
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Robust.Client/Graphics/Clyde/Clyde.LightRendering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using TKStencilOp = OpenToolkit.Graphics.OpenGL4.StencilOp;
using Robust.Shared.Physics;
using Robust.Client.ComponentTrees;
using Robust.Shared.Enums;
using Robust.Shared.Graphics;
using static Robust.Shared.GameObjects.OccluderComponent;
using Robust.Shared.Utility;
Expand Down Expand Up @@ -514,6 +515,8 @@ private void DrawLightsAndFov(Viewport viewport, Box2Rotated worldBounds, Box2 w

CheckGlError();

RenderOverlays(viewport, OverlaySpace.BeforeLighting, worldAABB, worldBounds);

if (_cfg.GetCVar(CVars.LightBlur))
BlurLights(viewport, eye);

Expand Down
39 changes: 39 additions & 0 deletions Robust.Client/Graphics/IRenderTarget.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Numerics;
using Robust.Shared.Graphics;
using Robust.Shared.Maths;
using SixLabors.ImageSharp.PixelFormats;

Expand All @@ -9,6 +11,43 @@ namespace Robust.Client.Graphics
/// </summary>
public interface IRenderTarget : IDisposable
{
public Vector2 LocalToWorld(IEye eye, Vector2 point, Vector2 scale)
{
var newPoint = point;

// (inlined version of UiProjMatrix^-1)
newPoint -= Size / 2f;
newPoint *= new Vector2(1, -1) / EyeManager.PixelsPerMeter;

// view matrix
eye.GetViewMatrixInv(out var viewMatrixInv, scale);
newPoint = Vector2.Transform(newPoint, viewMatrixInv);

return newPoint;
}

public Vector2 WorldToLocal(Vector2 point, IEye eye, Vector2 scale)
{
var newPoint = point;

eye.GetViewMatrix(out var viewMatrix, scale);
newPoint = Vector2.Transform(newPoint, viewMatrix);

// (inlined version of UiProjMatrix)
newPoint *= new Vector2(1, -1) * EyeManager.PixelsPerMeter;
newPoint += Size / 2f;

return newPoint;
}

public Matrix3x2 GetWorldToLocalMatrix(IEye eye, Vector2 scale)
{
eye.GetViewMatrix(out var viewMatrix, scale * new Vector2(EyeManager.PixelsPerMeter, -EyeManager.PixelsPerMeter));
viewMatrix.M31 += Size.X / 2f;
viewMatrix.M32 += Size.Y / 2f;
return viewMatrix;
}

/// <summary>
/// The size of the render target, in physical pixels.
/// </summary>
Expand Down
7 changes: 6 additions & 1 deletion Robust.Shared/Enums/OverlaySpaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public enum OverlaySpace : ushort
/// <summary>
/// Overlay will be rendered below grids, entities, and everything else. In world space.
/// </summary>
WorldSpaceBelowWorld = 1 << 8
WorldSpaceBelowWorld = 1 << 8,

/// <summary>
/// Overlay will be drawn before lighting occurs. Used to apply changes to the lighting render target.
/// </summary>
BeforeLighting = 1 << 9,
}
}

0 comments on commit 1907837

Please sign in to comment.