Skip to content

Commit

Permalink
Fix clip planes for OpenGL
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav committed Dec 7, 2021
1 parent 4ff7002 commit 3c45a66
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 26 deletions.
Binary file modified GameData/RealSolarSystem/Plugins/RealSolarSystem.dll
Binary file not shown.
6 changes: 5 additions & 1 deletion GameData/RealSolarSystem/Readme_RSS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ FINAL NOTES:
You really should play with the recommended mods. See the Realism Overhaul thread for details.

===========================
Changelog
v18.4.0
* Fix clip planes for OpenGL, @siimav

Changelog
v18.3.0
* Fix too low clip plane value which caused artifacts to appear near the horizon, @siimav
* Fix too low clip plane value which caused artifacts to appear near the horizon, @siimav
* Fix KSC runway becoming bumpy if KK is installed, @NathanKell

v18.2.0
Expand Down
12 changes: 11 additions & 1 deletion GameData/RealSolarSystem/RealSolarSystem.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ REALSOLARSYSTEM
{
overrideCommNetParams = True

cam00FarClip = 1250000
ClipPlanes
{
DX11
{
cam00FarClip = 1250000
}
Other
{
cam01FarClip = 1250000
}
}

timeWarpRates
{
Expand Down
2 changes: 1 addition & 1 deletion GameData/RealSolarSystem/RealSolarSystem.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"URL": "https://github.com/KSP-RO/RealSolarSystem/raw/master/GameData/RealSolarSystem/RealSolarSystem.version",
"VERSION": {
"MAJOR": 18,
"MINOR": 3,
"MINOR": 4,
"PATCH": 0
},
"KSP_VERSION_MIN": {
Expand Down
4 changes: 2 additions & 2 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("18.3.0.0")]
[assembly: AssemblyFileVersion("18.3.0.0")]
[assembly: AssemblyVersion("18.4.0.0")]
[assembly: AssemblyFileVersion("18.4.0.0")]

[assembly: KSPAssemblyDependency("Kopernicus", 1, 0)]
[assembly: KSPAssemblyDependency("Kopernicus.Parser", 1, 0)]
54 changes: 33 additions & 21 deletions Source/Watchdogs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using UnityEngine.Rendering;

namespace RealSolarSystem
{
Expand Down Expand Up @@ -38,67 +39,78 @@ public void Update()

delayCounter += Time.deltaTime;

if(delayCounter < initialDelay)
if (delayCounter < initialDelay)
return;

watchdogRun = true;

Camera[] cameras = Camera.allCameras;
string bodyName = FlightGlobals.getMainBody().name;

ConfigNode clipPlaneSettings;
if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11 ||
SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D12)
{
clipPlaneSettings = rssSettings.GetNode("ClipPlanes")?.GetNode("DX11");
}
else
{
clipPlaneSettings = rssSettings.GetNode("ClipPlanes")?.GetNode("Other");
}

if (clipPlaneSettings == null) return;

foreach (Camera cam in cameras)
{
float farClip = -1;
float nearClip = -1;

if (cam.name.Equals("Camera 00"))
{
rssSettings.TryGetValue("cam00FarClip", ref farClip);
clipPlaneSettings.TryGetValue("cam00FarClip", ref farClip);

if (rssSettings.HasNode(bodyName))
rssSettings.GetNode(bodyName).TryGetValue("cam00FarClip", ref farClip);
if (clipPlaneSettings.HasNode(bodyName))
clipPlaneSettings.GetNode(bodyName).TryGetValue("cam00FarClip", ref farClip);

rssSettings.TryGetValue("cam00NearClip", ref nearClip);
clipPlaneSettings.TryGetValue("cam00NearClip", ref nearClip);

if (rssSettings.HasNode(bodyName))
rssSettings.GetNode(bodyName).TryGetValue("cam00NearClip", ref nearClip);
if (clipPlaneSettings.HasNode(bodyName))
clipPlaneSettings.GetNode(bodyName).TryGetValue("cam00NearClip", ref nearClip);
}
else if (cam.name.Equals("Camera 01"))
{
rssSettings.TryGetValue("cam01FarClip", ref farClip);
clipPlaneSettings.TryGetValue("cam01FarClip", ref farClip);

if (rssSettings.HasNode(bodyName))
rssSettings.GetNode(bodyName).TryGetValue("cam01FarClip", ref farClip);
if (clipPlaneSettings.HasNode(bodyName))
clipPlaneSettings.GetNode(bodyName).TryGetValue("cam01FarClip", ref farClip);

rssSettings.TryGetValue("cam01NearClip", ref nearClip);
clipPlaneSettings.TryGetValue("cam01NearClip", ref nearClip);

if (rssSettings.HasNode(bodyName))
rssSettings.GetNode(bodyName).TryGetValue("cam01NearClip", ref nearClip);
if (clipPlaneSettings.HasNode(bodyName))
clipPlaneSettings.GetNode(bodyName).TryGetValue("cam01NearClip", ref nearClip);
}
else if (cam.name.Equals("Camera ScaledSpace"))
{
rssSettings.TryGetValue("camScaledSpaceFarClip", ref farClip);
clipPlaneSettings.TryGetValue("camScaledSpaceFarClip", ref farClip);

if (rssSettings.HasNode(bodyName))
rssSettings.GetNode(bodyName).TryGetValue("camScaledSpaceFarClip", ref farClip);
if (clipPlaneSettings.HasNode(bodyName))
clipPlaneSettings.GetNode(bodyName).TryGetValue("camScaledSpaceFarClip", ref farClip);

rssSettings.TryGetValue("camScaledSpaceNearClip", ref nearClip);
clipPlaneSettings.TryGetValue("camScaledSpaceNearClip", ref nearClip);

if (rssSettings.HasNode(bodyName))
rssSettings.GetNode(bodyName).TryGetValue("camScaledSpaceNearClip", ref nearClip);
if (clipPlaneSettings.HasNode(bodyName))
clipPlaneSettings.GetNode(bodyName).TryGetValue("camScaledSpaceNearClip", ref nearClip);
}

if (nearClip > 0)
{
cam.nearClipPlane = nearClip;

Debug.Log($"[RealSolarSystem] Watchdog: Setting camera {cam.name} near clip to {nearClip} so camera now has {cam.nearClipPlane}");
}

if (farClip > 0)
{
cam.farClipPlane = farClip;

Debug.Log($"[RealSolarSystem] Watchdog: Setting camera {cam.name} far clip to {farClip} so camera now has {cam.farClipPlane}");
}
}
Expand Down

0 comments on commit 3c45a66

Please sign in to comment.