BVB Source Codes

CRYENGINE Show ParticleSplineImpl.h Source code

Return Download CRYENGINE: download ParticleSplineImpl.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  Created:     04/03/2015 by Filipe amim
  5. //  Description:
  6. // -------------------------------------------------------------------------
  7. //
  8. ////////////////////////////////////////////////////////////////////////////
  9.  
  10. #ifndef PARTICLESPLINEIMPL_H
  11. #define PARTICLESPLINEIMPL_H
  12.  
  13. #pragma once
  14.  
  15. namespace pfx2
  16. {
  17.  
  18. ILINE float CParticleSpline::Interpolate(float time) const
  19. {
  20.         time = std::min(std::max(time, m_keys[0].time), m_keys.back().time);
  21.  
  22.         const SplineKey* pKey = &*m_keys.begin();
  23.         const SplineKey* pKeyEnd = &*(m_keys.end() - 2);
  24.         while (pKey < pKeyEnd && pKey[1].time < time)
  25.                 ++pKey;
  26.  
  27.         const float inTime = pKey->time;
  28.         const float multTime = pKey->timeMult;
  29.         const float t = (time - inTime) * multTime;
  30.         assert(t >= 0.0f && t <= 1.0f);
  31.         const float v0 = pKey->value;
  32.         const float v1 = pKey[1].value;
  33.         const float c0 = pKey->coeff0;
  34.         const float c1 = pKey->coeff1;
  35.         const float u = 1.0f - t;
  36.         const float tu = t * u;
  37.         const float v = (v0 * u + v1 * t) + (c0 * u + c1 * t) * tu;
  38.         return v;
  39. }
  40.  
  41. #ifdef CRY_PFX2_USE_SSE
  42. ILINE floatv CParticleSpline::Interpolate(const floatv time) const
  43. {
  44.         const SplineKey* __restrict pKey = &*m_keys.begin();
  45.         const SplineKey* __restrict pEndKey = &*(m_keys.end() - 1);
  46.  
  47.         // clamp time to curve bounds
  48.         const floatv minTime = _mm_load1_ps(&pKey->time);
  49.         const floatv maxTime = _mm_load1_ps(&pEndKey->time);
  50.         const floatv tk = clamp(time, minTime, maxTime);
  51.  
  52.         // search key
  53.         floatv t0 = _mm_load1_ps(&pKey->time);
  54.         floatv tm = _mm_load1_ps(&pKey->timeMult);
  55.         floatv v0 = _mm_load1_ps(&pKey->value);
  56.         floatv c0 = _mm_load1_ps(&pKey->coeff0);
  57.         floatv c1 = _mm_load1_ps(&pKey->coeff1);
  58.         floatv v1 = _mm_load1_ps(&pKey[1].value);
  59.  
  60.         for (pKey++; pKey < pEndKey; pKey++)
  61.         {
  62.                 const floatv t = _mm_load1_ps(&pKey->time);
  63.                 const mask32v4 condMask = t < tk;
  64.                 if (!Any(condMask))
  65.                         break;
  66.                 t0 = if_else(condMask, t, t0);
  67.                 tm = if_else(condMask, _mm_load1_ps(&pKey->timeMult), tm);
  68.                 v0 = if_else(condMask, _mm_load1_ps(&pKey->value), v0);
  69.                 c0 = if_else(condMask, _mm_load1_ps(&pKey->coeff0), c0);
  70.                 c1 = if_else(condMask, _mm_load1_ps(&pKey->coeff1), c1);
  71.                 v1 = if_else(condMask, _mm_load1_ps(&pKey[1].value), v1);
  72.         }
  73.  
  74.         // calculate curve
  75.         const floatv one = ToFloatv(1.0f);
  76.         const floatv t = (tk - t0) * tm;
  77.         const floatv u = one - t;
  78.         const floatv tu = t * u;
  79.         const floatv v = Lerp(v0, v1, t) + Lerp(c0, c1, t) * tu;
  80.  
  81.         return v;
  82. }
  83. #endif
  84.  
  85. ILINE void CParticleSpline::Interpolate(float time, ValueType& value)
  86. {
  87.         if (GetKeyCount() == 0)
  88.                 value[0] = 1.0f;
  89.         else if (GetKeyCount() == 1)
  90.                 value[0] = m_keys[0].value;
  91.         else
  92.                 value[0] = Interpolate(time);
  93. }
  94.  
  95. ILINE float CParticleDoubleSpline::Interpolate(float time, float unormRand) const
  96. {
  97.         const float low = m_splines[0].Interpolate(time);
  98.         const float high = m_splines[1].Interpolate(time);
  99.         const float result = Lerp(low, high, unormRand);
  100.         return result;
  101. }
  102.  
  103. #ifdef CRY_PFX2_USE_SSE
  104. ILINE floatv CParticleDoubleSpline::Interpolate(floatv time, floatv unormRand) const
  105. {
  106.         const floatv low = m_splines[0].Interpolate(time);
  107.         const floatv high = m_splines[1].Interpolate(time);
  108.         const floatv result = Lerp(low, high, unormRand);
  109.         return result;
  110. }
  111. #endif
  112.  
  113. ILINE ColorF CParticleColorSpline::Interpolate(float time) const
  114. {
  115.         return ColorF(
  116.           m_splines[0].Interpolate(time),
  117.           m_splines[1].Interpolate(time),
  118.           m_splines[2].Interpolate(time));
  119. }
  120.  
  121. #ifdef CRY_PFX2_USE_SSE
  122. ILINE ColorFv CParticleColorSpline::Interpolate(floatv time) const
  123. {
  124.         return ColorFv(
  125.           m_splines[0].Interpolate(time),
  126.           m_splines[1].Interpolate(time),
  127.           m_splines[2].Interpolate(time));
  128. }
  129. #endif
  130.  
  131. }
  132.  
  133. #endif
  134.  
downloadParticleSplineImpl.h 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