From 76e6f086417f2be78caa49a867d39d903ce77b45 Mon Sep 17 00:00:00 2001 From: lghassen Date: Sat, 15 May 2021 21:52:02 +0200 Subject: [PATCH] reduce ocean jittering in RSS --- .../Proland/Ocean/OceanCameraUpdateHook.cs | 16 +++++++--- scatterer/Scatterer.cs | 4 +-- .../Shadows/DoublePrecisionEmulation.cginc | 30 +++++++++++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/scatterer/Effects/Proland/Ocean/OceanCameraUpdateHook.cs b/scatterer/Effects/Proland/Ocean/OceanCameraUpdateHook.cs index b57d1c4d..6bbe6ae8 100644 --- a/scatterer/Effects/Proland/Ocean/OceanCameraUpdateHook.cs +++ b/scatterer/Effects/Proland/Ocean/OceanCameraUpdateHook.cs @@ -55,10 +55,18 @@ public void updateCameraSpecificUniforms (Material oceanMaterial, Camera inCamer ctol1.m10, ctol1.m11, ctol1.m12, ctol1.m13, ctol1.m20, ctol1.m21, ctol1.m22, ctol1.m23, ctol1.m30, ctol1.m31, ctol1.m32, ctol1.m33); - - Vector3d translation = oceanNode.m_manager.parentLocalTransform.position; - - + + Vector3d translation; + + if (HighLogic.LoadedScene == GameScenes.SPACECENTER) + { + translation = oceanNode.m_manager.parentLocalTransform.position; //have to use this in space center or get the tsunami bug + } + else + { + translation = oceanNode.m_manager.parentCelestialBody.position; //more precise, especially with RSS, but breaks a bit in KSC + } + Matrix4x4d worldToLocal = new Matrix4x4d(1, 0, 0, -translation.x, 0, 1, 0, -translation.y, 0, 0, 1, -translation.z, diff --git a/scatterer/Scatterer.cs b/scatterer/Scatterer.cs index ed79d0a2..03c9318c 100644 --- a/scatterer/Scatterer.cs +++ b/scatterer/Scatterer.cs @@ -11,7 +11,7 @@ using UnityEngine; using UnityEngine.Rendering; -[assembly:AssemblyVersion("0.0769")] +[assembly:AssemblyVersion("0.0770")] namespace scatterer { [KSPAddon(KSPAddon.Startup.EveryScene, false)] @@ -54,7 +54,7 @@ public class Scatterer: MonoBehaviour bool coreInitiated = false; public bool isActive = false; public bool unifiedCameraMode = false; - public string versionNumber = "0.0769 dev"; + public string versionNumber = "0.0770"; public List antiAliasingScripts = new List(); diff --git a/scatterer/Shaders/scattererShaders/Assets/Shaders/Shadows/DoublePrecisionEmulation.cginc b/scatterer/Shaders/scattererShaders/Assets/Shaders/Shadows/DoublePrecisionEmulation.cginc index 33adb2b1..9702e6a2 100644 --- a/scatterer/Shaders/scattererShaders/Assets/Shaders/Shadows/DoublePrecisionEmulation.cginc +++ b/scatterer/Shaders/scattererShaders/Assets/Shaders/Shadows/DoublePrecisionEmulation.cginc @@ -137,4 +137,34 @@ float2 ds_div (float2 dsa, float2 dsb) { dsc.y = minus_frc(s2, minus_frc(dsc.x, s1)); return dsc; +} + + +float2 ds_sqrt (float2 dsa) { + float2 dsb; + + float t1, t2, t3; + float2 f, s0, s1; + + if (dsa.x == 0.0) + { + return float2(0.0,0.0); + } + + t1 = div_frc(1.0, sqrt(dsa.x)); + t2 = times_frc(dsa.x, t1); + + s0 = ds_mul(ds_set(t2),ds_set(t2)); + s1 = ds_sub(dsa, s0); + + t3 = times_frc(0.5, times_frc(s1.x,t1)); + + s0.x = t2; + s0.y = 0.0; + s1.x = t3; + s1.y = 0.0; + + dsb = ds_add(s0, s1); + + return dsb; } \ No newline at end of file