BVB Source Codes

CRYENGINE Show EnvironmentPreset.cpp Source code

Return Download CRYENGINE: download EnvironmentPreset.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4.  
  5. #include <Cry3DEngine/ITimeOfDay.h>
  6. #include "EnvironmentPreset.h"
  7.  
  8. #include <CrySerialization/IArchive.h>
  9. #include <CrySerialization/IArchiveHost.h>
  10. #include <CrySerialization/ClassFactory.h>
  11. #include <CrySerialization/Enum.h>
  12. #include <CryMath/Bezier_impl.h>
  13.  
  14. namespace
  15. {
  16. static const unsigned int sCurrentPresetVersion = 2;
  17. static const float sAnimTimeSecondsIn24h = 24.0f;   // 24 hours = (sAnimTimeSecondsIn24h * SAnimTime::numTicksPerSecond) ticks
  18.  
  19. static const float sBezierSplineKeyValueEpsilon = 0.001f;
  20. }
  21.  
  22. CBezierSpline::CBezierSpline()
  23. {
  24.         m_keys.reserve(2);
  25. }
  26.  
  27. CBezierSpline::~CBezierSpline()
  28. {
  29.  
  30. }
  31.  
  32. void CBezierSpline::Init(float fDefaultValue)
  33. {
  34.         m_keys.clear();
  35.         InsertKey(SAnimTime(0.0f), fDefaultValue);
  36.         InsertKey(SAnimTime(sAnimTimeSecondsIn24h), fDefaultValue);
  37. }
  38.  
  39. float CBezierSpline::Evaluate(float t) const
  40. {
  41.         if (m_keys.size() == 0)
  42.                 return 0.0f;
  43.  
  44.         if (m_keys.size() == 1)
  45.                 return m_keys.front().m_controlPoint.m_value;
  46.  
  47.         const SAnimTime time(t);
  48.  
  49.         if (time <= m_keys.front().m_time)
  50.         {
  51.                 return m_keys.front().m_controlPoint.m_value;
  52.         }
  53.         else if (time >= m_keys.back().m_time)
  54.         {
  55.                 return m_keys.back().m_controlPoint.m_value;
  56.         }
  57.  
  58.         const TKeyContainer::const_iterator it = std::upper_bound(m_keys.begin(), m_keys.end(), time, SCompKeyTime());
  59.         const TKeyContainer::const_iterator startIt = it - 1;
  60.  
  61.         if (startIt->m_controlPoint.m_outTangentType == SBezierControlPoint::ETangentType::Step)
  62.         {
  63.                 return it->m_controlPoint.m_value;
  64.         }
  65.  
  66.         if (it->m_controlPoint.m_inTangentType == SBezierControlPoint::ETangentType::Step)
  67.         {
  68.                 return startIt->m_controlPoint.m_value;
  69.         }
  70.  
  71.         const SAnimTime deltaTime = it->m_time - startIt->m_time;
  72.  
  73.         if (deltaTime == SAnimTime(0))
  74.         {
  75.                 return startIt->m_controlPoint.m_value;
  76.         }
  77.  
  78.         const float timeInSegment = (time - startIt->m_time).ToFloat();
  79.  
  80.         const SBezierKey* pKeyLeftOfSegment = (startIt != m_keys.begin()) ? &*(startIt - 1) : NULL;
  81.         const SBezierKey* pKeyRightOfSegment = (startIt != (m_keys.end() - 2)) ? &*(startIt + 2) : NULL;
  82.         const SBezierKey segmentStart = Bezier::ApplyOutTangent(*startIt, pKeyLeftOfSegment, *(startIt + 1));
  83.         const SBezierKey segmentEnd = Bezier::ApplyInTangent(*(startIt + 1), *startIt, pKeyRightOfSegment);
  84.  
  85.         const float factor = Bezier::InterpolationFactorFromX(timeInSegment, deltaTime.ToFloat(), segmentStart.m_controlPoint, segmentEnd.m_controlPoint);
  86.         const float fResult = Bezier::EvaluateY(factor, segmentStart.m_controlPoint, segmentEnd.m_controlPoint);
  87.  
  88.         return fResult;
  89. }
  90.  
  91. void CBezierSpline::InsertKey(SAnimTime time, float value)
  92. {
  93.         SBezierKey key;
  94.         key.m_time = time;
  95.         key.m_controlPoint.m_value = value;
  96.  
  97.         const size_t nKeyNum = m_keys.size();
  98.         for (size_t i = 0; i < nKeyNum; ++i)
  99.         {
  100.                 if (m_keys[i].m_time > time)
  101.                 {
  102.                         m_keys.insert(m_keys.begin() + i, key);
  103.                         return;
  104.                 }
  105.         }
  106.  
  107.         m_keys.push_back(key);
  108. }
  109.  
  110. void CBezierSpline::UpdateKeyForTime(float fTime, float value)
  111. {
  112.         const SAnimTime time(fTime);
  113.  
  114.         const size_t nKeyNum = m_keys.size();
  115.         for (size_t i = 0; i < nKeyNum; ++i)
  116.         {
  117.                 if (fabs(m_keys[i].m_time.ToFloat() - fTime) < sBezierSplineKeyValueEpsilon)
  118.                 {
  119.                         m_keys[i].m_controlPoint.m_value = value;
  120.                         return;
  121.                 }
  122.         }
  123.  
  124.         InsertKey(time, value);
  125. }
  126.  
  127. void CBezierSpline::Serialize(Serialization::IArchive& ar)
  128. {
  129.         ar(m_keys, "keys");
  130. }
  131.  
  132. //////////////////////////////////////////////////////////////////////////
  133.  
  134. CTimeOfDayVariable::CTimeOfDayVariable() : m_id(ITimeOfDay::PARAM_TOTAL), m_type(ITimeOfDay::TYPE_FLOAT),
  135.         m_name(NULL), m_displayName(NULL), m_group(NULL),
  136.         m_minValue(0.0f), m_maxValue(0.0f), m_value(ZERO)
  137. {
  138.  
  139. }
  140.  
  141. CTimeOfDayVariable::~CTimeOfDayVariable()
  142. {
  143.  
  144. }
  145.  
  146. void CTimeOfDayVariable::Init(const char* group, const char* displayName, const char* name, ITimeOfDay::ETimeOfDayParamID nParamId, ITimeOfDay::EVariableType type, float defVal0, float defVal1, float defVal2)
  147. {
  148.         m_id = nParamId;
  149.         m_type = type;
  150.         m_name = name;
  151.         m_displayName = (displayName && *displayName) ? displayName : name;
  152.         m_group = (group && *group) ? group : "Default";
  153.  
  154.         if (ITimeOfDay::TYPE_FLOAT == type)
  155.         {
  156.                 m_value.x = defVal0;
  157.                 m_minValue = defVal1;
  158.                 m_maxValue = defVal2;
  159.                 m_spline[0].Init(defVal0);
  160.         }
  161.         else if (ITimeOfDay::TYPE_COLOR == type)
  162.         {
  163.                 m_value.x = defVal0;
  164.                 m_value.y = defVal1;
  165.                 m_value.z = defVal2;
  166.  
  167.                 m_minValue = 0.0f;
  168.                 m_maxValue = 1.0f;
  169.  
  170.                 m_spline[0].Init(defVal0);
  171.                 m_spline[1].Init(defVal1);
  172.                 m_spline[2].Init(defVal2);
  173.         }
  174. }
  175.  
  176. void CTimeOfDayVariable::Update(float time)
  177. {
  178.         m_value = GetInterpolatedAt(time);
  179. }
  180.  
  181. Vec3 CTimeOfDayVariable::GetInterpolatedAt(float t) const
  182. {
  183.         Vec3 result;
  184.         result.x = clamp_tpl(m_spline[0].Evaluate(t), m_minValue, m_maxValue);
  185.         result.y = clamp_tpl(m_spline[1].Evaluate(t), m_minValue, m_maxValue);
  186.         result.z = clamp_tpl(m_spline[2].Evaluate(t), m_minValue, m_maxValue);
  187.         return result;
  188. }
  189.  
  190. size_t CTimeOfDayVariable::GetSplineKeyCount(int nSpline) const
  191. {
  192.         if (const CBezierSpline* pSpline = GetSpline(nSpline))
  193.                 return pSpline->GetKeyCount();
  194.  
  195.         return 0;
  196. }
  197.  
  198. bool CTimeOfDayVariable::GetSplineKeys(int nSpline, SBezierKey* keysArray, unsigned int keysArraySize) const
  199. {
  200.         if (const CBezierSpline* pSpline = GetSpline(nSpline))
  201.         {
  202.                 if (keysArraySize < pSpline->GetKeyCount())
  203.                         return false;
  204.  
  205.                 pSpline->GetKeys(keysArray);
  206.                 return true;
  207.         }
  208.  
  209.         return false;
  210. }
  211.  
  212. bool CTimeOfDayVariable::SetSplineKeys(int nSpline, const SBezierKey* keysArray, unsigned int keysArraySize)
  213. {
  214.         if (CBezierSpline* pSpline = GetSpline(nSpline))
  215.         {
  216.                 pSpline->SetKeys(keysArray, keysArraySize);
  217.                 return true;
  218.         }
  219.         return false;
  220. }
  221.  
  222. bool CTimeOfDayVariable::UpdateSplineKeyForTime(int nSpline, float fTime, float newKey)
  223. {
  224.         if (CBezierSpline* pSpline = GetSpline(nSpline))
  225.         {
  226.                 pSpline->UpdateKeyForTime(fTime, newKey);
  227.                 return true;
  228.         }
  229.         return false;
  230. }
  231.  
  232. void CTimeOfDayVariable::Serialize(Serialization::IArchive& ar)
  233. {
  234.         ar(m_id, "id");
  235.         ar(m_type, "type");
  236.  
  237.         ar(m_minValue, "minValue");
  238.         ar(m_maxValue, "maxValue");
  239.  
  240.         ar(m_spline[0], "spline0");
  241.         ar(m_spline[1], "spline1");
  242.         ar(m_spline[2], "spline2");
  243. }
  244.  
  245. //////////////////////////////////////////////////////////////////////////
  246.  
  247. CEnvironmentPreset::CEnvironmentPreset()
  248. {
  249.         ResetVariables();
  250. }
  251.  
  252. CEnvironmentPreset::~CEnvironmentPreset()
  253. {
  254.  
  255. }
  256.  
  257. void CEnvironmentPreset::ResetVariables()
  258. {
  259.         const float fRecip255 = 1.0f / 255.0f;
  260.  
  261.         AddVar("Sun", "", "Sun color", ITimeOfDay::PARAM_SUN_COLOR, ITimeOfDay::TYPE_COLOR, 255.0f * fRecip255, 248.0f * fRecip255, 248.0f * fRecip255);
  262.         AddVar("Sun", "Sun intensity (lux)", "Sun intensity", ITimeOfDay::PARAM_SUN_INTENSITY, ITimeOfDay::TYPE_FLOAT, 119000.0f, 0.0f, 550000.0f);
  263.         AddVar("Sun", "", "Sun specular multiplier", ITimeOfDay::PARAM_SUN_SPECULAR_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 4.0f);
  264.  
  265.         AddVar("Fog", "Color (bottom)", "Fog color", ITimeOfDay::PARAM_FOG_COLOR, ITimeOfDay::TYPE_COLOR, 0.0f, 0.0f, 0.0f);
  266.         AddVar("Fog", "Color (bottom) multiplier", "Fog color multiplier", ITimeOfDay::PARAM_FOG_COLOR_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 0.0f, 0.0f, 16.0f);
  267.         AddVar("Fog", "Height (bottom)", "Fog height (bottom)", ITimeOfDay::PARAM_VOLFOG_HEIGHT, ITimeOfDay::TYPE_FLOAT, 0.0f, -5000.0f, 30000.0f);
  268.         AddVar("Fog", "Density (bottom)", "Fog layer density (bottom)", ITimeOfDay::PARAM_VOLFOG_DENSITY, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 1.0f);
  269.         AddVar("Fog", "Color (top)", "Fog color (top)", ITimeOfDay::PARAM_FOG_COLOR2, ITimeOfDay::TYPE_COLOR, 0.0f, 0.0f, 0.0f);
  270.         AddVar("Fog", "Color (top) multiplier", "Fog color (top) multiplier", ITimeOfDay::PARAM_FOG_COLOR2_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 0.0f, 0.0f, 16.0f);
  271.         AddVar("Fog", "Height (top)", "Fog height (top)", ITimeOfDay::PARAM_VOLFOG_HEIGHT2, ITimeOfDay::TYPE_FLOAT, 4000.0f, -5000.0f, 30000.0f);
  272.         AddVar("Fog", "Density (top)", "Fog layer density (top)", ITimeOfDay::PARAM_VOLFOG_DENSITY2, ITimeOfDay::TYPE_FLOAT, 0.0f, 0.0f, 1.0f);
  273.         AddVar("Fog", "Color height offset", "Fog color height offset", ITimeOfDay::PARAM_VOLFOG_HEIGHT_OFFSET, ITimeOfDay::TYPE_FLOAT, 0.0f, -1.0f, 1.0f);
  274.  
  275.         AddVar("Fog", "Color (radial)", "Fog color (radial)", ITimeOfDay::PARAM_FOG_RADIAL_COLOR, ITimeOfDay::TYPE_COLOR, 0.0f, 0.0f, 0.0f);
  276.         AddVar("Fog", "Color (radial) multiplier", "Fog color (radial) multiplier", ITimeOfDay::PARAM_FOG_RADIAL_COLOR_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 0.0f, 0.0f, 16.0f);
  277.         AddVar("Fog", "Radial size", "Fog radial size", ITimeOfDay::PARAM_VOLFOG_RADIAL_SIZE, ITimeOfDay::TYPE_FLOAT, 0.75f, 0.0f, 1.0f);
  278.         AddVar("Fog", "Radial lobe", "Fog radial lobe", ITimeOfDay::PARAM_VOLFOG_RADIAL_LOBE, ITimeOfDay::TYPE_FLOAT, 0.5f, 0.0f, 1.0f);
  279.  
  280.         AddVar("Fog", "Global density", "Volumetric fog: Global density", ITimeOfDay::PARAM_VOLFOG_GLOBAL_DENSITY, ITimeOfDay::TYPE_FLOAT, 0.02f, 0.0f, 100.0f);
  281.         AddVar("Fog", "Final density clamp", "Volumetric fog: Final density clamp", ITimeOfDay::PARAM_VOLFOG_FINAL_DENSITY_CLAMP, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 1.0f);
  282.  
  283.         AddVar("Fog", "Ramp start", "Volumetric fog: Ramp start", ITimeOfDay::PARAM_VOLFOG_RAMP_START, ITimeOfDay::TYPE_FLOAT, 0.0f, 0.0f, 30000.0f);
  284.         AddVar("Fog", "Ramp end", "Volumetric fog: Ramp end", ITimeOfDay::PARAM_VOLFOG_RAMP_END, ITimeOfDay::TYPE_FLOAT, 100.0f, 0.0f, 30000.0f);
  285.         AddVar("Fog", "Ramp influence", "Volumetric fog: Ramp influence", ITimeOfDay::PARAM_VOLFOG_RAMP_INFLUENCE, ITimeOfDay::TYPE_FLOAT, 0.0f, 0.0f, 1.0f);
  286.  
  287.         AddVar("Fog", "Shadow darkening", "Volumetric fog: Shadow darkening", ITimeOfDay::PARAM_VOLFOG_SHADOW_DARKENING, ITimeOfDay::TYPE_FLOAT, 0.25f, 0.0f, 1.0f);
  288.         AddVar("Fog", "Shadow darkening sun", "Volumetric fog: Shadow darkening sun", ITimeOfDay::PARAM_VOLFOG_SHADOW_DARKENING_SUN, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 1.0f);
  289.         AddVar("Fog", "Shadow darkening ambient", "Volumetric fog: Shadow darkening ambient", ITimeOfDay::PARAM_VOLFOG_SHADOW_DARKENING_AMBIENT, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 1.0f);
  290.         AddVar("Fog", "Shadow range", "Volumetric fog: Shadow range", ITimeOfDay::PARAM_VOLFOG_SHADOW_RANGE, ITimeOfDay::TYPE_FLOAT, 0.1f, 0.0f, 1.0f);
  291.  
  292.         AddVar("Volumetric fog", "Height (bottom)", "Volumetric fog 2: Fog height (bottom)", ITimeOfDay::PARAM_VOLFOG2_HEIGHT, ITimeOfDay::TYPE_FLOAT, 0.0f, -5000.0f, 30000.0f);
  293.         AddVar("Volumetric fog", "Density (bottom)", "Volumetric fog 2: Fog layer density (bottom)", ITimeOfDay::PARAM_VOLFOG2_DENSITY, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 1.0f);
  294.         AddVar("Volumetric fog", "Height (top)", "Volumetric fog 2: Fog height (top)", ITimeOfDay::PARAM_VOLFOG2_HEIGHT2, ITimeOfDay::TYPE_FLOAT, 4000.0f, -5000.0f, 30000.0f);
  295.         AddVar("Volumetric fog", "Density (top)", "Volumetric fog 2: Fog layer density (top)", ITimeOfDay::PARAM_VOLFOG2_DENSITY2, ITimeOfDay::TYPE_FLOAT, 0.0001f, 0.0f, 1.0f);
  296.         AddVar("Volumetric fog", "Global density", "Volumetric fog 2: Global fog density", ITimeOfDay::PARAM_VOLFOG2_GLOBAL_DENSITY, ITimeOfDay::TYPE_FLOAT, 0.1f, 0.0f, 100.0f);
  297.         AddVar("Volumetric fog", "Ramp start", "Volumetric fog 2: Ramp start", ITimeOfDay::PARAM_VOLFOG2_RAMP_START, ITimeOfDay::TYPE_FLOAT, 0.0f, 0.0f, 30000.0f);
  298.         AddVar("Volumetric fog", "Ramp end", "Volumetric fog 2: Ramp end", ITimeOfDay::PARAM_VOLFOG2_RAMP_END, ITimeOfDay::TYPE_FLOAT, 0.0f, 0.0f, 30000.0f);
  299.         AddVar("Volumetric fog", "Color (atmosphere)", "Volumetric fog 2: Fog albedo color (atmosphere)", ITimeOfDay::PARAM_VOLFOG2_COLOR1, ITimeOfDay::TYPE_COLOR, 1.0f, 1.0f, 1.0f);
  300.         AddVar("Volumetric fog", "Anisotropy (atmosphere)", "Volumetric fog 2: Anisotropy factor (atmosphere)", ITimeOfDay::PARAM_VOLFOG2_ANISOTROPIC1, ITimeOfDay::TYPE_FLOAT, 0.2f, -1.0f, 1.0f);
  301.         AddVar("Volumetric fog", "Color (sun radial)", "Volumetric fog 2: Fog albedo color (sun radial)", ITimeOfDay::PARAM_VOLFOG2_COLOR2, ITimeOfDay::TYPE_COLOR, 1.0f, 1.0f, 1.0f);
  302.         AddVar("Volumetric fog", "Anisotropy (sun radial)", "Volumetric fog 2: Anisotropy factor (sun radial)", ITimeOfDay::PARAM_VOLFOG2_ANISOTROPIC2, ITimeOfDay::TYPE_FLOAT, 0.95f, -1.0f, 1.0f);
  303.         AddVar("Volumetric fog", "Radial blend factor", "Volumetric fog 2: Blend factor for sun scattering", ITimeOfDay::PARAM_VOLFOG2_BLEND_FACTOR, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 1.0f);
  304.         AddVar("Volumetric fog", "Radial blend mode", "Volumetric fog 2: Blend mode for sun scattering", ITimeOfDay::PARAM_VOLFOG2_BLEND_MODE, ITimeOfDay::TYPE_FLOAT, 0.0f, 0.0f, 1.0f);
  305.         AddVar("Volumetric fog", "Range", "Volumetric fog 2: Maximum range of ray-marching", ITimeOfDay::PARAM_VOLFOG2_RANGE, ITimeOfDay::TYPE_FLOAT, 64.0f, 0.0f, 8192.0f);
  306.         AddVar("Volumetric fog", "In-scattering", "Volumetric fog 2: In-scattering factor", ITimeOfDay::PARAM_VOLFOG2_INSCATTER, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 100.0f);
  307.         AddVar("Volumetric fog", "Extinction", "Volumetric fog 2: Extinction factor", ITimeOfDay::PARAM_VOLFOG2_EXTINCTION, ITimeOfDay::TYPE_FLOAT, 0.3f, 0.0f, 100.0f);
  308.         AddVar("Volumetric fog", "Color (entities)", "Volumetric fog 2: Fog albedo color (entities)", ITimeOfDay::PARAM_VOLFOG2_COLOR, ITimeOfDay::TYPE_COLOR, 1.0f, 1.0f, 1.0f);
  309.         AddVar("Volumetric fog", "Anisotropy (entities)", "Volumetric fog 2: Anisotropy factor (entities)", ITimeOfDay::PARAM_VOLFOG2_ANISOTROPIC, ITimeOfDay::TYPE_FLOAT, 0.6f, -1.0f, 1.0f);
  310.         AddVar("Volumetric fog", "Analytical fog visibility", "Volumetric fog 2: Analytical volumetric fog visibility", ITimeOfDay::PARAM_VOLFOG2_GLOBAL_FOG_VISIBILITY, ITimeOfDay::TYPE_FLOAT, 0.5f, 0.0f, 1.0f);
  311.         AddVar("Volumetric fog", "Final density clamp", "Volumetric fog 2: Final density clamp", ITimeOfDay::PARAM_VOLFOG2_FINAL_DENSITY_CLAMP, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 1.0f);
  312.  
  313.         AddVar("Sky Light", "Sun intensity", "Sky light: Sun intensity", ITimeOfDay::PARAM_SKYLIGHT_SUN_INTENSITY, ITimeOfDay::TYPE_COLOR, 1.0f, 1.0f, 1.0f);
  314.         AddVar("Sky Light", "Sun intensity multiplier", "Sky light: Sun intensity multiplier", ITimeOfDay::PARAM_SKYLIGHT_SUN_INTENSITY_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 50.0f, 0.0f, 1000.0f);
  315.         AddVar("Sky Light", "Mie scattering", "Sky light: Mie scattering", ITimeOfDay::PARAM_SKYLIGHT_KM, ITimeOfDay::TYPE_FLOAT, 4.8f, 0.0f, 1000.0f);
  316.         AddVar("Sky Light", "Rayleigh scattering", "Sky light: Rayleigh scattering", ITimeOfDay::PARAM_SKYLIGHT_KR, ITimeOfDay::TYPE_FLOAT, 2.0f, 0.0f, 1000.0f);
  317.         AddVar("Sky Light", "Sun anisotropy factor", "Sky light: Sun anisotropy factor", ITimeOfDay::PARAM_SKYLIGHT_G, ITimeOfDay::TYPE_FLOAT, -0.997f, -0.9999f, 0.9999f);
  318.         AddVar("Sky Light", "Wavelength (R)", "Sky light: Wavelength (R)", ITimeOfDay::PARAM_SKYLIGHT_WAVELENGTH_R, ITimeOfDay::TYPE_FLOAT, 694.0f, 380.0f, 780.0f);
  319.         AddVar("Sky Light", "Wavelength (G)", "Sky light: Wavelength (G)", ITimeOfDay::PARAM_SKYLIGHT_WAVELENGTH_G, ITimeOfDay::TYPE_FLOAT, 597.0f, 380.0f, 780.0f);
  320.         AddVar("Sky Light", "Wavelength (B)", "Sky light: Wavelength (B)", ITimeOfDay::PARAM_SKYLIGHT_WAVELENGTH_B, ITimeOfDay::TYPE_FLOAT, 488.0f, 380.0f, 780.0f);
  321.  
  322.         AddVar("Night Sky", "Horizon color", "Night sky: Horizon color", ITimeOfDay::PARAM_NIGHSKY_HORIZON_COLOR, ITimeOfDay::TYPE_COLOR, 222.0f * fRecip255, 148.0f * fRecip255, 47.0f * fRecip255);
  323.         AddVar("Night Sky", "Zenith color", "Night sky: Zenith color", ITimeOfDay::PARAM_NIGHSKY_ZENITH_COLOR, ITimeOfDay::TYPE_COLOR, 17.0f * fRecip255, 38.0f * fRecip255, 78.0f * fRecip255);
  324.         AddVar("Night Sky", "Zenith shift", "Night sky: Zenith shift", ITimeOfDay::PARAM_NIGHSKY_ZENITH_SHIFT, ITimeOfDay::TYPE_FLOAT, 0.25f, 0.0f, 16.0f);
  325.         AddVar("Night Sky", "Star intensity", "Night sky: Star intensity", ITimeOfDay::PARAM_NIGHSKY_START_INTENSITY, ITimeOfDay::TYPE_FLOAT, 0.01f, 0.0f, 16.0f);
  326.         AddVar("Night Sky", "Moon color", "Night sky: Moon color", ITimeOfDay::PARAM_NIGHSKY_MOON_COLOR, ITimeOfDay::TYPE_COLOR, 255.0f * fRecip255, 255.0f * fRecip255, 255.0f * fRecip255);
  327.         AddVar("Night Sky", "Moon inner corona color", "Night sky: Moon inner corona color", ITimeOfDay::PARAM_NIGHSKY_MOON_INNERCORONA_COLOR, ITimeOfDay::TYPE_COLOR, 230.0f * fRecip255, 255.0f * fRecip255, 255.0f * fRecip255);
  328.         AddVar("Night Sky", "Moon inner corona scale", "Night sky: Moon inner corona scale", ITimeOfDay::PARAM_NIGHSKY_MOON_INNERCORONA_SCALE, ITimeOfDay::TYPE_FLOAT, 0.499f, 0.0f, 2.0f);
  329.         AddVar("Night Sky", "Moon outer corona color", "Night sky: Moon outer corona color", ITimeOfDay::PARAM_NIGHSKY_MOON_OUTERCORONA_COLOR, ITimeOfDay::TYPE_COLOR, 128.0f * fRecip255, 200.0f * fRecip255, 255.0f * fRecip255);
  330.         AddVar("Night Sky", "Moon outer corona scale", "Night sky: Moon outer corona scale", ITimeOfDay::PARAM_NIGHSKY_MOON_OUTERCORONA_SCALE, ITimeOfDay::TYPE_FLOAT, 0.006f, 0.0f, 2.0f);
  331.  
  332.         AddVar("Night Sky Multiplier", "Horizon color", "Night sky: Horizon color multiplier", ITimeOfDay::PARAM_NIGHSKY_HORIZON_COLOR_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 0.0001f, 0.0f, 0.1f);
  333.         AddVar("Night Sky Multiplier", "Zenith color", "Night sky: Zenith color multiplier", ITimeOfDay::PARAM_NIGHSKY_ZENITH_COLOR_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 0.00002f, 0.0f, 0.1f);
  334.         AddVar("Night Sky Multiplier", "Moon color", "Night sky: Moon color multiplier", ITimeOfDay::PARAM_NIGHSKY_MOON_COLOR_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 0.01f, 0.0f, 0.1f);
  335.         AddVar("Night Sky Multiplier", "Moon inner corona color", "Night sky: Moon inner corona color multiplier", ITimeOfDay::PARAM_NIGHSKY_MOON_INNERCORONA_COLOR_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 0.0001f, 0.0f, 0.1f);
  336.         AddVar("Night Sky Multiplier", "Moon outer corona color", "Night sky: Moon outer corona color multiplier", ITimeOfDay::PARAM_NIGHSKY_MOON_OUTERCORONA_COLOR_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 0.00005f, 0.0f, 0.1f);
  337.  
  338.         AddVar("Cloud Shading", "Sun contribution", "Cloud shading: Sun light multiplier", ITimeOfDay::PARAM_CLOUDSHADING_SUNLIGHT_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 1.96f, 0.0f, 16.0f);
  339.         AddVar("Cloud Shading", "Sky contribution", "Cloud shading: Sky light multiplier", ITimeOfDay::PARAM_CLOUDSHADING_SKYLIGHT_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 0.8f, 0.0f, 16.0f);
  340.         AddVar("Cloud Shading", "Sun custom color", "Cloud shading: Sun custom color", ITimeOfDay::PARAM_CLOUDSHADING_SUNLIGHT_CUSTOM_COLOR, ITimeOfDay::TYPE_COLOR, 215.0f * fRecip255, 200.0f * fRecip255, 170.0f * fRecip255);
  341.         AddVar("Cloud Shading", "Sun custom color multiplier", "Cloud shading: Sun custom color multiplier", ITimeOfDay::PARAM_CLOUDSHADING_SUNLIGHT_CUSTOM_COLOR_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 16.0f);
  342.         AddVar("Cloud Shading", "Sun custom color influence", "Cloud shading: Sun custom color influence", ITimeOfDay::PARAM_CLOUDSHADING_SUNLIGHT_CUSTOM_COLOR_INFLUENCE, ITimeOfDay::TYPE_FLOAT, 0.0f, 0.0f, 1.0f);
  343.  
  344.         AddVar("Volumetric Clouds", "Global cloudiness", "Volumetric clouds: Global cloudiness", ITimeOfDay::PARAM_VOLCLOUD_GLOBAL_DENSITY, ITimeOfDay::TYPE_FLOAT, 0.5f, 0.0f, 1.0f);
  345.         AddVar("Volumetric Clouds", "Clouds altitude", "Volumetric clouds: Clouds altitude", ITimeOfDay::PARAM_VOLCLOUD_HEIGHT, ITimeOfDay::TYPE_FLOAT, 1000.f, -4000.0f, 4000.0f);
  346.         AddVar("Volumetric Clouds", "Clouds thickness", "Volumetric clouds: Clouds thickness", ITimeOfDay::PARAM_VOLCLOUD_THICKNESS, ITimeOfDay::TYPE_FLOAT, 1500.f, 0.0f, 8000.0f);
  347.         AddVar("Volumetric Clouds", "Clouds edge turbulence", "Volumetric clouds: Clouds edge turbulence", ITimeOfDay::PARAM_VOLCLOUD_CLOUD_EDGE_TURBULENCE, ITimeOfDay::TYPE_FLOAT, 0.4f, 0.0f, 1.0f);
  348.         AddVar("Volumetric Clouds", "Clouds edge threshold", "Volumetric clouds: Clouds edge threshold", ITimeOfDay::PARAM_VOLCLOUD_CLOUD_EDGE_THRESHOLD, ITimeOfDay::TYPE_FLOAT, 0.3f, 0.0f, 1.0f);
  349.         AddVar("Volumetric Clouds", "Sun single scattering multiplier", "Volumetric clouds: Sun single scattering multiplier", ITimeOfDay::PARAM_VOLCLOUD_SUN_SINGLE_SCATTERING, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 10.0f);
  350.         AddVar("Volumetric Clouds", "Sun low-order scattering multiplier", "Volumetric clouds: Sun low-order scattering multiplier", ITimeOfDay::PARAM_VOLCLOUD_SUN_LOW_ORDER_SCATTERING, ITimeOfDay::TYPE_FLOAT, 2.0f, 0.0f, 10.0f);
  351.         AddVar("Volumetric Clouds", "Sun low-order scattering anisotropy", "Volumetric clouds: Sun low-order scattering anisotropy", ITimeOfDay::PARAM_VOLCLOUD_SUN_LOW_ORDER_SCATTERING_ANISTROPY, ITimeOfDay::TYPE_FLOAT, 0.2f, 0.0f, 0.999999f);
  352.         AddVar("Volumetric Clouds", "Sun high-order scattering multiplier", "Volumetric clouds: Sun high-order scattering multiplier", ITimeOfDay::PARAM_VOLCLOUD_SUN_HIGH_ORDER_SCATTERING, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 10.0f);
  353.         AddVar("Volumetric Clouds", "Sky lighting multiplier", "Volumetric clouds: Sky lighting multiplier", ITimeOfDay::PARAM_VOLCLOUD_SKY_LIGHTING_SCATTERING, ITimeOfDay::TYPE_FLOAT, 4.0f, 0.0f, 20.0f);
  354.         AddVar("Volumetric Clouds", "Ground lighting multiplier", "Volumetric clouds: Ground lighting multiplier", ITimeOfDay::PARAM_VOLCLOUD_GOUND_LIGHTING_SCATTERING, ITimeOfDay::TYPE_FLOAT, 2.0f, 0.0f, 20.0f);
  355.         AddVar("Volumetric Clouds", "Ground albedo", "Volumetric clouds: Ground albedo", ITimeOfDay::PARAM_VOLCLOUD_GROUND_LIGHTING_ALBEDO, ITimeOfDay::TYPE_COLOR, 0.19f, 0.2f, 0.15f);
  356.         AddVar("Volumetric Clouds", "Multi-scattering attenuation", "Volumetric clouds: Multi-scattering attenuation", ITimeOfDay::PARAM_VOLCLOUD_MULTI_SCATTERING_ATTENUATION, ITimeOfDay::TYPE_FLOAT, 8.0f, 0.0f, 40.0f);
  357.         AddVar("Volumetric Clouds", "Multi-scattering preservation", "Volumetric clouds: Multi-scattering preservation", ITimeOfDay::PARAM_VOLCLOUD_MULTI_SCATTERING_PRESERVATION, ITimeOfDay::TYPE_FLOAT, 0.4f, 0.0f, 1.0f);
  358.         AddVar("Volumetric Clouds", "Powder shading effect", "Volumetric clouds: Powder shading effect", ITimeOfDay::PARAM_VOLCLOUD_POWDER_EFFECT, ITimeOfDay::TYPE_FLOAT, 6.0f, 0.0f, 20.0f);
  359.         AddVar("Volumetric Clouds", "Absorption percentage", "Volumetric clouds: Absorption percentage", ITimeOfDay::PARAM_VOLCLOUD_ABSORPTION, ITimeOfDay::TYPE_FLOAT, 0.01f, 0.0f, 4.0f);
  360.         AddVar("Volumetric Clouds", "Atmospheric albedo", "Volumetric clouds: Atmospheric albedo", ITimeOfDay::PARAM_VOLCLOUD_ATMOSPHERIC_ALBEDO, ITimeOfDay::TYPE_COLOR, 0.244f, 0.446f, 1.0f);
  361.         AddVar("Volumetric Clouds", "Atmospheric scattering", "Volumetric clouds: Atmospheric scattering", ITimeOfDay::PARAM_VOLCLOUD_ATMOSPHERIC_SCATTERING, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 10.0f);
  362.         AddVar("Volumetric Clouds", "Wind influence", "Volumetric clouds: Wind influence", ITimeOfDay::PARAM_VOLCLOUD_WIND_INFLUENCE, ITimeOfDay::TYPE_FLOAT, 0.0f, -1000.0f, 1000.0f);
  363.  
  364.         AddVar("Sun Rays Effect", "", "Sun shafts visibility", ITimeOfDay::PARAM_SUN_SHAFTS_VISIBILITY, ITimeOfDay::TYPE_FLOAT, 0.25f, 0.0f, 1.0f);
  365.         AddVar("Sun Rays Effect", "", "Sun rays visibility", ITimeOfDay::PARAM_SUN_RAYS_VISIBILITY, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 10.0f);
  366.         AddVar("Sun Rays Effect", "", "Sun rays attenuation", ITimeOfDay::PARAM_SUN_RAYS_ATTENUATION, ITimeOfDay::TYPE_FLOAT, 5.0f, 0.0f, 10.0f);
  367.         AddVar("Sun Rays Effect", "", "Sun rays suncolor influence", ITimeOfDay::PARAM_SUN_RAYS_SUNCOLORINFLUENCE, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 1.0f);
  368.         AddVar("Sun Rays Effect", "", "Sun rays custom color", ITimeOfDay::PARAM_SUN_RAYS_CUSTOMCOLOR, ITimeOfDay::TYPE_COLOR, 1.0f, 1.0f, 1.0f);
  369.  
  370.         AddVar("HDR", "", "Film curve shoulder scale", ITimeOfDay::PARAM_HDR_FILMCURVE_SHOULDER_SCALE, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 10.0f);
  371.         AddVar("HDR", "", "Film curve midtones scale", ITimeOfDay::PARAM_HDR_FILMCURVE_LINEAR_SCALE, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 10.0f);
  372.         AddVar("HDR", "", "Film curve toe scale", ITimeOfDay::PARAM_HDR_FILMCURVE_TOE_SCALE, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 10.0f);
  373.         AddVar("HDR", "", "Film curve whitepoint", ITimeOfDay::PARAM_HDR_FILMCURVE_WHITEPOINT, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 10.0f);
  374.         AddVar("HDR", "", "Saturation", ITimeOfDay::PARAM_HDR_COLORGRADING_COLOR_SATURATION, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 2.0f);
  375.         AddVar("HDR", "", "Color balance", ITimeOfDay::PARAM_HDR_COLORGRADING_COLOR_BALANCE, ITimeOfDay::TYPE_COLOR, 1.0f, 1.0f, 1.0f);
  376.         AddVar("HDR", "(Dep) Scene key", "Scene key", ITimeOfDay::PARAM_HDR_EYEADAPTATION_SCENEKEY, ITimeOfDay::TYPE_FLOAT, 0.18f, 0.0f, 1.0f);
  377.         AddVar("HDR", "(Dep) Min exposure", "Min exposure", ITimeOfDay::PARAM_HDR_EYEADAPTATION_MIN_EXPOSURE, ITimeOfDay::TYPE_FLOAT, 0.36f, 0.0f, 10.0f);
  378.         AddVar("HDR", "(Dep) Max exposure", "Max exposure", ITimeOfDay::PARAM_HDR_EYEADAPTATION_MAX_EXPOSURE, ITimeOfDay::TYPE_FLOAT, 2.8f, 0.0f, 10.0f);
  379.         AddVar("HDR", "", "EV Min", ITimeOfDay::PARAM_HDR_EYEADAPTATION_EV_MIN, ITimeOfDay::TYPE_FLOAT, 4.5f, -10.0f, 20.0f);
  380.         AddVar("HDR", "", "EV Max", ITimeOfDay::PARAM_HDR_EYEADAPTATION_EV_MAX, ITimeOfDay::TYPE_FLOAT, 17.0f, -10.0f, 20.0f);
  381.         AddVar("HDR", "", "EV Auto compensation", ITimeOfDay::PARAM_HDR_EYEADAPTATION_EV_AUTO_COMPENSATION, ITimeOfDay::TYPE_FLOAT, 1.5f, -5.0f, 5.0f);
  382.         AddVar("HDR", "", "Bloom amount", ITimeOfDay::PARAM_HDR_BLOOM_AMOUNT, ITimeOfDay::TYPE_FLOAT, 0.1f, 0.0f, 10.0f);
  383.  
  384.         AddVar("Filters", "Grain", "Filters: grain", ITimeOfDay::PARAM_COLORGRADING_FILTERS_GRAIN, ITimeOfDay::TYPE_FLOAT, 0.0f, 0.0f, 8.0f);                                           // deprecated
  385.         AddVar("Filters", "Photofilter color", "Filters: photofilter color", ITimeOfDay::PARAM_COLORGRADING_FILTERS_PHOTOFILTER_COLOR, ITimeOfDay::TYPE_COLOR, 0.952f, 0.517f, 0.09f);  // deprecated
  386.         AddVar("Filters", "Photofilter density", "Filters: photofilter density", ITimeOfDay::PARAM_COLORGRADING_FILTERS_PHOTOFILTER_DENSITY, ITimeOfDay::TYPE_FLOAT, 0.0f, 0.0f, 1.0f); // deprecated
  387.  
  388.         AddVar("Depth Of Field", "Focus range", "Dof: focus range", ITimeOfDay::PARAM_COLORGRADING_DOF_FOCUSRANGE, ITimeOfDay::TYPE_FLOAT, 1000.0f, 0.0f, 10000.0f);
  389.         AddVar("Depth Of Field", "Blur amount", "Dof: blur amount", ITimeOfDay::PARAM_COLORGRADING_DOF_BLURAMOUNT, ITimeOfDay::TYPE_FLOAT, 0.0f, 0.0f, 1.0f);
  390.  
  391.         AddVar("Advanced", "", "Ocean fog color", ITimeOfDay::PARAM_OCEANFOG_COLOR, ITimeOfDay::TYPE_COLOR, 29.0f * fRecip255, 102.0f * fRecip255, 141.0f * fRecip255);
  392.         AddVar("Advanced", "", "Ocean fog color multiplier", ITimeOfDay::PARAM_OCEANFOG_COLOR_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 1.0f);
  393.         AddVar("Advanced", "", "Ocean fog density", ITimeOfDay::PARAM_OCEANFOG_DENSITY, ITimeOfDay::TYPE_FLOAT, 0.2f, 0.0f, 1.0f);
  394.  
  395.         AddVar("Advanced", "", "Skybox multiplier", ITimeOfDay::PARAM_SKYBOX_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 1.0f);
  396.  
  397.         const float arrDepthConstBias[] = { 1.0f, 1.0f, 1.9f, 3.0f, 2.0f, 2.0f, 2.0f, 2.0f };
  398.         const float arrDepthSlopeBias[] = { 4.0f, 2.0f, 0.24f, 0.24f, 0.5f, 0.5f, 0.5f, 0.5f };
  399.         AddVar("Shadows", "", "Cascade 0: Bias", ITimeOfDay::PARAM_SHADOWSC0_BIAS, ITimeOfDay::TYPE_FLOAT, arrDepthConstBias[0], 0.0f, 10.0f);
  400.         AddVar("Shadows", "", "Cascade 0: Slope Bias", ITimeOfDay::PARAM_SHADOWSC0_SLOPE_BIAS, ITimeOfDay::TYPE_FLOAT, arrDepthSlopeBias[0], 0.0f, 500.0f);
  401.         AddVar("Shadows", "", "Cascade 1: Bias", ITimeOfDay::PARAM_SHADOWSC1_BIAS, ITimeOfDay::TYPE_FLOAT, arrDepthConstBias[1], 0.0f, 10.0f);
  402.         AddVar("Shadows", "", "Cascade 1: Slope Bias", ITimeOfDay::PARAM_SHADOWSC1_SLOPE_BIAS, ITimeOfDay::TYPE_FLOAT, arrDepthSlopeBias[1], 0.0f, 500.0f);
  403.         AddVar("Shadows", "", "Cascade 2: Bias", ITimeOfDay::PARAM_SHADOWSC2_BIAS, ITimeOfDay::TYPE_FLOAT, arrDepthConstBias[2], 0.0f, 10.0f);
  404.         AddVar("Shadows", "", "Cascade 2: Slope Bias", ITimeOfDay::PARAM_SHADOWSC2_SLOPE_BIAS, ITimeOfDay::TYPE_FLOAT, arrDepthSlopeBias[2], 0.0f, 500.0f);
  405.         AddVar("Shadows", "", "Cascade 3: Bias", ITimeOfDay::PARAM_SHADOWSC3_BIAS, ITimeOfDay::TYPE_FLOAT, arrDepthConstBias[3], 0.0f, 10.0f);
  406.         AddVar("Shadows", "", "Cascade 3: Slope Bias", ITimeOfDay::PARAM_SHADOWSC3_SLOPE_BIAS, ITimeOfDay::TYPE_FLOAT, arrDepthSlopeBias[3], 0.0f, 500.0f);
  407.         AddVar("Shadows", "", "Cascade 4: Bias", ITimeOfDay::PARAM_SHADOWSC4_BIAS, ITimeOfDay::TYPE_FLOAT, arrDepthConstBias[4], 0.0f, 10.0f);
  408.         AddVar("Shadows", "", "Cascade 4: Slope Bias", ITimeOfDay::PARAM_SHADOWSC4_SLOPE_BIAS, ITimeOfDay::TYPE_FLOAT, arrDepthSlopeBias[4], 0.0f, 500.0f);
  409.         AddVar("Shadows", "", "Cascade 5: Bias", ITimeOfDay::PARAM_SHADOWSC5_BIAS, ITimeOfDay::TYPE_FLOAT, arrDepthConstBias[5], 0.0f, 10.0f);
  410.         AddVar("Shadows", "", "Cascade 5: Slope Bias", ITimeOfDay::PARAM_SHADOWSC5_SLOPE_BIAS, ITimeOfDay::TYPE_FLOAT, arrDepthSlopeBias[5], 0.0f, 500.0f);
  411.         AddVar("Shadows", "", "Cascade 6: Bias", ITimeOfDay::PARAM_SHADOWSC6_BIAS, ITimeOfDay::TYPE_FLOAT, arrDepthConstBias[6], 0.0f, 10.0f);
  412.         AddVar("Shadows", "", "Cascade 6: Slope Bias", ITimeOfDay::PARAM_SHADOWSC6_SLOPE_BIAS, ITimeOfDay::TYPE_FLOAT, arrDepthSlopeBias[6], 0.0f, 500.0f);
  413.         AddVar("Shadows", "", "Cascade 7: Bias", ITimeOfDay::PARAM_SHADOWSC7_BIAS, ITimeOfDay::TYPE_FLOAT, arrDepthConstBias[7], 0.0f, 10.0f);
  414.         AddVar("Shadows", "", "Cascade 7: Slope Bias", ITimeOfDay::PARAM_SHADOWSC7_SLOPE_BIAS, ITimeOfDay::TYPE_FLOAT, arrDepthSlopeBias[7], 0.0f, 500.0f);
  415.  
  416.         AddVar("Shadows", "", "Shadow jittering", ITimeOfDay::PARAM_SHADOW_JITTERING, ITimeOfDay::TYPE_FLOAT, 2.5f, 0.f, 10.f);
  417.  
  418.         AddVar("Obsolete", "", "HDR dynamic power factor", ITimeOfDay::PARAM_HDR_DYNAMIC_POWER_FACTOR, ITimeOfDay::TYPE_FLOAT, 0.0f, -4.0f, 4.0f);
  419.         AddVar("Obsolete", "", "Global illumination multiplier", ITimeOfDay::PARAM_GI_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 1.f, 0.f, 100.f);
  420.         AddVar("Obsolete", "", "Sky brightening (terrain occlusion)", ITimeOfDay::PARAM_TERRAIN_OCCL_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 0.3f, 0.f, 1.f);
  421.         AddVar("Obsolete", "", "Sun color multiplier", ITimeOfDay::PARAM_SUN_COLOR_MULTIPLIER, ITimeOfDay::TYPE_FLOAT, 1.0f, 0.0f, 16.0f);
  422. }
  423.  
  424. void CEnvironmentPreset::Serialize(Serialization::IArchive& ar)
  425. {
  426.         if (ar.isInput())
  427.         {
  428.                 unsigned int version = 0;
  429.                 const bool bReadResult = ar(version, "version");
  430.                 if (bReadResult && (sCurrentPresetVersion == version))
  431.                 {
  432.                         // read directly
  433.                         for (size_t i = 0; i < ITimeOfDay::PARAM_TOTAL; ++i)
  434.                         {
  435.                                 ar(m_vars[i], "var");
  436.                         }
  437.                 }
  438.                 else
  439.                 {
  440.                         // convert to current version
  441.                         for (size_t i = 0; i < ITimeOfDay::PARAM_TOTAL; ++i)
  442.                         {
  443.                                 const CTimeOfDayVariable& var = m_vars[i];
  444.                                 CTimeOfDayVariable tempVar = var;
  445.                                 ar(tempVar, "var");
  446.  
  447.                                 if (!bReadResult)
  448.                                 {
  449.                                         //converting from initial version.
  450.                                         //rescale time from [0..1] to [0..sAnimTimeSecondsIn24h]
  451.                                         for (unsigned int i = 0; i < 3; ++i)
  452.                                         {
  453.                                                 CBezierSpline* pSpline = tempVar.GetSpline(i);
  454.                                                 const size_t nKeyCount = pSpline->GetKeyCount();
  455.  
  456.                                                 if (!nKeyCount)
  457.                                                         continue;
  458.  
  459.                                                 std::vector<SBezierKey> tempKeys;
  460.                                                 tempKeys.resize(nKeyCount);
  461.                                                 pSpline->GetKeys(&tempKeys[0]);
  462.                                                 for (unsigned int j = 0; j < nKeyCount; ++j)
  463.                                                 {
  464.                                                         SBezierKey& key = tempKeys[j];
  465.                                                         key.m_time *= sAnimTimeSecondsIn24h;
  466.                                                 }
  467.                                                 pSpline->SetKeys(&tempKeys[0], nKeyCount);
  468.                                         }
  469.                                 }
  470.  
  471.                                 const ITimeOfDay::ETimeOfDayParamID id = tempVar.GetId();
  472.                                 if (id < ITimeOfDay::PARAM_TOTAL)
  473.                                         m_vars[id] = tempVar; //update the actual var
  474.                         }
  475.                 }
  476.         }
  477.         else
  478.         {
  479.                 ar(sCurrentPresetVersion, "version");
  480.                 for (size_t i = 0; i < ITimeOfDay::PARAM_TOTAL; ++i)
  481.                 {
  482.                         ar(m_vars[i], "var");
  483.                 }
  484.         }
  485. }
  486.  
  487. void CEnvironmentPreset::Update(float t)
  488. {
  489.         t *= sAnimTimeSecondsIn24h;
  490.         for (size_t i = 0; i < ITimeOfDay::PARAM_TOTAL; ++i)
  491.         {
  492.                 m_vars[i].Update(t);
  493.         }
  494. }
  495.  
  496. CTimeOfDayVariable* CEnvironmentPreset::GetVar(const char* varName)
  497. {
  498.         for (size_t i = 0; i < ITimeOfDay::PARAM_TOTAL; ++i)
  499.         {
  500.                 if (strcmp(m_vars[i].GetName(), varName) == 0)
  501.                 {
  502.                         return &m_vars[i];
  503.                 }
  504.         }
  505.         return NULL;
  506. }
  507.  
  508. bool CEnvironmentPreset::InterpolateVarInRange(ITimeOfDay::ETimeOfDayParamID id, float fMin, float fMax, unsigned int nCount, Vec3* resultArray) const
  509. {
  510.         const float fdx = 1.0f / float(nCount);
  511.         float normX = 0.0f;
  512.         for (unsigned int i = 0; i < nCount; ++i)
  513.         {
  514.                 const float time = Lerp(fMin, fMax, normX);
  515.                 resultArray[i] = m_vars[id].GetInterpolatedAt(time);
  516.                 normX += fdx;
  517.         }
  518.  
  519.         return true;
  520. }
  521.  
  522. float CEnvironmentPreset::GetAnimTimeSecondsIn24h()
  523. {
  524.         return sAnimTimeSecondsIn24h;
  525. }
  526.  
  527. void CEnvironmentPreset::AddVar(const char* group, const char* displayName, const char* name, ITimeOfDay::ETimeOfDayParamID nParamId, ITimeOfDay::EVariableType type, float defVal0, float defVal1, float defVal2)
  528. {
  529.         CTimeOfDayVariable& var = m_vars[nParamId];
  530.         var.Init(group, displayName, name, nParamId, type, defVal0, defVal1, defVal2);
  531. }
  532.  
downloadEnvironmentPreset.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top