diff --git a/CHANGELOG.md b/CHANGELOG.md index 8180d09..d2931e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,13 +11,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Web API (`/api/v1`) - This allows you to make your own apps, pages and overlays on the same JRTI feeds as the default proposed interface, with an optional control key for other devices if need be. Pages from other websites can no longer change anything, as a security measure. See the API page of the docs for more information -- Your own pages and styles (`PluginData/Apps/`, `PluginData/Web/`) - you can now make your own pages and styles, kept across updates - Save recordings to this device (Settings, Finished recordings) - the web UI downloads each recording when it stops, so recordings land on the computer watching the feeds as well as the KSP one. On by default on every device except the KSP computer ### Fixed - Firefly re-entry (Visual Mod Integrations) - with Deferred installed, re-entry plasma no longer turns huge and drops the game below 1 FPS when feeds are open on parts with built-in cameras, like SEP's onboards. This is a workaround until Firefly merges my proper fix (https://github.com/M1rageDev/Firefly/pull/58), see Troubleshooting +- Planet from orbit (Scatterer, Deferred) - camera feeds keep the atmosphere over the planet after loading a save in orbit, instead of showing improperly drawn atmosphere +- Hull lighting in orbit (Scatterer) - shiny hulls on camera feeds are no longer lit from where the main camera is looking + +## v3.3.0.2 - 2026-11-27 + +### Fixed + +- Fix the timing at which the JRTI cameras copy depth buffer to avoid lighting artifacts. + + +## v3.3.0.1 - 2026-11-26 + +### Added + +- Web API (`/api/v1`) - This allows you to make your own apps, pages and overlays on the same JRTI feeds as the default proposed interface, with an optional control key for other devices if need be. Pages from other websites can no longer change anything, as a security measure. See the API page of the docs for more information +- Your own pages and styles (`PluginData/Apps/`, `PluginData/Web/`) - you can now make your own pages and styles, kept across updates + +### Fixed + +- Atmosphere seen from orbit (Scatterer) - feeds no longer cut the atmosphere off along a line that follows where the main view looks, at least from what my testing has shown... Answers issue [#39](https://github.com/RELMYMathieu/JustReadTheInstructions/issues/39) + ## v3.3.0 - 2026-11-11 diff --git a/GameData/JustReadTheInstructions/JustReadTheInstructions.version b/GameData/JustReadTheInstructions/JustReadTheInstructions.version index 10f8cee..239e239 100644 --- a/GameData/JustReadTheInstructions/JustReadTheInstructions.version +++ b/GameData/JustReadTheInstructions/JustReadTheInstructions.version @@ -1,6 +1,6 @@ { "NAME": "Just Read The Instructions", - "VERSION": "3.3.0.0", + "VERSION": "3.3.0.2", "URL": "https://raw.githubusercontent.com/RELMYMathieu/JustReadTheInstructions/main/GameData/JustReadTheInstructions/JustReadTheInstructions.version", "DOWNLOAD": "https://github.com/RELMYMathieu/JustReadTheInstructions/releases/latest", "KSP_VERSION": "1.12.5", diff --git a/GameData/JustReadTheInstructions/changelog.cfg b/GameData/JustReadTheInstructions/changelog.cfg index 9ae1593..3022202 100644 --- a/GameData/JustReadTheInstructions/changelog.cfg +++ b/GameData/JustReadTheInstructions/changelog.cfg @@ -5,6 +5,32 @@ KERBALCHANGELOG license = MIT author = Mathieu Relmy + VERSION + { + version = 3.3.0.2 + CHANGE + { + change = Fixed + subchange = Fix the timing at which the JRTI cameras copy depth buffer to avoid lighting artifacts. + } + } + + VERSION + { + version = 3.3.0.1 + CHANGE + { + change = Added + subchange = Web API (/api/v1) - This allows you to make your own apps, pages and overlays on the same JRTI feeds as the default proposed interface, with an optional control key for other devices if need be. Pages from other websites can no longer change anything, as a security measure. See the API page of the docs for more information + subchange = Your own pages and styles (PluginData/Apps/, PluginData/Web/) - you can now make your own pages and styles, kept across updates + } + CHANGE + { + change = Fixed + subchange = Atmosphere seen from orbit (Scatterer) - feeds no longer cut the atmosphere off along a line that follows where the main view looks, at least from what my testing has shown... Answers issue #39 + } + } + VERSION { version = 3.3.0 diff --git a/Source/DeferredIntegration.cs b/Source/DeferredIntegration.cs index 9aa36a0..785ddbd 100644 --- a/Source/DeferredIntegration.cs +++ b/Source/DeferredIntegration.cs @@ -8,8 +8,11 @@ namespace JustReadTheInstructions { public static class DeferredIntegration { + private const int LocalCameraQueue = 15; + private static bool? _isAvailable; private static Type _forwardRenderingCompatibilityType; + private static Type _pqsFadeType; private static MethodInfo _initMethod; private static FieldInfo _dummyObjectField; @@ -33,6 +36,7 @@ public static bool IsAvailable } _forwardRenderingCompatibilityType = deferredAssembly.GetType("Deferred.ForwardRenderingCompatibility"); + _pqsFadeType = deferredAssembly.GetType("Deferred.DeferredPQSFade"); if (_forwardRenderingCompatibilityType == null) { @@ -67,7 +71,7 @@ public static bool IsAvailable } } - public static void ApplyToCamera(Camera camera, int renderQueue = 15) + public static void ApplyToCamera(Camera camera, int renderQueue = LocalCameraQueue) { if (!IsAvailable || camera == null) return; @@ -76,6 +80,9 @@ public static void ApplyToCamera(Camera camera, int renderQueue = 15) { camera.renderingPath = RenderingPath.DeferredShading; + if (renderQueue == LocalCameraQueue) + AddPQSFade(camera); + var existingComponent = camera.gameObject.GetComponent(_forwardRenderingCompatibilityType); if (existingComponent != null) { @@ -107,6 +114,15 @@ public static void ApplyToCamera(Camera camera, int renderQueue = 15) } } + private static void AddPQSFade(Camera camera) + { + if (_pqsFadeType == null || camera.gameObject.GetComponent(_pqsFadeType) != null) + return; + + camera.gameObject.AddComponent(_pqsFadeType); + Debug.Log($"[JRTI-Deferred]: Added PQS fade to {camera.name}"); + } + // TEMP: until Firefly merges https://github.com/M1rageDev/Firefly/pull/58 private static void DetachDummyObject(Component component, Camera camera) { @@ -126,6 +142,13 @@ public static void RemoveFromCamera(Camera camera) { camera.renderingPath = RenderingPath.Forward; + if (_pqsFadeType != null) + { + var fade = camera.gameObject.GetComponent(_pqsFadeType); + if (fade != null) + UnityEngine.Object.Destroy(fade); + } + if (_forwardRenderingCompatibilityType != null) { var component = camera.gameObject.GetComponent(_forwardRenderingCompatibilityType); @@ -158,6 +181,9 @@ public static string GetDiagnosticInfo(Camera camera) : "- ForwardRenderingCompatibility: Missing\n"; } + if (_pqsFadeType != null) + info += $"- DeferredPQSFade: {(camera.GetComponent(_pqsFadeType) != null ? "Present" : "Missing")}\n"; + return info; } } diff --git a/Source/JustReadTheInstructions.csproj b/Source/JustReadTheInstructions.csproj index dbc7a5d..a247568 100644 --- a/Source/JustReadTheInstructions.csproj +++ b/Source/JustReadTheInstructions.csproj @@ -2,7 +2,7 @@ net48 - 3.3.0.0 + 3.3.0.2 KSP Mod, inspired by OCISLY, as a spiritual successor. MIT $(MSBuildThisFileDirectory)../GameData/JustReadTheInstructions diff --git a/Source/ScattererAtmosphereBinding.cs b/Source/ScattererAtmosphereBinding.cs new file mode 100644 index 0000000..60707e5 --- /dev/null +++ b/Source/ScattererAtmosphereBinding.cs @@ -0,0 +1,18 @@ +using UnityEngine; + +namespace JustReadTheInstructions +{ + public class ScattererAtmosphereBinding : MonoBehaviour + { + private Camera _camera; + + void Awake() + { + _camera = GetComponent(); + } + + void OnPreRender() => ScattererScaledAtmosphere.Bind(_camera); + + void OnPostRender() => ScattererScaledAtmosphere.RestoreMain(); + } +} diff --git a/Source/ScattererScaledAtmosphere.cs b/Source/ScattererScaledAtmosphere.cs new file mode 100644 index 0000000..900549c --- /dev/null +++ b/Source/ScattererScaledAtmosphere.cs @@ -0,0 +1,137 @@ +using System; +using System.Reflection; +using UnityEngine; + +namespace JustReadTheInstructions +{ + internal static class ScattererScaledAtmosphere + { + private const string ReflectionProbeScaledCameraName = "ScattererReflectionProbeScaledSpaceCamera"; + private const float ReflectionProbeSearchInterval = 1f; + + private static bool _resolved; + private static Type _skyNodeType; + private static FieldInfo _materialField; + private static FieldInfo _containerField; + private static FieldInfo _parentScaledTransformField; + private static FieldInfo _rtField; + private static MethodInfo _updateScreenBoundsMethod; + private static MethodInfo _enableScreenCopyMethod; + private static readonly object[] ScreenCopyArgs = new object[1]; + + private static GameObject _reflectionProbeScaledCamera; + private static float _nextReflectionProbeSearch; + + private static readonly int CameraToWorldId = Shader.PropertyToID("CameraToWorld"); + private static readonly int CurrentVpId = Shader.PropertyToID("currentVP"); private static readonly object[] BoundsArgs = new object[5]; + + public static void Bind(Camera viewer) + { + var mainScaledCamera = ScattererScaledCameraSwap.MainScaledCamera; + if (viewer == null || mainScaledCamera == null || !Resolve()) + return; + + try + { + foreach (var skyNode in mainScaledCamera.GetComponents(_skyNodeType)) + BindSkyNode(skyNode, viewer); + } + catch (Exception ex) + { + Debug.LogError($"[JRTI-ScaledSwap]: Scaled atmosphere bind failed, disabled: {ex.Message}"); + _skyNodeType = null; + } + } + + public static void RestoreMain() => Bind(ScattererScaledCameraSwap.MainScaledCamera); + + public static void EnableScreenCopy(Camera camera) + { + if (camera == null || !Resolve() || _enableScreenCopyMethod == null) + return; + + try + { + ScreenCopyArgs[0] = camera; + _enableScreenCopyMethod.Invoke(null, ScreenCopyArgs); + } + catch (Exception ex) + { + Debug.LogError($"[JRTI-ScaledSwap]: Screen copy failed, disabled: {ex.Message}"); + _enableScreenCopyMethod = null; + } + } + + public static void AttachToReflectionProbe() + { + if (_reflectionProbeScaledCamera != null || Time.unscaledTime < _nextReflectionProbeSearch) + return; + + _nextReflectionProbeSearch = Time.unscaledTime + ReflectionProbeSearchInterval; + _reflectionProbeScaledCamera = GameObject.Find(ReflectionProbeScaledCameraName); + if (_reflectionProbeScaledCamera == null || _reflectionProbeScaledCamera.GetComponent() != null) + return; + + _reflectionProbeScaledCamera.AddComponent(); + Debug.Log("[JRTI-ScaledSwap]: Scaled atmosphere follows the reflection probe camera"); + } + + private static void BindSkyNode(Component skyNode, Camera camera) + { + var material = _materialField.GetValue(skyNode) as Material; + var container = _containerField.GetValue(skyNode); + var parent = _parentScaledTransformField.GetValue(skyNode) as Transform; + if (material == null || container == null || parent == null) + return; + + var projection = camera.nonJitteredProjectionMatrix; + var view = camera.worldToCameraMatrix; + + var cameraToWorld = view.inverse; + cameraToWorld.SetColumn(2, -cameraToWorld.GetColumn(2)); + material.SetMatrix(CameraToWorldId, cameraToWorld); + material.SetMatrix(CurrentVpId, GL.GetGPUProjectionMatrix(projection, false) * view); + + BoundsArgs[0] = camera; + BoundsArgs[1] = projection; + BoundsArgs[2] = view; + BoundsArgs[3] = parent.position; + BoundsArgs[4] = (float)_rtField.GetValue(skyNode) / ScaledSpace.ScaleFactor; + _updateScreenBoundsMethod.Invoke(container, BoundsArgs); + } + + private static bool Resolve() + { + if (_resolved) + return _skyNodeType != null; + + var scatterer = ScattererScaledCameraSwap.ScattererAssembly; + if (scatterer == null) + return false; + + _resolved = true; + var skyNodeType = scatterer.GetType("Scatterer.SkyNode"); + if (skyNodeType == null) + return false; + + const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; + _materialField = skyNodeType.GetField("scaledDepthBufferScatteringMaterial", flags); + _containerField = skyNodeType.GetField("scaledDepthBufferScatteringContainer", flags); + _parentScaledTransformField = skyNodeType.GetField("parentScaledTransform", flags); + _rtField = skyNodeType.GetField("Rt", flags); + _updateScreenBoundsMethod = _containerField?.FieldType.GetMethod("UpdateScreenBounds", flags); + _enableScreenCopyMethod = scatterer.GetType("Scatterer.ScreenCopyCommandBuffer") + ?.GetMethod("EnableScreenCopyForFrame", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(Camera) }, null); + + if (_materialField == null || _parentScaledTransformField == null || _rtField == null || _updateScreenBoundsMethod == null) + { + Debug.Log("[JRTI-ScaledSwap]: Scatterer has no scaled depth-buffer atmosphere - nothing to bind"); + return false; + } + + _skyNodeType = skyNodeType; + Debug.Log("[JRTI-ScaledSwap]: Scaled atmosphere follows feed cameras"); + return true; + } + } +} diff --git a/Source/ScattererScaledCameraSwap.cs b/Source/ScattererScaledCameraSwap.cs index f674d16..55ff948 100644 --- a/Source/ScattererScaledCameraSwap.cs +++ b/Source/ScattererScaledCameraSwap.cs @@ -13,6 +13,7 @@ public class ScattererScaledCameraSwap : MonoBehaviour private static object _scattererInstance; private static FieldInfo _scaledCameraField; private static Camera _mainScaledCamera; + private static Assembly _scattererAssembly; private static readonly string[] _candidateFieldNames = { @@ -22,9 +23,13 @@ public class ScattererScaledCameraSwap : MonoBehaviour "mainScaledCamera", }; + internal static Camera MainScaledCamera => _initialized ? _mainScaledCamera : null; + internal static Assembly ScattererAssembly => _scattererAssembly; + void Awake() { _camera = GetComponent(); + gameObject.AddComponent(); } void OnEnable() @@ -51,6 +56,7 @@ private static bool Initialize(Camera scaledCamera) if (assembly == null) return false; + _scattererAssembly = assembly; var scattererType = assembly.GetType("Scatterer.Scatterer"); if (scattererType == null) { @@ -121,6 +127,8 @@ void OnPreCull() return; _scaledCameraField.SetValue(_scattererInstance, _camera); + ScattererScaledAtmosphere.EnableScreenCopy(_camera); + ScattererScaledAtmosphere.AttachToReflectionProbe(); } void OnPostRender()