ColorGradingModel.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. using System;
  2. namespace UnityEngine.PostProcessing
  3. {
  4. [Serializable]
  5. public class ColorGradingModel : PostProcessingModel
  6. {
  7. public ColorGradingModel.Settings settings
  8. {
  9. get
  10. {
  11. return this.m_Settings;
  12. }
  13. set
  14. {
  15. this.m_Settings = value;
  16. this.OnValidate();
  17. }
  18. }
  19. public bool isDirty { get; internal set; }
  20. public RenderTexture bakedLut { get; internal set; }
  21. public override void Reset()
  22. {
  23. this.m_Settings = ColorGradingModel.Settings.defaultSettings;
  24. this.OnValidate();
  25. }
  26. public override void OnValidate()
  27. {
  28. this.isDirty = true;
  29. }
  30. [SerializeField]
  31. private ColorGradingModel.Settings m_Settings = ColorGradingModel.Settings.defaultSettings;
  32. public enum Tonemapper
  33. {
  34. None,
  35. ACES,
  36. Neutral
  37. }
  38. [Serializable]
  39. public struct TonemappingSettings
  40. {
  41. public static ColorGradingModel.TonemappingSettings defaultSettings
  42. {
  43. get
  44. {
  45. return new ColorGradingModel.TonemappingSettings
  46. {
  47. tonemapper = ColorGradingModel.Tonemapper.Neutral,
  48. neutralBlackIn = 0.02f,
  49. neutralWhiteIn = 10f,
  50. neutralBlackOut = 0f,
  51. neutralWhiteOut = 10f,
  52. neutralWhiteLevel = 5.3f,
  53. neutralWhiteClip = 10f
  54. };
  55. }
  56. }
  57. [Tooltip("Tonemapping algorithm to use at the end of the color grading process. Use \"Neutral\" if you need a customizable tonemapper or \"Filmic\" to give a standard filmic look to your scenes.")]
  58. public ColorGradingModel.Tonemapper tonemapper;
  59. [Range(-0.1f, 0.1f)]
  60. public float neutralBlackIn;
  61. [Range(1f, 20f)]
  62. public float neutralWhiteIn;
  63. [Range(-0.09f, 0.1f)]
  64. public float neutralBlackOut;
  65. [Range(1f, 19f)]
  66. public float neutralWhiteOut;
  67. [Range(0.1f, 20f)]
  68. public float neutralWhiteLevel;
  69. [Range(1f, 10f)]
  70. public float neutralWhiteClip;
  71. }
  72. [Serializable]
  73. public struct BasicSettings
  74. {
  75. public static ColorGradingModel.BasicSettings defaultSettings
  76. {
  77. get
  78. {
  79. return new ColorGradingModel.BasicSettings
  80. {
  81. postExposure = 0f,
  82. temperature = 0f,
  83. tint = 0f,
  84. hueShift = 0f,
  85. saturation = 1f,
  86. contrast = 1f
  87. };
  88. }
  89. }
  90. [Tooltip("Adjusts the overall exposure of the scene in EV units. This is applied after HDR effect and right before tonemapping so it won't affect previous effects in the chain.")]
  91. public float postExposure;
  92. [Range(-100f, 100f)]
  93. [Tooltip("Sets the white balance to a custom color temperature.")]
  94. public float temperature;
  95. [Range(-100f, 100f)]
  96. [Tooltip("Sets the white balance to compensate for a green or magenta tint.")]
  97. public float tint;
  98. [Range(-180f, 180f)]
  99. [Tooltip("Shift the hue of all colors.")]
  100. public float hueShift;
  101. [Range(0f, 2f)]
  102. [Tooltip("Pushes the intensity of all colors.")]
  103. public float saturation;
  104. [Range(0f, 2f)]
  105. [Tooltip("Expands or shrinks the overall range of tonal values.")]
  106. public float contrast;
  107. }
  108. [Serializable]
  109. public struct ChannelMixerSettings
  110. {
  111. public static ColorGradingModel.ChannelMixerSettings defaultSettings
  112. {
  113. get
  114. {
  115. return new ColorGradingModel.ChannelMixerSettings
  116. {
  117. red = new Vector3(1f, 0f, 0f),
  118. green = new Vector3(0f, 1f, 0f),
  119. blue = new Vector3(0f, 0f, 1f),
  120. currentEditingChannel = 0
  121. };
  122. }
  123. }
  124. public Vector3 red;
  125. public Vector3 green;
  126. public Vector3 blue;
  127. [HideInInspector]
  128. public int currentEditingChannel;
  129. }
  130. [Serializable]
  131. public struct LogWheelsSettings
  132. {
  133. public static ColorGradingModel.LogWheelsSettings defaultSettings
  134. {
  135. get
  136. {
  137. return new ColorGradingModel.LogWheelsSettings
  138. {
  139. slope = Color.clear,
  140. power = Color.clear,
  141. offset = Color.clear
  142. };
  143. }
  144. }
  145. [Trackball("GetSlopeValue")]
  146. public Color slope;
  147. [Trackball("GetPowerValue")]
  148. public Color power;
  149. [Trackball("GetOffsetValue")]
  150. public Color offset;
  151. }
  152. [Serializable]
  153. public struct LinearWheelsSettings
  154. {
  155. public static ColorGradingModel.LinearWheelsSettings defaultSettings
  156. {
  157. get
  158. {
  159. return new ColorGradingModel.LinearWheelsSettings
  160. {
  161. lift = Color.clear,
  162. gamma = Color.clear,
  163. gain = Color.clear
  164. };
  165. }
  166. }
  167. [Trackball("GetLiftValue")]
  168. public Color lift;
  169. [Trackball("GetGammaValue")]
  170. public Color gamma;
  171. [Trackball("GetGainValue")]
  172. public Color gain;
  173. }
  174. public enum ColorWheelMode
  175. {
  176. Linear,
  177. Log
  178. }
  179. [Serializable]
  180. public struct ColorWheelsSettings
  181. {
  182. public static ColorGradingModel.ColorWheelsSettings defaultSettings
  183. {
  184. get
  185. {
  186. return new ColorGradingModel.ColorWheelsSettings
  187. {
  188. mode = ColorGradingModel.ColorWheelMode.Log,
  189. log = ColorGradingModel.LogWheelsSettings.defaultSettings,
  190. linear = ColorGradingModel.LinearWheelsSettings.defaultSettings
  191. };
  192. }
  193. }
  194. public ColorGradingModel.ColorWheelMode mode;
  195. [TrackballGroup]
  196. public ColorGradingModel.LogWheelsSettings log;
  197. [TrackballGroup]
  198. public ColorGradingModel.LinearWheelsSettings linear;
  199. }
  200. [Serializable]
  201. public struct CurvesSettings
  202. {
  203. public static ColorGradingModel.CurvesSettings defaultSettings
  204. {
  205. get
  206. {
  207. return new ColorGradingModel.CurvesSettings
  208. {
  209. master = new ColorGradingCurve(new AnimationCurve(new Keyframe[]
  210. {
  211. new Keyframe(0f, 0f, 1f, 1f),
  212. new Keyframe(1f, 1f, 1f, 1f)
  213. }), 0f, false, new Vector2(0f, 1f)),
  214. red = new ColorGradingCurve(new AnimationCurve(new Keyframe[]
  215. {
  216. new Keyframe(0f, 0f, 1f, 1f),
  217. new Keyframe(1f, 1f, 1f, 1f)
  218. }), 0f, false, new Vector2(0f, 1f)),
  219. green = new ColorGradingCurve(new AnimationCurve(new Keyframe[]
  220. {
  221. new Keyframe(0f, 0f, 1f, 1f),
  222. new Keyframe(1f, 1f, 1f, 1f)
  223. }), 0f, false, new Vector2(0f, 1f)),
  224. blue = new ColorGradingCurve(new AnimationCurve(new Keyframe[]
  225. {
  226. new Keyframe(0f, 0f, 1f, 1f),
  227. new Keyframe(1f, 1f, 1f, 1f)
  228. }), 0f, false, new Vector2(0f, 1f)),
  229. hueVShue = new ColorGradingCurve(new AnimationCurve(), 0.5f, true, new Vector2(0f, 1f)),
  230. hueVSsat = new ColorGradingCurve(new AnimationCurve(), 0.5f, true, new Vector2(0f, 1f)),
  231. satVSsat = new ColorGradingCurve(new AnimationCurve(), 0.5f, false, new Vector2(0f, 1f)),
  232. lumVSsat = new ColorGradingCurve(new AnimationCurve(), 0.5f, false, new Vector2(0f, 1f)),
  233. e_CurrentEditingCurve = 0,
  234. e_CurveY = true,
  235. e_CurveR = false,
  236. e_CurveG = false,
  237. e_CurveB = false
  238. };
  239. }
  240. }
  241. public ColorGradingCurve master;
  242. public ColorGradingCurve red;
  243. public ColorGradingCurve green;
  244. public ColorGradingCurve blue;
  245. public ColorGradingCurve hueVShue;
  246. public ColorGradingCurve hueVSsat;
  247. public ColorGradingCurve satVSsat;
  248. public ColorGradingCurve lumVSsat;
  249. [HideInInspector]
  250. public int e_CurrentEditingCurve;
  251. [HideInInspector]
  252. public bool e_CurveY;
  253. [HideInInspector]
  254. public bool e_CurveR;
  255. [HideInInspector]
  256. public bool e_CurveG;
  257. [HideInInspector]
  258. public bool e_CurveB;
  259. }
  260. [Serializable]
  261. public struct Settings
  262. {
  263. public static ColorGradingModel.Settings defaultSettings
  264. {
  265. get
  266. {
  267. return new ColorGradingModel.Settings
  268. {
  269. tonemapping = ColorGradingModel.TonemappingSettings.defaultSettings,
  270. basic = ColorGradingModel.BasicSettings.defaultSettings,
  271. channelMixer = ColorGradingModel.ChannelMixerSettings.defaultSettings,
  272. colorWheels = ColorGradingModel.ColorWheelsSettings.defaultSettings,
  273. curves = ColorGradingModel.CurvesSettings.defaultSettings
  274. };
  275. }
  276. }
  277. public ColorGradingModel.TonemappingSettings tonemapping;
  278. public ColorGradingModel.BasicSettings basic;
  279. public ColorGradingModel.ChannelMixerSettings channelMixer;
  280. public ColorGradingModel.ColorWheelsSettings colorWheels;
  281. public ColorGradingModel.CurvesSettings curves;
  282. }
  283. }
  284. }