summaryrefslogtreecommitdiff
path: root/DeepSky.Haze/DS_HazeContextItem.cs
blob: d9208c9bdc04c23fce23fecf03fa9d8cf929458e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
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);
		}
	}
}