Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DateToSkyMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@ private static double ToJulianDays(DateTime now)
private static readonly double jDaysPerLunarPrecession = 18.6 * 365.25; // 18.6 years per precessions, 365.25 jdays per year

public static readonly float maxProjectedSunOffset = ProceduralSkyInitializer.sunDistanceToCamera * Mathf.Tan(Mathf.Deg2Rad * 23.4f);
public static readonly float maxProjectedMoonOffset = ProceduralSkyInitializer.moonDistanceToCamera * Mathf.Tan(Mathf.Deg2Rad * (23.4f + 5.14f));
}
}
14 changes: 10 additions & 4 deletions SkyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace ProceduralSkyMod
public class SkyManager : MonoBehaviour
{
private Color ambientDay = new Color(.282f, .270f, .243f, 1f);
private Color ambientNight = new Color(.079f, .079f, .112f, 1f);
private Color ambientDarkNight = new Color(.082f, .082f, .098f, 1f);
private Color ambientMoonNight = new Color(.180f, .180f, .220f, 1f);
private Color defaultFog, nightFog;
private float defaultFogDensity;

Expand Down Expand Up @@ -105,17 +106,21 @@ void Update ()
worldPos = PlayerManager.PlayerTransform.position - WorldMover.currentMove;
transform.position = new Vector3(worldPos.x * .001f, 0, worldPos.z * .001f);

Vector3 highLatitudeCorrection = SunPathCenter.parent.TransformVector(SunPathCenter.localPosition) - SunPathCenter.parent.position / DateToSkyMapper.maxProjectedSunOffset;
Vector3 sunPos = SunLight.transform.position - SunPathCenter.position + highLatitudeCorrection;
Vector3 sunHighLatitudeCorrection = SunPathCenter.parent.TransformVector(SunPathCenter.localPosition) - SunPathCenter.parent.position / DateToSkyMapper.maxProjectedSunOffset;
Vector3 sunPos = SunLight.transform.position - SunPathCenter.position + sunHighLatitudeCorrection;
float sunOverHorizonFac = Mathf.Clamp01(sunPos.y);
Vector3 moonHighLatitudeCorrection = MoonPathCenter.parent.TransformVector(MoonPathCenter.localPosition) - MoonPathCenter.parent.position / DateToSkyMapper.maxProjectedMoonOffset;
Vector3 moonPos = MoonPathCenter.TransformVector(Vector3.up * ProceduralSkyInitializer.moonDistanceToCamera) - MoonPathCenter.position + moonHighLatitudeCorrection;
float moonOverHorizonFac = Mathf.Clamp01(moonPos.y);
SunLight.intensity = sunOverHorizonFac * 1.5f;
SunLight.color = Color.Lerp(new Color(1f, 0.5f, 0), Color.white, sunOverHorizonFac);

StarMaterial.SetFloat("_Visibility", (-sunOverHorizonFac + 1) * .01f);

MoonMaterial.SetFloat("_MoonDayNight", Mathf.Lerp(2.19f, 1.5f, sunOverHorizonFac));
// gives aproximate moon phase
MoonMaterial.SetFloat("_MoonPhase", Vector3.SignedAngle(SunPathCenter.right, MoonPathCenter.right, SunPathCenter.forward) / 180);
float moonPhase = Vector3.SignedAngle(SunPathCenter.right, MoonPathCenter.right, SunPathCenter.forward) / 180;
MoonMaterial.SetFloat("_MoonPhase", moonPhase);
MoonMaterial.SetFloat("_Exposure", Mathf.Lerp(2f, 4f, sunOverHorizonFac));

SkyMaterial.SetFloat("_Exposure", Mathf.Lerp(.01f, 1f, sunOverHorizonFac));
Expand All @@ -141,6 +146,7 @@ void Update ()
}
#endif

Color ambientNight = Color.Lerp(ambientDarkNight, ambientMoonNight, moonOverHorizonFac * Mathf.Abs(moonPhase));
RenderSettings.fogColor = Color.Lerp(nightFog, defaultFog, sunOverHorizonFac);
RenderSettings.ambientSkyColor = Color.Lerp(ambientNight, ambientDay, sunOverHorizonFac);

Expand Down