Skip to content

Commit

Permalink
rendercontext small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
saint11 committed Dec 9, 2023
1 parent 5fe0a48 commit ca22a91
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/Murder/Core/Graphics/Batch/Batches2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Batches2D

public const int FloorBatchId = 1;

public const int LightBatchId = 2;
// Legacy LightBatchId 2;

public const int GameUiBatchId = 3;

Expand Down
44 changes: 15 additions & 29 deletions src/Murder/Core/Graphics/RenderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,21 @@ public class RenderContext : IDisposable
{
public readonly Camera2D Camera;

/// <summary>
/// Intended to be the main gameplay batch, influenced by the camera.
/// </summary>
public Batch2D GameplayBatch => GetBatch(Batches2D.GameplayBatchId);
/// <summary>
/// Renders behind the <see cref="GameplayBatch"/>, influenced by the camera.
/// </summary>
public Batch2D FloorBatch => GetBatch(Batches2D.FloorBatchId);
public Batch2D LightBatch => GetBatch(Batches2D.LightBatchId);
/// <summary>
/// Renders in front of the <see cref="GameplayBatch"/>, influenced by the camera.
/// </summary>
public Batch2D GameUiBatch => GetBatch(Batches2D.GameUiBatchId);
/// <summary>
/// Renders above everything, ignores any camera movement.
/// </summary>
public Batch2D UiBatch => GetBatch(Batches2D.UiBatchId);

public Vector2 Scale => _scale;
Expand All @@ -27,19 +38,19 @@ public class RenderContext : IDisposable
protected Vector2 _subPixelOffset;

/// <summary>
/// Only used if <see cref="RenderContextFlags.Debug"/> is set.
/// Only used if <see cref="RenderContextFlags.Debug"/> is set, has a nice effect to it. Influenced by the camera.
/// </summary>
public Batch2D DebugFxBatch => GetBatch(Batches2D.DebugFxBatchId);

/// <summary>
/// Only used if <see cref="RenderContextFlags.Debug"/> is set.
/// Only used if <see cref="RenderContextFlags.Debug"/> is set. Influenced by the camera.
/// </summary>
public Batch2D DebugBatch => GetBatch(Batches2D.DebugBatchId);

protected RenderTarget2D? _floorBufferTarget;

protected RenderTarget2D? _uiTarget;
protected RenderTarget2D? _mainTarget;

public RenderTarget2D? MainTarget => _mainTarget;

public BatchPreviewState PreviewState;
Expand Down Expand Up @@ -178,16 +189,6 @@ public virtual void Initialize()
SamplerState.PointClamp
));

RegisterSpriteBatch(Batches2D.LightBatchId,
new("Light",
_graphicsDevice,
true,
Game.Data.ShaderSprite,
BatchMode.DrawOrder,
BlendState.Additive,
SamplerState.AnisotropicClamp
));

if (_useDebugBatches)
{
RegisterSpriteBatch(Batches2D.DebugFxBatchId,
Expand Down Expand Up @@ -365,21 +366,6 @@ _tempTarget is not null &&
Matrix.Identity,
Color.White, Game.Data.ShaderSimple, BlendState.Opaque, false);

_graphicsDevice.SetRenderTarget(_tempTarget);
_graphicsDevice.Clear(Color.Black);
LightBatch.End();
CreateDebugPreviewIfNecessary(BatchPreviewState.Lights, _tempTarget);

_graphicsDevice.SetRenderTarget(_finalTarget);
Game.Data.PosterizerShader.SetParameter("levels", 16f);
Game.Data.PosterizerShader.SetParameter("aberrationStrength", 0.04f);

RenderServices.DrawTextureQuad(_tempTarget, // <=== Draws the light buffer to the final buffer using an additive blend
_tempTarget.Bounds,
new Rectangle(_subPixelOffset, _tempTarget.Bounds.Size.ToSysVector2().Multiply(_scale)),
Matrix.Identity,
Color.White * 0.75f, Game.Data.PosterizerShader, BlendState.Additive, false);

CreateDebugPreviewIfNecessary(BatchPreviewState.Step3, _finalTarget);

_graphicsDevice.SetRenderTarget(_tempTarget);
Expand Down

0 comments on commit ca22a91

Please sign in to comment.