Skip to content

Commit

Permalink
Fix stencilling
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth committed Oct 6, 2024
1 parent 41aa383 commit fccbc0d
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions Robust.Client/Graphics/Clyde/Clyde.LightRendering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,18 +410,20 @@ private void DrawLightsAndFov(Viewport viewport, Box2Rotated worldBounds, Box2 w
GL.StencilMask(0xFF);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.StencilBufferBit);
CheckGlError();

var oldTarget = _currentRenderTarget;
var oldProj = _currentMatrixProj;
var oldShader = _queuedShaderInstance;
var oldModel = _currentMatrixModel;
var oldScissor = _currentScissorState;
var oldScissoring = _isScissoring;
_lightingReady = true;

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

GL.Viewport(0, 0, lightW, lightH);
BindVertexArray(_occlusionVao.Handle);
// Batching doesn't restore stencil state so we do it here.
// Yes I spent 8 hours across 2 days just to track down this as the problem.
GL.Enable(EnableCap.StencilTest);
_isStencilling = true;
DebugTools.Assert(oldScissoring.Equals(_isScissoring));
DebugTools.Assert(oldScissor.Equals(_currentScissorState));
DebugTools.Assert(oldModel.Equals(_currentMatrixModel));
Expand Down Expand Up @@ -552,6 +554,7 @@ private void DrawLightsAndFov(Viewport viewport, Box2Rotated worldBounds, Box2 w
GL.Viewport(0, 0, viewport.Size.X, viewport.Size.Y);
CheckGlError();

_lightingReady = true;
Array.Clear(_lightsToRenderList, 0, count);
}

Expand Down Expand Up @@ -1163,20 +1166,30 @@ private void RegenLightRts(Viewport viewport)
viewport.WallMaskRenderTarget?.Dispose();
viewport.WallBleedIntermediateRenderTarget1?.Dispose();
viewport.WallBleedIntermediateRenderTarget2?.Dispose();
var lightMapColorFormat = _hasGLFloatFramebuffers
? RenderTargetColorFormat.R11FG11FB10F
: RenderTargetColorFormat.Rgba8;
var lightMapSampleParameters = new TextureSampleParameters { Filter = true };

viewport.WallMaskRenderTarget = CreateRenderTarget(viewport.Size, RenderTargetColorFormat.R8,
name: $"{viewport.Name}-{nameof(viewport.WallMaskRenderTarget)}");

viewport.LightRenderTarget = (RenderTexture) CreateLightRenderTarget(lightMapSize,
$"{viewport.Name}-{nameof(viewport.LightRenderTarget)}");

viewport.LightBlurTarget = (RenderTexture) CreateLightRenderTarget(lightMapSize,
viewport.LightBlurTarget = CreateRenderTarget(lightMapSize,
new RenderTargetFormatParameters(lightMapColorFormat),
lightMapSampleParameters,
$"{viewport.Name}-{nameof(viewport.LightBlurTarget)}");

viewport.WallBleedIntermediateRenderTarget1 = (RenderTexture) CreateLightRenderTarget(lightMapSizeQuart,
viewport.WallBleedIntermediateRenderTarget1 = CreateRenderTarget(lightMapSizeQuart,
new RenderTargetFormatParameters(lightMapColorFormat),
lightMapSampleParameters,
$"{viewport.Name}-{nameof(viewport.WallBleedIntermediateRenderTarget1)}");

viewport.WallBleedIntermediateRenderTarget2 = (RenderTexture) CreateLightRenderTarget(lightMapSizeQuart,
viewport.WallBleedIntermediateRenderTarget2 = CreateRenderTarget(lightMapSizeQuart,
new RenderTargetFormatParameters(lightMapColorFormat),
lightMapSampleParameters,
$"{viewport.Name}-{nameof(viewport.WallBleedIntermediateRenderTarget2)}");
}

Expand Down

0 comments on commit fccbc0d

Please sign in to comment.