From 7eb6115a7bae896ac770fdf87fe680a0958a343c Mon Sep 17 00:00:00 2001
From: OrangeSpork <57274555+OrangeSpork@users.noreply.github.com>
Date: Sun, 24 Oct 2021 23:12:11 -0600
Subject: [PATCH] Improvements to light setting tracking. Fixes for additional
lights in main game.
---
Graphics/AIGraphics/AIGraphics.csproj | 2 +-
Graphics/Shared/Graphics.cs | 2 +-
Graphics/Shared/LightManager.cs | 8 +++
Graphics/Shared/MapLightPreset.cs | 10 +++-
Graphics/Shared/SceneController.cs | 54 +++++++++++++++++++--
Graphics/Shared/Setting/PerLightSettings.cs | 23 +++++++--
6 files changed, 88 insertions(+), 11 deletions(-)
diff --git a/Graphics/AIGraphics/AIGraphics.csproj b/Graphics/AIGraphics/AIGraphics.csproj
index 0e44ab4..9e94256 100644
--- a/Graphics/AIGraphics/AIGraphics.csproj
+++ b/Graphics/AIGraphics/AIGraphics.csproj
@@ -20,7 +20,7 @@
full
false
D:\AI-Syoujyo\BepInEx\plugins\gps\
- DEBUG;TRACE
+ TRACE;DEBUG;AI
prompt
4
true
diff --git a/Graphics/Shared/Graphics.cs b/Graphics/Shared/Graphics.cs
index 8b65fad..1ef5f08 100644
--- a/Graphics/Shared/Graphics.cs
+++ b/Graphics/Shared/Graphics.cs
@@ -25,7 +25,7 @@ public partial class Graphics : BaseUnityPlugin
{
public const string GUID = "ore.graphics";
public const string PluginName = "Graphics";
- public const string Version = "0.4.4";
+ public const string Version = "0.4.5";
public static ConfigEntry ConfigShortcut { get; private set; }
public static ConfigEntry ConfigCubeMapPath { get; private set; }
diff --git a/Graphics/Shared/LightManager.cs b/Graphics/Shared/LightManager.cs
index 76f2a65..ba807d0 100644
--- a/Graphics/Shared/LightManager.cs
+++ b/Graphics/Shared/LightManager.cs
@@ -114,6 +114,14 @@ internal static List GetLights()
private bool IsStudioLight { get => Graphics.Instance.IsStudio() && null == _light && null != _ociLight; }
+ internal OCILight ociLight
+ {
+ get
+ {
+ return _ociLight;
+ }
+ }
+
internal Light light
{
get
diff --git a/Graphics/Shared/MapLightPreset.cs b/Graphics/Shared/MapLightPreset.cs
index c788b1e..ae2c4c8 100644
--- a/Graphics/Shared/MapLightPreset.cs
+++ b/Graphics/Shared/MapLightPreset.cs
@@ -69,9 +69,14 @@ public void UpdateParameters()
public void ApplyParameters()
{
+#if DEBUG
+ Graphics.Instance.Log.LogInfo($"Loading Reflection Probes.");
+#endif
if (reflectionProbes != null && reflectionProbes.Length > 0)
SceneController.ApplyReflectionProbeSettings(reflectionProbes);
-
+#if DEBUG
+ Graphics.Instance.Log.LogInfo($"Loaded Light Settings.");
+#endif
if (lights != null && lights.Length > 0)
SceneController.ApplyLightSettings(lights);
}
@@ -79,6 +84,9 @@ public void ApplyParameters()
public void Load(byte[] bytes)
{
Deserialize(bytes);
+#if DEBUG
+ Graphics.Instance.Log.LogInfo($"Loaded map preset, applying.");
+#endif
ApplyParameters();
}
diff --git a/Graphics/Shared/SceneController.cs b/Graphics/Shared/SceneController.cs
index b3175a7..a4ab43b 100644
--- a/Graphics/Shared/SceneController.cs
+++ b/Graphics/Shared/SceneController.cs
@@ -86,6 +86,48 @@ private PluginData DoSave()
return pluginData;
}
+
+ // Using a mix of hierarchy and object id key allows us to handle both Object lights and Scene lights
+ private static PerLightSettings FindLightSettingsForLight(LightObject light, PerLightSettings[] settings)
+ {
+#if DEBUG
+ Graphics.Instance.Log.LogInfo($"Light: {light?.ociLight} {light?.ociLight?.lightInfo?.dicKey} {light?.light?.gameObject?.transform}");
+#endif
+
+ PerLightSettings setting = null;
+ if (light.ociLight != null)
+ {
+ // Try by dic key AND path
+ setting = settings.FirstOrDefault(s => s.LightId == light?.ociLight?.lightInfo.dicKey && s.HierarchyPath != null && s.HierarchyPath.Matches(light.light.gameObject.transform));
+ if (setting != null)
+ {
+#if DEBUG
+ Graphics.Instance.Log.LogInfo($"Found by dic key and hierarchy: {setting.LightId}:{setting.HierarchyPath}");
+#endif
+ return setting;
+ }
+
+ // Try by dic key
+ setting = settings.FirstOrDefault(s => s.LightId == light.ociLight.lightInfo.dicKey);
+ if (setting != null)
+ {
+#if DEBUG
+ Graphics.Instance.Log.LogInfo($"Found by dic key only: {setting.LightId}:{setting.HierarchyPath}");
+#endif
+ return setting;
+ }
+ }
+ // Try by path
+ setting = settings.FirstOrDefault(s => s.HierarchyPath.Matches(light.light.gameObject.transform));
+#if DEBUG
+ if (setting != null)
+ Graphics.Instance.Log.LogInfo($"Found by hierarchy only: {setting.LightId}:{setting.HierarchyPath}");
+ else
+ Graphics.Instance.Log.LogInfo($"New Light");
+#endif
+ return setting;
+ }
+
public static void ApplyLightSettings(PerLightSettings[] settings)
{
LightManager lightManager = Graphics.Instance.LightManager;
@@ -98,7 +140,7 @@ public static void ApplyLightSettings(PerLightSettings[] settings)
{
foreach (LightObject light in lightManager.DirectionalLights)
{
- PerLightSettings setting = settings.FirstOrDefault(s => s.HierarchyPath.Matches(light.light.gameObject.transform));
+ PerLightSettings setting = FindLightSettingsForLight(light, settings);
if (setting != null)
{
setting.ApplySettings(light);
@@ -108,14 +150,14 @@ public static void ApplyLightSettings(PerLightSettings[] settings)
foreach (LightObject light in lightManager.PointLights)
{
- PerLightSettings setting = settings.FirstOrDefault(s => s.HierarchyPath.Matches(light.light.gameObject.transform));
+ PerLightSettings setting = FindLightSettingsForLight(light, settings);
if (setting != null)
setting.ApplySettings(light);
}
foreach (LightObject light in lightManager.SpotLights)
{
- PerLightSettings setting = settings.FirstOrDefault(s => s.HierarchyPath.Matches(light.light.gameObject.transform));
+ PerLightSettings setting = FindLightSettingsForLight(light, settings);
if (setting != null)
setting.ApplySettings(light);
}
@@ -149,6 +191,10 @@ public static void ApplyLightSettings(PerLightSettings[] settings)
// Add extra lights if requested
foreach (PerLightSettings setting in newDirectionalLights)
{
+#if DEBUG
+ Graphics.Instance.Log.LogInfo($"Adding Additional Light {setting.LightName}");
+#endif
+
GameObject lightGameObject = new GameObject(setting.LightName);
Light lightComp = lightGameObject.AddComponent();
lightGameObject.GetComponent().type = LightType.Directional;
@@ -156,7 +202,7 @@ public static void ApplyLightSettings(PerLightSettings[] settings)
lightManager.Light();
foreach (LightObject light in lightManager.DirectionalLights)
{
- PerLightSettings setting = settings.FirstOrDefault(s => s.HierarchyPath.Matches(light.light.gameObject.transform));
+ PerLightSettings setting = FindLightSettingsForLight(light, settings);
if (setting != null)
{
setting.ApplySettings(light);
diff --git a/Graphics/Shared/Setting/PerLightSettings.cs b/Graphics/Shared/Setting/PerLightSettings.cs
index d31aff6..3327b06 100644
--- a/Graphics/Shared/Setting/PerLightSettings.cs
+++ b/Graphics/Shared/Setting/PerLightSettings.cs
@@ -34,11 +34,12 @@ public class PerLightSettings
public int RenderMode { get; set; }
public int CullingMask { get; set; }
public PathElement HierarchyPath { get; set; }
+ public int LightId { get; set; }
public int Type { get; set; }
internal void ApplySettings(LightObject lightObject)
- {
+ {
lightObject.enabled = !Disabled;
Graphics.Instance.LightManager.UseAlloyLight = UseAlloyLight;
@@ -47,10 +48,11 @@ internal void ApplySettings(LightObject lightObject)
{
SetAlias(lightObject.light, LightName);
}
-
+
lightObject.color = Color;
lightObject.light.colorTemperature = ColorTemperature;
+
lightObject.shadows = (LightShadows)ShadowType;
lightObject.light.shadowStrength = ShadowStrength;
if (LightType.Directional == lightObject.type && Graphics.Instance.Settings.UsePCSS)
@@ -58,12 +60,14 @@ internal void ApplySettings(LightObject lightObject)
else
lightObject.light.shadowResolution = (LightShadowResolution)ShadowResolutionType;
+
lightObject.light.shadowBias = ShadowBias;
lightObject.light.shadowNormalBias = ShadowNormalBias;
lightObject.light.shadowNearPlane = ShadowNearPlane;
-
+
lightObject.intensity = LightIntensity;
lightObject.light.bounceIntensity = IndirectMultiplier;
+
if (SegiSun)
{
if (null != Graphics.Instance.CameraSettings.MainCamera)
@@ -82,7 +86,6 @@ internal void ApplySettings(LightObject lightObject)
else if (!KKAPI.Studio.StudioAPI.InsideStudio && lightObject.light.name.StartsWith("(Graphics)"))
lightObject.rotation = Rotation;
-
lightObject.range = Range;
lightObject.spotAngle = SpotAngle;
if (Graphics.Instance.LightManager.UseAlloyLight)
@@ -111,6 +114,10 @@ internal void FillSettings(LightObject lightObject)
LightName = NameForLight(lightObject.light);
Graphics.Instance.Log.LogInfo($"Storing Light Alias {LightName}");
}
+ else if (GraphicsAddedLight(lightObject.light))
+ {
+ LightName = lightObject.light.gameObject.name;
+ }
Color = lightObject.color;
ColorTemperature = lightObject.light.colorTemperature;
@@ -166,6 +173,14 @@ internal void FillSettings(LightObject lightObject)
CullingMask = lightObject.light.cullingMask;
HierarchyPath = PathElement.Build(lightObject.light.gameObject.transform);
+
+ if (lightObject.ociLight != null)
+ LightId = lightObject.ociLight.lightInfo.dicKey;
+ }
+
+ internal static bool GraphicsAddedLight(Light light)
+ {
+ return light.gameObject.name.StartsWith("(Graphics)");
}
internal static Dictionary, string> LightNameAliases = new Dictionary, string>();