Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
ShaderVec3.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2025 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5inline float3 JPH_Vec3DecompressUnit(uint inValue)
6{
7 const float cOneOverSqrt2 = 0.70710678f;
8 const uint cNumBits = 14;
9 const uint cMask = (1u << cNumBits) - 1;
10 const uint cMaxValue = cMask - 1; // Need odd number of buckets to quantize to or else we can't encode 0
11 const int cHalfMaxValue = int(cMaxValue >> 1);
12 const float cScale = 2.0f * cOneOverSqrt2 / float(cMaxValue);
13
14 // Restore two components
15 float2 v2 = float2(float(int(inValue & cMask) - cHalfMaxValue), float(int((inValue >> cNumBits) & cMask) - cHalfMaxValue)) * cScale;
16
17 // Restore the highest component
18 float3 v = float3(v2, sqrt(max(1.0f - dot(v2, v2), 0.0f)));
19
20 // Extract sign
21 if ((inValue & 0x80000000u) != 0)
22 v = -v;
23
24 // Swizzle the components in place
25 uint max_element = (inValue >> 29) & 3;
26 v = max_element == 0? v.zxy : (max_element == 1? v.xzy : v);
27
28 return v;
29}
unsigned int uint
Definition Core.h:510
float3 JPH_Vec3DecompressUnit(uint inValue)
Definition ShaderVec3.h:5