BVB Source Codes

CRYENGINE Show ParticleMathImplSSE.h Source code

Return Download CRYENGINE: download ParticleMathImplSSE.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. namespace pfx2
  4. {
  5.  
  6. namespace detail
  7. {
  8.  
  9. }
  10.  
  11. ILINE floatv ToFloatv(float v)
  12. {
  13.         return convert<floatv>(v);
  14. }
  15.  
  16. ILINE uint32v ToUint32v(uint32 v)
  17. {
  18.         return convert<uint32v>(v);
  19. }
  20.  
  21. ILINE floatv ToFloatv(int32v v)
  22. {
  23.         return convert<floatv>(v);
  24. }
  25.  
  26. ILINE floatv ToFloatv(uint32v v)
  27. {
  28.         return convert<floatv>(v);
  29. }
  30.  
  31. ILINE uint32v ToUint32v(floatv v)
  32. {
  33.         return convert<uint32v>(v);
  34. }
  35.  
  36. ILINE Vec3v ToVec3v(Vec3 v)
  37. {
  38.         return Vec3v(
  39.                 convert<floatv>(v.x),
  40.                 convert<floatv>(v.y),
  41.                 convert<floatv>(v.z));
  42. }
  43.  
  44. ILINE Vec4v ToVec4v(Vec4 v)
  45. {
  46.         return Vec4v(
  47.                 convert<floatv>(v.x),
  48.                 convert<floatv>(v.y),
  49.                 convert<floatv>(v.z),
  50.                 convert<floatv>(v.w));
  51. }
  52.  
  53. ILINE Planev ToPlanev(Plane v)
  54. {
  55.         return Planev(
  56.           ToVec3v(v.n),
  57.           ToFloatv(v.d));
  58. }
  59.  
  60. ILINE float HMin(floatv v0)
  61. {
  62.         const floatv v1 = _mm_shuffle_ps(v0, v0, _MM_SHUFFLE(3, 3, 1, 1));
  63.         const floatv v2 = _mm_min_ps(v0, v1);
  64.         const floatv v3 = _mm_shuffle_ps(v2, v2, _MM_SHUFFLE(2, 2, 2, 2));
  65.         const floatv res = _mm_min_ps(v3, v2);
  66.         return _mm_cvtss_f32(res);
  67. }
  68.  
  69. ILINE float HMax(floatv v0)
  70. {
  71.         const floatv v1 = _mm_shuffle_ps(v0, v0, _MM_SHUFFLE(3, 3, 1, 1));
  72.         const floatv v2 = _mm_max_ps(v0, v1);
  73.         const floatv v3 = _mm_shuffle_ps(v2, v2, _MM_SHUFFLE(2, 2, 2, 2));
  74.         const floatv res = _mm_max_ps(v3, v2);
  75.         return _mm_cvtss_f32(res);
  76. }
  77.  
  78. ILINE ColorFv operator+(const ColorFv& a, const ColorFv& b)
  79. {
  80.         return ColorFv(
  81.           Add(a.r, b.r),
  82.           Add(a.g, b.g),
  83.           Add(a.b, b.b));
  84. }
  85.  
  86. ILINE ColorFv operator*(const ColorFv& a, const ColorFv& b)
  87. {
  88.         return ColorFv(
  89.           Mul(a.r, b.r),
  90.           Mul(a.g, b.g),
  91.           Mul(a.b, b.b));
  92. }
  93.  
  94. ILINE ColorFv operator*(const ColorFv& a, floatv b)
  95. {
  96.         return ColorFv(
  97.           Mul(a.r, b),
  98.           Mul(a.g, b),
  99.           Mul(a.b, b));
  100. }
  101.  
  102. ILINE floatv DeltaTime(floatv normAge, floatv frameTime)
  103. {
  104.         return __fsel(normAge, frameTime, -(normAge * frameTime));
  105. }
  106.  
  107. ILINE ColorFv ToColorFv(UColv color)
  108. {
  109.         ColorFv result;
  110.         const floatv toFloat = _mm_set1_ps(1.0f / 255.0f);
  111.         const uint32v redMask = _mm_set1_epi32(0x00ff0000);
  112.         const uint32v greenMask = _mm_set1_epi32(0x0000ff00);
  113.         const uint32v blueMask = _mm_set1_epi32(0x000000ff);
  114.         result.r = _mm_mul_ps(_mm_cvtepi32_ps(_mm_srli_epi32(_mm_and_si128(color, redMask), 16)), toFloat);
  115.         result.g = _mm_mul_ps(_mm_cvtepi32_ps(_mm_srli_epi32(_mm_and_si128(color, greenMask), 8)), toFloat);
  116.         result.b = _mm_mul_ps(_mm_cvtepi32_ps(_mm_and_si128(color, blueMask)), toFloat);
  117.         return result;
  118. }
  119.  
  120. ILINE UColv ColorFvToUColv(const ColorFv& color)
  121. {
  122.         UColv result;
  123.         const floatv fromFloat = _mm_set1_ps(255.0f);
  124.         const uint32v mask = _mm_set1_epi32(0x000000ff);
  125.         const uint32v alphaMask = _mm_set1_epi32(0xff000000);
  126.  
  127.         const uint32v red = _mm_slli_epi32(_mm_and_si128(_mm_cvtps_epi32(_mm_mul_ps(color.r, fromFloat)), mask), 16);
  128.         const uint32v green = _mm_slli_epi32(_mm_and_si128(_mm_cvtps_epi32(_mm_mul_ps(color.g, fromFloat)), mask), 8);
  129.         const uint32v blue = _mm_and_si128(_mm_cvtps_epi32(_mm_mul_ps(color.b, fromFloat)), mask);
  130.  
  131.         result = _mm_or_si128(alphaMask, _mm_or_si128(red, _mm_or_si128(green, blue)));
  132.  
  133.         return result;
  134. }
  135.  
  136. ILINE UColv ToUColv(UCol color)
  137. {
  138.         return _mm_set1_epi32(color.dcolor);
  139. }
  140.  
  141. //////////////////////////////////////////////////////////////////////////
  142. // Quaternions
  143.  
  144. ILINE floatv sin_fast(floatv x)
  145. {
  146.         const floatv one = ToFloatv(1.0f);
  147.         const floatv negOne = ToFloatv(-1.0f);
  148.         const floatv half = ToFloatv(0.5f);
  149.         const floatv negHalfPi = ToFloatv(-gf_PI * 0.5f);
  150.         const floatv pi = ToFloatv(gf_PI);
  151.         const floatv ipi = ToFloatv(1.0f / gf_PI);
  152.         const floatv ipi2 = ToFloatv(1.0f / gf_PI2);
  153.  
  154.         const floatv x1 = MAdd(frac(x * ipi), pi, negHalfPi);
  155.         const floatv m = __fsel(Sub(frac(x * ipi2), half), one, negOne);
  156.  
  157.         const floatv p0 = ToFloatv(-0.4964738f);
  158.         const floatv p1 = ToFloatv(0.036957536f);
  159.         const floatv x2 = x1 * x1;
  160.         const floatv x4 = x2 * x2;
  161.         const floatv result = MAdd(x4, p1, MAdd(x2, p0, one)) * m;
  162.  
  163.         return result;
  164. }
  165.  
  166. ILINE floatv cos_fast(floatv x)
  167. {
  168.         const floatv halfPi = ToFloatv(gf_PI * 0.5f);
  169.         return sin_fast(x - halfPi);
  170. }
  171.  
  172. ILINE Quatv quat_exp_fast(Vec3v v)
  173. {
  174.         const floatv lenSqr = v.len2();
  175.         const floatv len = sqrt_fast_tpl(lenSqr);
  176.         const floatv invLen = rcp_fast(max(len, convert<floatv>(FLT_MIN)));
  177.         const floatv s = sin_fast(len) * invLen;
  178.         const floatv c = cos_fast(len);
  179.  
  180.         return Quatv(c, v.x * s, v.y * s, v.z * s);
  181. }
  182.  
  183. ILINE Quatv AddAngularVelocity(Quatv initial, Vec3v angularVel, floatv deltaTime)
  184. {
  185.         const floatv haldDt = deltaTime * ToFloatv(0.5f);
  186.         const Quatv rotated = quat_exp_fast(angularVel * haldDt) * initial;
  187.         return rotated.GetNormalized();
  188. }
  189.  
  190. }
  191.  
downloadParticleMathImplSSE.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