GlowSettings.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. //
  2. // Copyright (c) 2014-2017, THUNDERBEAST GAMES LLC All rights reserved
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include <Atomic/Math/MathDefs.h>
  24. #include <Atomic/Container/Str.h>
  25. #include <Atomic/IO/VectorBuffer.h>
  26. using namespace Atomic;
  27. namespace AtomicGlow
  28. {
  29. enum GlowPreset
  30. {
  31. GLOW_PRESET_FAST_LOW_QUALITY,
  32. GLOW_PRESET_MEDIUM_QUALITY,
  33. GLOW_PRESET_HIGH_QUALITY,
  34. GLOW_PRESET_SLOW_EXTREME_QUALITY
  35. };
  36. enum GlowOutputFormat
  37. {
  38. GLOW_OUTPUT_PNG,
  39. GLOW_OUTPUT_DDS
  40. };
  41. struct GlowSettings
  42. {
  43. int lightmapSize_;
  44. GlowOutputFormat outputFormat_;
  45. // global scalar
  46. float lexelDensity_;
  47. float sceneLexelDensityScale_;
  48. // global illumination
  49. bool giEnabled_;
  50. int giGranularity_;
  51. int giMaxBounces_;
  52. // ambient occlusion
  53. bool aoEnabled_;
  54. float aoDepth_;
  55. unsigned nsamples_;
  56. float aoMin_;
  57. float aoMultiply_;
  58. // NEW GI
  59. // Number of photon passes.
  60. int photonPassCount_;
  61. // Maximum photon tracing depth (number of light bounces).
  62. int photonBounceCount_;
  63. // The minimum energy that photon should have to continue tracing.
  64. float photonEnergyThreshold_;
  65. // The reflected light maximum distance. All intersections above this value will be ignored.
  66. float photonMaxDistance_;
  67. // Number of final gather samples.
  68. int finalGatherSamples_;
  69. // Maximum distance to gather photons at.
  70. float finalGatherDistance_;
  71. // A radius of circle in which samples are gathered from photon map.
  72. int finalGatherRadius_;
  73. GlowSettings()
  74. {
  75. SetDefaults();
  76. Validate();
  77. }
  78. void Pack(VectorBuffer& buffer) const
  79. {
  80. buffer.WriteInt(lightmapSize_);
  81. buffer.WriteUInt((unsigned) outputFormat_);
  82. buffer.WriteFloat(lexelDensity_);
  83. buffer.WriteFloat(sceneLexelDensityScale_);
  84. buffer.WriteBool(giEnabled_);
  85. buffer.WriteInt(giGranularity_);
  86. buffer.WriteInt(giMaxBounces_);
  87. buffer.WriteBool(aoEnabled_);
  88. buffer.WriteFloat(aoDepth_);
  89. buffer.WriteUInt(nsamples_);
  90. buffer.WriteFloat(aoDepth_);
  91. buffer.WriteFloat(aoMin_);
  92. buffer.WriteFloat(aoMultiply_);
  93. }
  94. void Unpack(VectorBuffer& buffer)
  95. {
  96. lightmapSize_ = buffer.ReadInt();
  97. outputFormat_ = (GlowOutputFormat) buffer.ReadUInt();
  98. lexelDensity_ = buffer.ReadFloat();
  99. sceneLexelDensityScale_ = buffer.ReadFloat();
  100. giEnabled_ = buffer.ReadBool();
  101. giGranularity_ = buffer.ReadInt();
  102. giMaxBounces_ = buffer.ReadInt();
  103. aoEnabled_ = buffer.ReadBool();
  104. aoDepth_ = buffer.ReadFloat();
  105. nsamples_ = buffer.ReadUInt( );
  106. aoDepth_= buffer.ReadFloat();
  107. aoMin_ = buffer.ReadFloat();
  108. aoMultiply_ = buffer.ReadFloat();
  109. }
  110. void Validate()
  111. {
  112. // always use 2048 for lightmap size
  113. lightmapSize_ = 2048;
  114. sceneLexelDensityScale_ = Atomic::Clamp<float>(sceneLexelDensityScale_, 0.01f, 1.0f);
  115. lexelDensity_ = Atomic::Clamp<float>(lexelDensity_, 0.01f, 1.0f);
  116. nsamples_ = Atomic::Clamp<unsigned>(nsamples_, 16, 256);
  117. giMaxBounces_ = Atomic::Clamp<int>(giMaxBounces_, 0, 8);
  118. giGranularity_ = Atomic::Clamp<int>(giGranularity_, 4, 16);
  119. aoDepth_ = Atomic::Clamp<float>(aoDepth_, 0.01f, 10.0f);
  120. aoMin_ = Atomic::Clamp<float>(aoMin_, 0.0f, 0.95f);
  121. aoMultiply_ = Atomic::Clamp<float>(aoMultiply_, 0.01f, 100.0f);
  122. }
  123. void SetDefaults(GlowPreset preset = GLOW_PRESET_FAST_LOW_QUALITY)
  124. {
  125. // common settings
  126. // lightmap size
  127. lightmapSize_ = 2048;
  128. giMaxBounces_ = 3;
  129. sceneLexelDensityScale_ = 0.35f;
  130. // TODO: Factor in DDS scene lighting loader, which have tested
  131. // and minimal artifacts with significant runtime memory savings
  132. outputFormat_ = GLOW_OUTPUT_PNG;
  133. aoEnabled_ = false;
  134. aoDepth_ = 0.25f;
  135. aoMin_ = 0.45f;
  136. aoMultiply_ = 1.0f;
  137. switch (preset)
  138. {
  139. case GLOW_PRESET_FAST_LOW_QUALITY:
  140. lexelDensity_ = 0.16f;
  141. nsamples_ = 16;
  142. photonPassCount_ = 64;
  143. photonBounceCount_ = 4;
  144. photonEnergyThreshold_ = 0.05f;
  145. photonMaxDistance_ = 10;
  146. finalGatherSamples_ = 1024;
  147. finalGatherDistance_ = 50;
  148. finalGatherRadius_ = 7;
  149. break;
  150. case GLOW_PRESET_MEDIUM_QUALITY:
  151. lexelDensity_ = 0.32f;
  152. nsamples_ = 64;
  153. giEnabled_ = true;
  154. giGranularity_ = 8;
  155. photonPassCount_ = 16;
  156. photonBounceCount_ = 3;
  157. photonEnergyThreshold_ = 0.05f;
  158. photonMaxDistance_ = 10;
  159. finalGatherSamples_ = 64;
  160. finalGatherDistance_ = 50;
  161. finalGatherRadius_ = 7;
  162. break;
  163. case GLOW_PRESET_HIGH_QUALITY:
  164. lexelDensity_ = 0.5f;
  165. giEnabled_ = true;
  166. nsamples_ = 256;
  167. giGranularity_ = 8;
  168. photonPassCount_ = 32;
  169. photonBounceCount_ = 3;
  170. photonEnergyThreshold_ = 0.05f;
  171. photonMaxDistance_ = 10;
  172. finalGatherSamples_ = 128;
  173. finalGatherDistance_ = 50;
  174. finalGatherRadius_ = 7;
  175. break;
  176. case GLOW_PRESET_SLOW_EXTREME_QUALITY:
  177. lexelDensity_ = 0.65f;
  178. nsamples_ = 256;
  179. giEnabled_ = true;
  180. giGranularity_ = 8;
  181. photonPassCount_ = 64;
  182. photonBounceCount_ = 4;
  183. photonEnergyThreshold_ = 0.05f;
  184. photonMaxDistance_ = 10;
  185. finalGatherSamples_ = 1024;
  186. finalGatherDistance_ = 50;
  187. finalGatherRadius_ = 7;
  188. break;
  189. }
  190. }
  191. };
  192. extern GlowSettings GlobalGlowSettings;
  193. }