mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-29 23:40:23 +00:00
update light angle every frame
This commit is contained in:
parent
91f136b97c
commit
bcf74a342d
1 changed files with 16 additions and 3 deletions
|
@ -18,6 +18,8 @@ namespace SanAndreasUnity.Behaviours.World
|
||||||
public byte CurrentTimeHours { get; private set; }
|
public byte CurrentTimeHours { get; private set; }
|
||||||
public byte CurrentTimeMinutes { get; private set; }
|
public byte CurrentTimeMinutes { get; private set; }
|
||||||
|
|
||||||
|
public float CurrentCurveTime => (this.CurrentTimeHours + this.CurrentTimeMinutes / 60f) / 24f;
|
||||||
|
|
||||||
private float m_timeSinceTimeAdvanced = 0;
|
private float m_timeSinceTimeAdvanced = 0;
|
||||||
|
|
||||||
public float timeScale = 1;
|
public float timeScale = 1;
|
||||||
|
@ -69,6 +71,11 @@ namespace SanAndreasUnity.Behaviours.World
|
||||||
m_timeSinceTimeAdvanced = 0;
|
m_timeSinceTimeAdvanced = 0;
|
||||||
this.AdvanceTime();
|
this.AdvanceTime();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// light angle should be updated every frame
|
||||||
|
this.UpdateLightAngle(this.CurrentCurveTime + m_timeSinceTimeAdvanced / 60f / 24f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdvanceTime()
|
void AdvanceTime()
|
||||||
|
@ -95,7 +102,7 @@ namespace SanAndreasUnity.Behaviours.World
|
||||||
this.CurrentTimeHours = hours;
|
this.CurrentTimeHours = hours;
|
||||||
this.CurrentTimeMinutes = minutes;
|
this.CurrentTimeMinutes = minutes;
|
||||||
|
|
||||||
float curveTime = (hours + minutes / 60f) / 24f;
|
float curveTime = this.CurrentCurveTime;
|
||||||
|
|
||||||
float lightIntensity = this.lightIntensityCurve.Evaluate(curveTime);
|
float lightIntensity = this.lightIntensityCurve.Evaluate(curveTime);
|
||||||
bool isNight = lightIntensity <= 0;
|
bool isNight = lightIntensity <= 0;
|
||||||
|
@ -112,8 +119,7 @@ namespace SanAndreasUnity.Behaviours.World
|
||||||
float skyboxExposure = isNight ? 0f : m_originalSkyboxExposure * lightIntensity;
|
float skyboxExposure = isNight ? 0f : m_originalSkyboxExposure * lightIntensity;
|
||||||
RenderSettings.skybox.SetFloat(ExposurePropertyId, skyboxExposure);
|
RenderSettings.skybox.SetFloat(ExposurePropertyId, skyboxExposure);
|
||||||
|
|
||||||
float lightAngle = this.lightAngleCurve.Evaluate(curveTime) * 180f;
|
float lightAngle = this.UpdateLightAngle(curveTime);
|
||||||
this.directionalLight.transform.rotation = Quaternion.AngleAxis(lightAngle, Vector3.right);
|
|
||||||
|
|
||||||
float nightMultiplier = this.nightColorsIntensityCurve.Evaluate(curveTime) * this.nightColorsMultiplier;
|
float nightMultiplier = this.nightColorsIntensityCurve.Evaluate(curveTime) * this.nightColorsMultiplier;
|
||||||
Shader.SetGlobalFloat(NightMultiplierPropertyId, nightMultiplier);
|
Shader.SetGlobalFloat(NightMultiplierPropertyId, nightMultiplier);
|
||||||
|
@ -123,5 +129,12 @@ namespace SanAndreasUnity.Behaviours.World
|
||||||
Debug.Log($"Time set to {hours}:{minutes}, curveTime {curveTime}, lightIntensity {lightIntensity}, lightAngle {lightAngle}, nightMultiplier {nightMultiplier}");
|
Debug.Log($"Time set to {hours}:{minutes}, curveTime {curveTime}, lightIntensity {lightIntensity}, lightAngle {lightAngle}, nightMultiplier {nightMultiplier}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float UpdateLightAngle(float curveTime)
|
||||||
|
{
|
||||||
|
float lightAngle = this.lightAngleCurve.Evaluate(curveTime) * 180f;
|
||||||
|
this.directionalLight.transform.rotation = Quaternion.AngleAxis(lightAngle, Vector3.right);
|
||||||
|
return lightAngle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue