Skip to content

Commit

Permalink
Fix #174: improve shadows in IVAs
Browse files Browse the repository at this point in the history
-Not really sure why this happens, but unity's "soft" shadow mode really butchers the shadows inside IVAs.  So we change it to use "hard" mode instead, and tweak the bias numbers to make it look better
-also disable shadow casting on internal depth masks and any window renderers, so the sunlight comes through them
  • Loading branch information
JonnyOThan committed Jan 24, 2023
1 parent 54f21dc commit 28e593c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions FreeIva/FreeIva.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public void Start()
Physics.IgnoreLayerCollision((int)Layers.Kerbals, (int)Layers.InternalSpace);
Physics.IgnoreLayerCollision((int)Layers.Kerbals, (int)Layers.Kerbals, false);

var ivaSun = InternalSpace.Instance.transform.Find("IVASun").GetComponent<IVASun>();
ivaSun.ivaLight.shadowBias = 0;
ivaSun.ivaLight.shadowNormalBias = 0;
ivaSun.ivaLight.shadows = LightShadows.Hard;


// prevent mouse clicks from hitting the kerbal collider or the internal shell
// Some of the shell colliders are a little too tight and block props
// This has a few downsides:
Expand Down
24 changes: 24 additions & 0 deletions FreeIva/Gui/GuiManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public static void Gui()
#if Experimental
PressureGui();
#endif
ShadowsGui();
SeatGui();
PropGui();
MeshRendererGui();
Expand All @@ -111,6 +112,29 @@ public static void Gui()
//GUILayout.Label("Colliding: " + colliding);
}

private static bool showShadowGui = false;
private static void ShadowsGui()
{
if (GUILayout.Button((showShadowGui ? "Hide" : "Show") + " shadows configuration"))
{
showShadowGui = !showShadowGui;
}

if (!showShadowGui) return;

IVASun ivaSun = InternalSpace.Instance.transform.Find("IVASun").GetComponent<IVASun>();

float bias = ivaSun.ivaLight.shadowBias;
GuiUtils.slider("bias", ref bias, 0, 1);
ivaSun.ivaLight.shadowBias = bias;

float normalBias = ivaSun.ivaLight.shadowNormalBias;
GuiUtils.slider("normal bias", ref normalBias, 0, 1);
ivaSun.ivaLight.shadowNormalBias = normalBias;

ivaSun.ivaLight.shadows = (LightShadows)GuiUtils.radioButtons(Enum.GetNames(typeof(LightShadows)), (int)ivaSun.ivaLight.shadows);
}

private static bool showKerbalColliderGui = false;
private static void KerbalColliderGui()
{
Expand Down
3 changes: 3 additions & 0 deletions FreeIva/InternalModules/InternalModuleFreeIva.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ private void OnLoad_DepthMasks()
{
meshRenderer.sharedMaterial = Utils.GetDepthMaskCullingMaterial();
meshRenderer.gameObject.layer = (int)Layers.InternalSpace;
meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
meshRenderer.receiveShadows = false;
}
}
}
Expand Down Expand Up @@ -391,6 +393,7 @@ private bool OnLoad_Windows(ConfigNode node)
{
hasWindows = true;
meshRenderer.material.renderQueue = WINDOW_RENDER_QUEUE;
meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
Debug.Log($"[FreeIva] INTERNAL '{internalModel.internalName}' auto-detected window transform '{meshRenderer.transform.name}'");
}
}
Expand Down

0 comments on commit 28e593c

Please sign in to comment.