diff options
author | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
commit | 6ce8b9e22fc13be34b442c7b6af48b42cd44275a (patch) | |
tree | b38119d2acf0a982cb67e381f146924b9bfc3b3f /DeepSky.Haze/DS_HazeContextItem.cs |
+init
Diffstat (limited to 'DeepSky.Haze/DS_HazeContextItem.cs')
-rw-r--r-- | DeepSky.Haze/DS_HazeContextItem.cs | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/DeepSky.Haze/DS_HazeContextItem.cs b/DeepSky.Haze/DS_HazeContextItem.cs new file mode 100644 index 0000000..d9208c9 --- /dev/null +++ b/DeepSky.Haze/DS_HazeContextItem.cs @@ -0,0 +1,173 @@ +using System; +using System.Reflection; +using UnityEngine; + +namespace DeepSky.Haze; + +[Serializable] +[AddComponentMenu("")] +public class DS_HazeContextItem +{ + public enum Multiplier + { + OneTenth, + OneFifth, + OneHalf, + One, + Two, + Five, + Ten, + OneHundredth + } + + [SerializeField] + public string m_Name; + + [SerializeField] + public AnimationCurve m_Weight; + + [SerializeField] + [Range(0f, 8f)] + public float m_AirScatteringScale = 1f; + + [SerializeField] + public Multiplier m_AirScatteringMultiplier = Multiplier.One; + + [SerializeField] + [Range(0.0001f, 0.1f)] + public float m_AirDensityHeightFalloff = 0.001f; + + [SerializeField] + [Range(0f, 8f)] + public float m_HazeScatteringScale = 1f; + + [SerializeField] + public Multiplier m_HazeScatteringMultiplier = Multiplier.One; + + [SerializeField] + [Range(0.0001f, 0.1f)] + public float m_HazeDensityHeightFalloff = 0.003f; + + [SerializeField] + [Range(-0.99f, 0.99f)] + public float m_HazeScatteringDirection = 0.8f; + + [SerializeField] + [Range(0f, 1f)] + public float m_HazeSecondaryScatteringRatio = 0.8f; + + [SerializeField] + [Range(0f, 1f)] + public float m_FogOpacity = 1f; + + [SerializeField] + [Range(0f, 8f)] + public float m_FogScatteringScale = 1f; + + [SerializeField] + [Range(0f, 8f)] + public float m_FogExtinctionScale = 1f; + + [SerializeField] + public Multiplier m_FogExtinctionMultiplier = Multiplier.One; + + [SerializeField] + [Range(0.0001f, 1f)] + public float m_FogDensityHeightFalloff = 0.01f; + + [SerializeField] + [Range(0f, 1f)] + public float m_FogStartDistance; + + [SerializeField] + [Range(-0.99f, 0.99f)] + public float m_FogScatteringDirection = 0.7f; + + [SerializeField] + [Range(-10000f, 10000f)] + public float m_FogStartHeight; + + [SerializeField] + public Color m_FogAmbientColour = Color.white; + + [SerializeField] + public Color m_FogLightColour = Color.white; + + public DS_HazeContextItem() + { + m_Name = "New"; + m_Weight = new AnimationCurve(new Keyframe(0.25f, 0f), new Keyframe(0.5f, 1f), new Keyframe(0.75f, 0f)); + } + + public static float MultiplierAsFloat(Multiplier mult) + { + return mult switch + { + Multiplier.OneTenth => 0.1f, + Multiplier.OneFifth => 0.2f, + Multiplier.OneHalf => 0.5f, + Multiplier.One => 1f, + Multiplier.Two => 2f, + Multiplier.Five => 5f, + Multiplier.Ten => 10f, + Multiplier.OneHundredth => 0.01f, + _ => 1f, + }; + } + + public static float ParamWithMultiplier(float param, Multiplier mult) + { + return mult switch + { + Multiplier.OneTenth => param * 0.1f, + Multiplier.OneFifth => param * 0.2f, + Multiplier.OneHalf => param * 0.5f, + Multiplier.One => param * 1f, + Multiplier.Two => param * 2f, + Multiplier.Five => param * 5f, + Multiplier.Ten => param * 10f, + Multiplier.OneHundredth => param * 0.01f, + _ => param * 1f, + }; + } + + public void Lerp(DS_HazeContextItem other, float dt) + { + if (other != null) + { + dt = Mathf.Clamp01(dt); + float num = 1f - dt; + m_AirScatteringScale = m_AirScatteringScale * num + other.m_AirScatteringScale * dt; + m_AirDensityHeightFalloff = m_AirDensityHeightFalloff * num + other.m_AirDensityHeightFalloff * dt; + m_HazeScatteringScale = m_HazeScatteringScale * num + other.m_HazeScatteringScale * dt; + m_HazeDensityHeightFalloff = m_HazeDensityHeightFalloff * num + other.m_HazeDensityHeightFalloff * dt; + m_HazeScatteringDirection = m_HazeScatteringDirection * num + other.m_HazeScatteringDirection * dt; + m_HazeSecondaryScatteringRatio = m_HazeSecondaryScatteringRatio * num + other.m_HazeSecondaryScatteringRatio * dt; + m_FogOpacity = m_FogOpacity * num + other.m_FogOpacity * dt; + m_FogScatteringScale = m_FogScatteringScale * num + other.m_FogScatteringScale * dt; + m_FogExtinctionScale = m_FogExtinctionScale * num + other.m_FogExtinctionScale * dt; + m_FogDensityHeightFalloff = m_FogDensityHeightFalloff * num + other.m_FogDensityHeightFalloff * dt; + m_FogStartDistance = m_FogStartDistance * num + other.m_FogStartDistance * dt; + m_FogScatteringDirection = m_FogScatteringDirection * num + other.m_FogScatteringDirection * dt; + m_FogStartHeight = m_FogStartHeight * num + other.m_FogStartHeight * dt; + m_FogAmbientColour = m_FogAmbientColour * num + other.m_FogAmbientColour * dt; + m_FogLightColour = m_FogLightColour * num + other.m_FogLightColour * dt; + } + } + + public void CopyFrom(DS_HazeContextItem other) + { + if (other != null) + { + Type type = GetType(); + Type type2 = other.GetType(); + FieldInfo[] fields = type.GetFields(); + foreach (FieldInfo fieldInfo in fields) + { + FieldInfo field = type2.GetField(fieldInfo.Name); + fieldInfo.SetValue(this, field.GetValue(other)); + } + m_Weight = new AnimationCurve(m_Weight.keys); + } + } +} |