From 5820817879f764c3a569731c9f52c81b9d7a4f24 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 6 Dec 2026 01:19:25 +0100 Subject: [PATCH] Soul Pass #1 fixes: stepScale raymarch traversal, remove verify harness, forcePersist ResetToDefaults, windowed UI/hotkey sync --- client/GraphicsSettings.cs | 10 ++- client/Main.cs | 87 +++---------------- client/volumetric_raymarch.glsl | 7 +- .../RustToDust.Tests/GraphicsSettingsTests.cs | 11 +++ 4 files changed, 36 insertions(+), 79 deletions(-) diff --git a/client/GraphicsSettings.cs b/client/GraphicsSettings.cs index e0e6461..e8e4e60 100644 --- a/client/GraphicsSettings.cs +++ b/client/GraphicsSettings.cs @@ -181,7 +181,8 @@ public sealed class GraphicsSettings VolumetricSamples volumetricSamples, SdfgiQuality sdfgiQuality, bool borderlessFullscreen, - bool persist = true) + bool persist = true, + bool forcePersist = false) { VfxResolutionScale safeRes = Enum.IsDefined(vfxResolution) ? vfxResolution : VfxResolutionScale.Half; VolumetricSamples safeSamples = Enum.IsDefined(volumetricSamples) ? volumetricSamples : VolumetricSamples.Medium; @@ -194,6 +195,10 @@ public sealed class GraphicsSettings if (!changed) { + if (persist && forcePersist) + { + Save(); + } return; } @@ -227,7 +232,8 @@ public sealed class GraphicsSettings VolumetricSamples.Medium, SdfgiQuality.Balanced, borderlessFullscreen: true, - persist: persist); + persist: persist, + forcePersist: persist); public static float GetResolutionScaleFactor(VfxResolutionScale scale) => scale switch { diff --git a/client/Main.cs b/client/Main.cs index b7c9786..94ce5fb 100644 --- a/client/Main.cs +++ b/client/Main.cs @@ -64,7 +64,6 @@ public partial class Main : Node3D private int _menuPreviewTargetFrames; private int _menuPreviewFrames; private string? _menuPreviewOut; - private string? _gfxVerifyOut; private readonly WalkerFootstepTracker _footsteps = new(); private readonly CameraJuiceState _camJuice = new(); private readonly List _frameEvents = new(128); @@ -350,7 +349,6 @@ public partial class Main : Node3D _menuPreviewTargetFrames = menuExitFrames; } _menuPreviewOut = System.Environment.GetEnvironmentVariable("RTD_MENU_PREVIEW_OUT"); - _gfxVerifyOut = System.Environment.GetEnvironmentVariable("RTD_GFX_VERIFY_OUT"); _hasWindowOverride = GetCliArg("--windowed", allowBareFlag: true) is not null || GetCliArg("--resolution", allowBareFlag: true) is not null @@ -359,9 +357,19 @@ public partial class Main : Node3D { ApplyWindowMode(_graphicsSettings.BorderlessFullscreen); } - else if (IsAutomatedRun && DisplayServer.GetName() != "headless") + else { - DisplayServer.WindowSetFlag(DisplayServer.WindowFlags.NoFocus, true); + if (IsAutomatedRun && DisplayServer.GetName() != "headless") + { + DisplayServer.WindowSetFlag(DisplayServer.WindowFlags.NoFocus, true); + } + if (_hasWindowOverride && DisplayServer.GetName() != "headless") + { + var winMode = DisplayServer.WindowGetMode(); + bool actualFullscreen = winMode == DisplayServer.WindowMode.Fullscreen + || winMode == DisplayServer.WindowMode.ExclusiveFullscreen; + _graphicsSettings.SetBorderlessFullscreen(actualFullscreen, persist: false); + } } bool perfCombat = _perfTargetFrames > 0 && System.Environment.GetEnvironmentVariable("RTD_PERF_COMBAT") == "1"; @@ -396,10 +404,6 @@ public partial class Main : Node3D else { EnterMainMenuBackdrop(); - if (System.Environment.GetEnvironmentVariable("RTD_OPEN_SETTINGS") == "1") - { - OpenSettingsFromCurrentScreen(); - } } if (perfCombat && _session is not null) @@ -1122,7 +1126,7 @@ public partial class Main : Node3D private void ToggleBorderlessFullscreen() { - if (DisplayServer.GetName() == "headless") + if (IsAutomatedRun || DisplayServer.GetName() == "headless") { return; } @@ -1597,10 +1601,6 @@ public partial class Main : Node3D } _perfFrameCount++; - if (!string.IsNullOrWhiteSpace(_gfxVerifyOut)) - { - StepGfxVerifySuite(_perfFrameCount); - } if (_perfFrameCount >= _perfTargetFrames) { PrintPerfSummaryAndQuit(); @@ -1839,70 +1839,9 @@ public partial class Main : Node3D GD.Print($"PERF PREVIEW SAVED: {previewOut} ({img.GetWidth()}x{img.GetHeight()}, err={err})"); } } - if (!string.IsNullOrWhiteSpace(_gfxVerifyOut)) - { - VerifyPersistenceRoundTrip(); - _graphicsSettings.Apply(VfxResolutionScale.Half, VolumetricSamples.Medium, SdfgiQuality.Balanced, borderlessFullscreen: true, persist: false); - _menuPreviewOut = _gfxVerifyOut; - _menuPreviewTargetFrames = 12; - _menuPreviewFrames = 0; - _perfTargetFrames = 0; - EnterMainMenuBackdrop(); - OpenSettingsFromCurrentScreen(); - return; - } GetTree().Quit(0); } - private void StepGfxVerifySuite(int frameCount) - { - var volFx = _atmosphere.VolumetricEffect; - var env = _atmosphere.Environment; - if (frameCount == 33) - { - GD.Print($"GFX_VERIFY Phase0 (Half/Medium/Balanced): march={volFx?.LastMarchSize.X}x{volFx?.LastMarchSize.Y} steps={volFx?.CurrentMaxSteps} iter={volFx?.CurrentMaxIter} total={volFx?.LastTotalGpuMs:F3}ms marchMs={volFx?.LastMarchGpuMs:F3}ms compMs={volFx?.LastCompGpuMs:F3}ms sdfgi={env.SdfgiEnabled} cell={env.SdfgiMinCellSize:F1} casc={env.SdfgiCascades}"); - _graphicsSettings.Apply(VfxResolutionScale.ThreeQuarter, VolumetricSamples.High, SdfgiQuality.High, borderlessFullscreen: true, persist: false); - } - else if (frameCount == 57) - { - GD.Print($"GFX_VERIFY Phase1 (ThreeQuarter/High/SdfgiHigh): march={volFx?.LastMarchSize.X}x{volFx?.LastMarchSize.Y} steps={volFx?.CurrentMaxSteps} iter={volFx?.CurrentMaxIter} total={volFx?.LastTotalGpuMs:F3}ms marchMs={volFx?.LastMarchGpuMs:F3}ms compMs={volFx?.LastCompGpuMs:F3}ms sdfgi={env.SdfgiEnabled} cell={env.SdfgiMinCellSize:F1} casc={env.SdfgiCascades}"); - _graphicsSettings.Apply(VfxResolutionScale.Full, VolumetricSamples.Ultra, SdfgiQuality.Off, borderlessFullscreen: true, persist: false); - } - else if (frameCount == 81) - { - GD.Print($"GFX_VERIFY Phase2 (Full/Ultra/SdfgiOff): march={volFx?.LastMarchSize.X}x{volFx?.LastMarchSize.Y} steps={volFx?.CurrentMaxSteps} iter={volFx?.CurrentMaxIter} total={volFx?.LastTotalGpuMs:F3}ms marchMs={volFx?.LastMarchGpuMs:F3}ms compMs={volFx?.LastCompGpuMs:F3}ms sdfgi={env.SdfgiEnabled}"); - _graphicsSettings.Apply(VfxResolutionScale.Half, VolumetricSamples.Low, SdfgiQuality.Balanced, borderlessFullscreen: true, persist: false); - } - else if (frameCount == 98) - { - GD.Print($"GFX_VERIFY Phase3 (Half/Low/Balanced): march={volFx?.LastMarchSize.X}x{volFx?.LastMarchSize.Y} steps={volFx?.CurrentMaxSteps} iter={volFx?.CurrentMaxIter} total={volFx?.LastTotalGpuMs:F3}ms marchMs={volFx?.LastMarchGpuMs:F3}ms compMs={volFx?.LastCompGpuMs:F3}ms sdfgi={env.SdfgiEnabled}"); - } - } - - private static void VerifyPersistenceRoundTrip() - { - string userPath = ResolveGraphicsSettingsPath() ?? string.Empty; - string verifyPath = ProjectSettings.GlobalizePath("user://graphics_settings_verify_rt.json"); - try - { - var s1 = new GraphicsSettings(verifyPath); - s1.Apply(VfxResolutionScale.Full, VolumetricSamples.Ultra, SdfgiQuality.High, borderlessFullscreen: false, persist: true); - var s2 = GraphicsSettings.Load(verifyPath); - bool ok = s2.VfxResolution == VfxResolutionScale.Full - && s2.VolumetricSamples == VolumetricSamples.Ultra - && s2.SdfgiQuality == SdfgiQuality.High - && !s2.BorderlessFullscreen; - GD.Print($"GFX_VERIFY PersistenceRoundTrip: ok={ok} userPath='{userPath}' verifyPath='{verifyPath}'"); - } - finally - { - if (System.IO.File.Exists(verifyPath)) - { - System.IO.File.Delete(verifyPath); - } - } - } - private static void CollectNodeNames(Node cur, List outNames, int limit) { if (outNames.Count >= limit) return; diff --git a/client/volumetric_raymarch.glsl b/client/volumetric_raymarch.glsl index 2781bf3..63e61aa 100644 --- a/client/volumetric_raymarch.glsl +++ b/client/volumetric_raymarch.glsl @@ -322,7 +322,8 @@ void main() { int steps = 0; int iter = 0; int maxSteps = clamp(int(u_frame.qualityParams.x), 1, 64); - int maxIter = clamp(int(u_frame.qualityParams.y), 1, 96); + int maxIter = clamp(max(int(u_frame.qualityParams.y), maxSteps * 2), 1, 96); + float stepScale = 10.0 / max(float(maxSteps), 1.0); while ((nextIdx < hitCount || activeMask != 0u) && t < tEndMax && T >= 0.03 && steps < maxSteps && iter < maxIter) { // Empty-space jump directly to nextIdx's t0 whenever no emitter is currently active @@ -330,7 +331,7 @@ void main() { float minNext = uintBitsToFloat(hitPack[nextIdx] & 0xFFFFFFE0u); float nextT1 = hitT1[nextIdx]; float chord = max(0.0, nextT1 - minNext); - float dsLeap = max(0.42, 0.32 + 0.014 * minNext); + float dsLeap = max(0.16, max(0.42, 0.32 + 0.014 * minNext) * stepScale); float jitter = ign * min(dsLeap, max(0.05, chord * 0.45)); t = min(max(t, minNext) + jitter, tEndMax - 1e-4); if (t >= tEndMax) { @@ -338,7 +339,7 @@ void main() { } } - float ds = max(0.42, 0.32 + 0.014 * t); + float ds = max(0.16, max(0.42, 0.32 + 0.014 * t) * stepScale); float tLo = t - 0.5 * ds; float tHi = t + 0.5 * ds; diff --git a/tests/RustToDust.Tests/GraphicsSettingsTests.cs b/tests/RustToDust.Tests/GraphicsSettingsTests.cs index 6b9c2a3..e798424 100644 --- a/tests/RustToDust.Tests/GraphicsSettingsTests.cs +++ b/tests/RustToDust.Tests/GraphicsSettingsTests.cs @@ -48,6 +48,17 @@ public sealed class GraphicsSettingsTests Assert.Equal(SdfgiQuality.Balanced, corruptLoaded.SdfgiQuality); Assert.True(corruptLoaded.BorderlessFullscreen); + // ResetToDefaults(persist: true) must unconditionally rewrite a corrupt file even when memory equals defaults + corruptLoaded.ResetToDefaults(persist: true); + string repairedJson = File.ReadAllText(corruptPath); + Assert.DoesNotContain("not valid json", repairedJson, StringComparison.Ordinal); + var repaired = new GraphicsSettings(); + Assert.True(repaired.LoadFromJson(repairedJson)); + Assert.Equal(VfxResolutionScale.Half, repaired.VfxResolution); + Assert.Equal(VolumetricSamples.Medium, repaired.VolumetricSamples); + Assert.Equal(SdfgiQuality.Balanced, repaired.SdfgiQuality); + Assert.True(repaired.BorderlessFullscreen); + var outOfRange = new GraphicsSettings(); Assert.True(outOfRange.LoadFromJson("""{"vfxResolutionScale":99,"volumetricSamples":42,"sdfgiQuality":77,"borderlessFullscreen":false}""")); Assert.Equal(VfxResolutionScale.Half, outOfRange.VfxResolution);