Ingen beskrivning
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Tonemapping.cs 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System;
  2. namespace UnityEngine.Rendering.Universal
  3. {
  4. /// <summary>
  5. /// Options to select a tonemapping algorithm to use for color grading.
  6. /// </summary>
  7. public enum TonemappingMode
  8. {
  9. /// <summary>
  10. /// Use this option if you do not want to apply tonemapping
  11. /// </summary>
  12. None,
  13. /// <summary>
  14. /// Use this option if you only want range-remapping with minimal impact on color hue and saturation.
  15. /// It is generally a great starting point for extensive color grading.
  16. /// </summary>
  17. Neutral, // Neutral tonemapper
  18. /// <summary>
  19. /// Use this option to apply a close approximation of the reference ACES tonemapper for a more filmic look.
  20. /// It is more contrasted than Neutral and has an effect on actual color hue and saturation.
  21. /// Note that if you use this tonemapper all the grading operations will be done in the ACES color spaces for optimal precision and results.
  22. /// </summary>
  23. ACES, // ACES Filmic reference tonemapper (custom approximation)
  24. }
  25. /// <summary>
  26. /// Available options for when HDR Output is enabled and Tonemap is set to Neutral.
  27. /// </summary>
  28. public enum NeutralRangeReductionMode
  29. {
  30. /// <summary>
  31. /// Simple Reinhard tonemapping curve.
  32. /// </summary>
  33. Reinhard = HDRRangeReduction.Reinhard,
  34. /// <summary>
  35. /// Range reduction curve as specified in the BT.2390 standard.
  36. /// </summary>
  37. BT2390 = HDRRangeReduction.BT2390
  38. }
  39. /// <summary>
  40. /// Preset used when selecting ACES tonemapping for HDR displays.
  41. /// </summary>
  42. public enum HDRACESPreset
  43. {
  44. /// <summary>
  45. /// Preset for a display with a maximum range of 1000 nits.
  46. /// </summary>
  47. ACES1000Nits = HDRRangeReduction.ACES1000Nits,
  48. /// <summary>
  49. /// Preset for a display with a maximum range of 2000 nits.
  50. /// </summary>
  51. ACES2000Nits = HDRRangeReduction.ACES2000Nits,
  52. /// <summary>
  53. /// Preset for a display with a maximum range of 4000 nits.
  54. /// </summary>
  55. ACES4000Nits = HDRRangeReduction.ACES4000Nits,
  56. }
  57. /// <summary>
  58. /// A volume component that holds settings for the tonemapping effect.
  59. /// </summary>
  60. [Serializable, VolumeComponentMenu("Post-processing/Tonemapping")]
  61. [SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
  62. [URPHelpURL("post-processing-tonemapping")]
  63. public sealed class Tonemapping : VolumeComponent, IPostProcessComponent
  64. {
  65. /// <summary>
  66. /// Use this to select a tonemapping algorithm to use for color grading.
  67. /// </summary>
  68. [Tooltip("Select a tonemapping algorithm to use for the color grading process.")]
  69. public TonemappingModeParameter mode = new TonemappingModeParameter(TonemappingMode.None);
  70. // -- HDR Output options --
  71. /// <summary>
  72. /// Specifies the range reduction mode used when HDR output is enabled and Neutral tonemapping is enabled.
  73. /// </summary>
  74. [AdditionalProperty]
  75. [Tooltip("Specifies the range reduction mode used when HDR output is enabled and Neutral tonemapping is enabled.")]
  76. public NeutralRangeReductionModeParameter neutralHDRRangeReductionMode = new NeutralRangeReductionModeParameter(NeutralRangeReductionMode.BT2390);
  77. /// <summary>
  78. /// Specifies the preset for HDR displays.
  79. /// </summary>
  80. [Tooltip("Use the ACES preset for HDR displays.")]
  81. public HDRACESPresetParameter acesPreset = new HDRACESPresetParameter(HDRACESPreset.ACES1000Nits);
  82. /// <summary>
  83. /// Specify how much hue to preserve. Values closer to 0 are likely to preserve hue. As values get closer to 1, Unity doesn't correct hue shifts.
  84. /// </summary>
  85. [Tooltip("Specify how much hue to preserve. Values closer to 0 are likely to preserve hue. As values get closer to 1, Unity doesn't correct hue shifts.")]
  86. public ClampedFloatParameter hueShiftAmount = new ClampedFloatParameter(0.0f, 0.0f, 1.0f);
  87. /// <summary>
  88. /// Enable to use values detected from the output device as paper white. When enabled, output images might differ between SDR and HDR. For best accuracy, set this value manually.
  89. /// </summary>
  90. [Tooltip("Enable to use values detected from the output device as paper white. When enabled, output images might differ between SDR and HDR. For best accuracy, set this value manually.")]
  91. public BoolParameter detectPaperWhite = new BoolParameter(false);
  92. /// <summary>
  93. /// The reference brightness of a paper white surface. This property determines the maximum brightness of UI. The brightness of the scene is scaled relative to this value. The value is in nits.
  94. /// </summary>
  95. [Tooltip("The reference brightness of a paper white surface. This property determines the maximum brightness of UI. The brightness of the scene is scaled relative to this value. The value is in nits.")]
  96. public ClampedFloatParameter paperWhite = new ClampedFloatParameter(300.0f, 0.0f, 400.0f);
  97. /// <summary>
  98. /// Enable to use the minimum and maximum brightness values detected from the output device. For best accuracy, considering calibrating these values manually.
  99. /// </summary>
  100. [Tooltip("Enable to use the minimum and maximum brightness values detected from the output device. For best accuracy, considering calibrating these values manually.")]
  101. public BoolParameter detectBrightnessLimits = new BoolParameter(true);
  102. /// <summary>
  103. /// The minimum brightness of the screen (in nits). This value is assumed to be 0.005f with ACES Tonemap.
  104. /// </summary>
  105. [Tooltip("The minimum brightness of the screen (in nits). This value is assumed to be 0.005f with ACES Tonemap.")]
  106. public ClampedFloatParameter minNits = new ClampedFloatParameter(0.005f, 0.0f, 50.0f);
  107. /// <summary>
  108. /// The maximum brightness of the screen (in nits). This value is defined by the preset when using ACES Tonemap.
  109. /// </summary>
  110. [Tooltip("The maximum brightness of the screen (in nits). This value is defined by the preset when using ACES Tonemap.")]
  111. public ClampedFloatParameter maxNits = new ClampedFloatParameter(1000.0f, 0.0f, 5000.0f);
  112. /// <inheritdoc/>
  113. public bool IsActive() => mode.value != TonemappingMode.None;
  114. /// <inheritdoc/>
  115. [Obsolete("Unused #from(2023.1)", false)]
  116. public bool IsTileCompatible() => true;
  117. }
  118. /// <summary>
  119. /// A <see cref="VolumeParameter"/> that holds a <see cref="TonemappingMode"/> value.
  120. /// </summary>
  121. [Serializable]
  122. public sealed class TonemappingModeParameter : VolumeParameter<TonemappingMode>
  123. {
  124. /// <summary>
  125. /// Creates a new <see cref="TonemappingModeParameter"/> instance.
  126. /// </summary>
  127. /// <param name="value">The initial value to store in the parameter.</param>
  128. /// <param name="overrideState">The initial override state for the parameter.</param>
  129. public TonemappingModeParameter(TonemappingMode value, bool overrideState = false) : base(value, overrideState) { }
  130. }
  131. /// <summary>
  132. /// A <see cref="VolumeParameter"/> that contains a <see cref="NeutralRangeReductionMode"/> value.
  133. /// </summary>
  134. [Serializable]
  135. public sealed class NeutralRangeReductionModeParameter : VolumeParameter<NeutralRangeReductionMode>
  136. {
  137. /// <summary>
  138. /// Creates a new <see cref="NeutralRangeReductionModeParameter"/> instance.
  139. /// </summary>
  140. /// <param name="value">The initial value to store in the parameter.</param>
  141. /// <param name="overrideState">The initial override state for the parameter.</param>
  142. public NeutralRangeReductionModeParameter(NeutralRangeReductionMode value, bool overrideState = false) : base(value, overrideState) { }
  143. }
  144. /// <summary>
  145. /// A <see cref="VolumeParameter"/> that contains a <see cref="HDRACESPreset"/> value.
  146. /// </summary>
  147. [Serializable]
  148. public sealed class HDRACESPresetParameter : VolumeParameter<HDRACESPreset>
  149. {
  150. /// <summary>
  151. /// Creates a new <see cref="HDRACESPresetParameter"/> instance.
  152. /// </summary>
  153. /// <param name="value">The initial value to store in the parameter.</param>
  154. /// <param name="overrideState">The initial override state for the parameter.</param>
  155. public HDRACESPresetParameter(HDRACESPreset value, bool overrideState = false) : base(value, overrideState) { }
  156. }
  157. }