imp. sun system

This commit is contained in:
Vladimir Koshevarov
2022-12-12 18:48:02 +02:00
parent c6e463e795
commit 10b7647f3f
3 changed files with 83 additions and 22 deletions
@@ -0,0 +1,64 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!850595691 &4890085278179872738
LightingSettings:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: New Lighting Settings
serializedVersion: 4
m_GIWorkflowMode: 1
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 0
m_RealtimeEnvironmentLighting: 1
m_BounceScale: 1
m_AlbedoBoost: 1
m_IndirectOutputScale: 1
m_UsingShadowmask: 1
m_BakeBackend: 1
m_LightmapMaxSize: 1024
m_BakeResolution: 40
m_Padding: 2
m_LightmapCompression: 3
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_ExtractAO: 0
m_MixedBakeMode: 2
m_LightmapsBakeMode: 1
m_FilterMode: 1
m_LightmapParameters: {fileID: 15204, guid: 0000000000000000f000000000000000, type: 0}
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_RealtimeResolution: 2
m_ForceWhiteAlbedo: 0
m_ForceUpdates: 0
m_FinalGather: 0
m_FinalGatherRayCount: 256
m_FinalGatherFiltering: 1
m_PVRCulling: 1
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 512
m_PVREnvironmentSampleCount: 256
m_PVREnvironmentReferencePointCount: 2048
m_LightProbeSampleCountMultiplier: 4
m_PVRBounces: 2
m_PVRMinBounces: 1
m_PVREnvironmentMIS: 1
m_PVRFilteringMode: 1
m_PVRDenoiserTypeDirect: 1
m_PVRDenoiserTypeIndirect: 1
m_PVRDenoiserTypeAO: 1
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_PVRTiledBaking: 0
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0ed2a899ff2cfdd4aaea5de3a75433c2
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 4890085278179872738
userData:
assetBundleName:
assetBundleVariant:
+11 -22
View File
@@ -38,6 +38,7 @@ public class TimeManager : MonoBehaviour
private TimeSpan _sunsetTime;
private float _timer;
private float _sunInitialIntensity;
[SerializeField]
private float _minuteToRealTime = 0.05f;
@@ -48,6 +49,7 @@ public class TimeManager : MonoBehaviour
// Start is called before the first frame update
void Start()
{
_sunInitialIntensity = _sunLight.intensity;
_timer = _minuteToRealTime;
_currentTime = TimeSpan.Zero + TimeSpan.FromHours(_startHour);
_sunriseTime = TimeSpan.FromHours(_sunriseHour);
@@ -75,36 +77,23 @@ public class TimeManager : MonoBehaviour
private void RotateSun()
{
float sunLightRotation;
float intensityMultiplier = 1;
float timeofDay = (float)CurrentTime.TotalSeconds / 86400;
_sunLight.transform.localRotation = Quaternion.Euler((timeofDay * 360f) - 90, 170, 0);
if (_currentTime > _sunriseTime && _currentTime < _sunsetTime)
{
TimeSpan sunriseToSunsetDuration = CalculateTimeDifference(_sunriseTime, _sunsetTime);
TimeSpan timeSinceSunrise = CalculateTimeDifference(_sunriseTime, _currentTime);
double percentage = timeSinceSunrise.TotalMinutes / sunriseToSunsetDuration.TotalMinutes;
sunLightRotation = Mathf.Lerp(0, 180, (float)percentage);
if (timeofDay <= 0.25f)
intensityMultiplier = Mathf.Clamp01((timeofDay - 0.23f) * (1 / 0.02f));
if (timeofDay >= 0.73f)
intensityMultiplier = Mathf.Clamp01(1 - (timeofDay - 0.73f) * (1 / 0.02f));
}
else
{
TimeSpan nightDuration = CalculateTimeDifference(_sunsetTime, _sunriseTime);
TimeSpan timeSinceSunset = CalculateTimeDifference(_sunsetTime, _currentTime);
double percentage = timeSinceSunset.TotalMinutes / nightDuration.TotalMinutes;
sunLightRotation = Mathf.Lerp(180, 360, (float)percentage);
intensityMultiplier = 0;
}
_sunLight.transform.rotation = Quaternion.AngleAxis(sunLightRotation, Vector3.right);
_sunLight.intensity = _sunInitialIntensity * intensityMultiplier;
}
private void UpdateLightSettings()
{
float dotProduct = Vector3.Dot(_sunLight.transform.forward, Vector3.down);
_sunLight.intensity = Mathf.Lerp(0, _maxSunLightIntensity, _lightChangeCurve.Evaluate(dotProduct));
_moonLight.intensity = Mathf.Lerp(_maxMoonLightIntensity, 0, _lightChangeCurve.Evaluate(dotProduct));
RenderSettings.ambientLight = Color.Lerp(_nightAmbientLight, _dayAmbientLight, _lightChangeCurve.Evaluate(dotProduct));
}
private TimeSpan CalculateTimeDifference(TimeSpan from, TimeSpan to)
{
TimeSpan diff = to - from;