Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add before-lighting overlay rendering #5472

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}
}
Loading