Fix Shadows (#686)

<!-- A new module or something else important -->
## Major features
-

<!-- A new parameter added to a module, or API feature -->
## Minor features
-

<!-- Some improvement that requires no action on the part of add-on
creators i.e., improved star graphics -->
## Improvements
-

<!-- Be sure to reference the existing issue if it exists -->
## Bug fixes
- Shadows glitch out way less
- Custom planets now can have better, longer shadows (using
ProxyShadowCaster and ProxyShadowCasterGroup from existing details and
in bundles)
  - Shadows no longer jitter
- Note: short-distance shadows still cast from planets behind suns.
However, this also happens in vanilla, so it is not fixed here
This commit is contained in:
Will Corby 2023-08-07 20:39:13 -07:00 committed by GitHub
commit fea15287c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 15 deletions

View File

@ -30,6 +30,11 @@ namespace NewHorizons.Builder.Body
{ {
groundGO.transform.localScale *= 2; // Multiply by 2 to match top layer groundGO.transform.localScale *= 2; // Multiply by 2 to match top layer
} }
var superGroup = planetGO.GetComponent<ProxyShadowCasterSuperGroup>();
// idk if we need to set _superGroup manually since it does that in Awake, but it's done everywhere else so wtv
if (superGroup != null) groundGO.AddComponent<ProxyShadowCaster>()._superGroup = superGroup;
groundGO.SetActive(true); groundGO.SetActive(true);
return groundGO; return groundGO;

View File

@ -178,14 +178,11 @@ namespace NewHorizons.Builder.Body
light.color = lightColour; light.color = lightColour;
ambientLight.color = new Color(lightColour.r, lightColour.g, lightColour.b, lightColour.a == 0 ? 0.0001f : lightColour.a); ambientLight.color = new Color(lightColour.r, lightColour.g, lightColour.b, lightColour.a == 0 ? 0.0001f : lightColour.a);
// used to use CopyPropertiesFrom, but that doesnt work here. instead, just copy settings from unity explorer
var faceActiveCamera = sunLight.AddComponent<FaceActiveCamera>(); var faceActiveCamera = sunLight.AddComponent<FaceActiveCamera>();
faceActiveCamera.CopyPropertiesFrom(_sunLight.GetComponent<FaceActiveCamera>()); faceActiveCamera._useLookAt = true;
var csmTextureCacher = sunLight.AddComponent<CSMTextureCacher>(); var csmTextureCacher = sunLight.AddComponent<CSMTextureCacher>();
csmTextureCacher.CopyPropertiesFrom(_sunLight.GetComponent<CSMTextureCacher>());
csmTextureCacher._light = light;
var proxyShadowLight = sunLight.AddComponent<ProxyShadowLight>(); var proxyShadowLight = sunLight.AddComponent<ProxyShadowLight>();
proxyShadowLight.CopyPropertiesFrom(_sunLight.GetComponent<ProxyShadowLight>());
proxyShadowLight._light = light;
sunLight.name = "StarLight"; sunLight.name = "StarLight";

View File

@ -1,13 +1,12 @@
using NewHorizons.External.Configs;
using NewHorizons.Utility; using NewHorizons.Utility;
using UnityEngine; using UnityEngine;
namespace NewHorizons.Builder.General namespace NewHorizons.Builder.General
{ {
public static class RigidBodyBuilder public static class RigidBodyBuilder
{ {
public static OWRigidbody Make(GameObject body, PlanetConfig config) public static OWRigidbody Make(GameObject body, float sphereOfInfluence)
{ {
body.AddComponent<ProxyShadowCasterSuperGroup>(); body.AddComponent<ProxyShadowCasterSuperGroup>()._bounds.radius = sphereOfInfluence;
Rigidbody rigidBody = body.AddComponent<Rigidbody>(); Rigidbody rigidBody = body.AddComponent<Rigidbody>();
rigidBody.mass = 10000; rigidBody.mass = 10000;

View File

@ -346,10 +346,12 @@ namespace NewHorizons.Handlers
body.Config.Base.showMinimap = false; body.Config.Base.showMinimap = false;
body.Config.Base.hasMapMarker = false; body.Config.Base.hasMapMarker = false;
var owRigidBody = RigidBodyBuilder.Make(go, body.Config); const float sphereOfInfluence = 2000f;
var owRigidBody = RigidBodyBuilder.Make(go, sphereOfInfluence);
var ao = AstroObjectBuilder.Make(go, null, body.Config, false); var ao = AstroObjectBuilder.Make(go, null, body.Config, false);
var sector = SectorBuilder.Make(go, owRigidBody, 2000f); var sector = SectorBuilder.Make(go, owRigidBody, sphereOfInfluence);
ao._rootSector = sector; ao._rootSector = sector;
ao._type = AstroObject.Type.None; ao._type = AstroObject.Type.None;
@ -419,10 +421,10 @@ namespace NewHorizons.Handlers
}; };
} }
var owRigidBody = RigidBodyBuilder.Make(go, body.Config);
var ao = AstroObjectBuilder.Make(go, primaryBody, body.Config, false);
var sphereOfInfluence = GetSphereOfInfluence(body); var sphereOfInfluence = GetSphereOfInfluence(body);
var owRigidBody = RigidBodyBuilder.Make(go, sphereOfInfluence);
var ao = AstroObjectBuilder.Make(go, primaryBody, body.Config, false);
var sector = SectorBuilder.Make(go, owRigidBody, sphereOfInfluence * 2f); var sector = SectorBuilder.Make(go, owRigidBody, sphereOfInfluence * 2f);
ao._rootSector = sector; ao._rootSector = sector;

View File

@ -78,6 +78,12 @@ namespace NewHorizons.Handlers
gameObject.SetActive(false); gameObject.SetActive(false);
} }
GameObject.FindObjectOfType<SunProxy>().gameObject.SetActive(false); GameObject.FindObjectOfType<SunProxy>().gameObject.SetActive(false);
// force call update here to make it switch to an active star. idk why we didnt have to do this before
SunLightEffectsController.Instance.Update();
// Since we didn't call RemoveBody on the Stranger have to call this here
StrangerRemoved();
}, 2); // Have to wait or shit goes wild }, 2); // Have to wait or shit goes wild
foreach (var streamingAssetBundle in StreamingManager.s_activeBundles) foreach (var streamingAssetBundle in StreamingManager.s_activeBundles)
@ -96,14 +102,23 @@ namespace NewHorizons.Handlers
} }
} }
public static void StrangerRemoved()
{
CloakHandler.FlagStrangerDisabled = true;
if (Locator._cloakFieldController?.GetComponentInParent<AstroObject>()?.GetAstroObjectName() == AstroObject.Name.RingWorld)
{
Locator._cloakFieldController = null;
}
}
public static void RemoveBody(AstroObject ao, bool delete = false, List<AstroObject> toDestroy = null) public static void RemoveBody(AstroObject ao, bool delete = false, List<AstroObject> toDestroy = null)
{ {
NHLogger.LogVerbose($"Removing [{ao.name}]"); NHLogger.LogVerbose($"Removing [{ao.name}]");
if (ao.GetAstroObjectName() == AstroObject.Name.RingWorld) if (ao.GetAstroObjectName() == AstroObject.Name.RingWorld)
{ {
CloakHandler.FlagStrangerDisabled = true; StrangerRemoved();
if (Locator._cloakFieldController?.GetComponentInParent<AstroObject>() == ao) Locator._cloakFieldController = null;
} }
if (ao.gameObject == null || !ao.gameObject.activeInHierarchy) if (ao.gameObject == null || !ao.gameObject.activeInHierarchy)