ColorGradingModel.cs 9.8 KB

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