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 float cScale = 2.0f * cOneOverSqrt2 / float(cMaxValue);
12
13 // Restore two components
14 float2 v2 = float2(float(inValue & cMask), float((inValue >> cNumBits) & cMask)) * cScale - float2(cOneOverSqrt2, cOneOverSqrt2);
15
16 // Restore the highest component
17 float3 v = float3(v2, sqrt(max(1.0f - dot(v2, v2), 0.0f)));
18
19 // Extract sign
20 if ((inValue & 0x80000000u) != 0)
21 v = -v;
22
23 // Swizzle the components in place
24 uint max_element = (inValue >> 29) & 3;
25 v = max_element == 0? v.zxy : (max_element == 1? v.xzy : v);
26
27 return v;
28}
unsigned int uint
Definition Core.h:500
float3 JPH_Vec3DecompressUnit(uint inValue)
Definition ShaderVec3.h:5