mat4_invertPose;

~3.9x
This commit is contained in:
bjorn 2018-10-06 21:21:25 -07:00
parent 11e6580717
commit 4279cf086f
5 changed files with 48 additions and 11 deletions

View File

@ -454,6 +454,10 @@ if(LOVR_ENABLE_MATH)
src/api/types/transform.c
src/lib/noise1234/noise1234.c
)
if(LOVR_USE_SSE)
add_definitions(-DLOVR_USE_SSE)
endif()
endif()
if(LOVR_ENABLE_PHYSICS)

View File

@ -218,7 +218,7 @@ static void fakeRenderTo(void (*callback)(void*), void* userdata) {
mat4_identity(camera.viewMatrix[0]);
mat4_translate(camera.viewMatrix[0], 0, state.offset, 0);
mat4_multiply(camera.viewMatrix[0], state.transform);
mat4_invert(camera.viewMatrix[0]);
mat4_invertPose(camera.viewMatrix[0]);
mat4_set(camera.projection[1], camera.projection[0]);
mat4_set(camera.viewMatrix[1], camera.viewMatrix[0]);
lovrGraphicsSetCamera(&camera, true);

View File

@ -553,7 +553,7 @@ static void openvrRenderTo(void (*callback)(void*), void* userdata) {
mat4_translate(camera.viewMatrix[i], 0, state.offset, 0);
mat4_multiply(camera.viewMatrix[i], head);
mat4_multiply(camera.viewMatrix[i], mat4_fromMat34(eye, state.system->GetEyeToHeadTransform(vrEye).m));
mat4_invert(camera.viewMatrix[i]);
mat4_invertPose(camera.viewMatrix[i]);
}
lovrGraphicsSetCamera(&camera, true);

View File

@ -108,17 +108,44 @@ mat4 mat4_invert(mat4 m) {
return m;
}
// This can only be used if the matrix doesn't have any scale applied
#ifdef LOVR_USE_SSE
mat4 mat4_invertPose(mat4 m) {
__m128 c0 = _mm_loadu_ps(m + 0);
__m128 c1 = _mm_loadu_ps(m + 4);
__m128 c2 = _mm_loadu_ps(m + 8);
__m128 c3 = _mm_loadu_ps(m + 12);
__m128 x1 = _mm_set_ps(1.f, 0.f, 0.f, 0.f);
_MM_TRANSPOSE4_PS(c0, c1, c2, x1);
__m128 x0 = _mm_add_ps(
_mm_mul_ps(c0, _mm_shuffle_ps(c3, c3, _MM_SHUFFLE(0, 0, 0, 0))),
_mm_mul_ps(c1, _mm_shuffle_ps(c3, c3, _MM_SHUFFLE(1, 1, 1, 1)))
);
x0 = _mm_add_ps(x0, _mm_mul_ps(c2, _mm_shuffle_ps(c3, c3, _MM_SHUFFLE(2, 2, 2, 2))));
x0 = _mm_xor_ps(x0, _mm_set1_ps(-0.f));
x0 = _mm_add_ps(x0, x1);
_mm_storeu_ps(m + 0, c0);
_mm_storeu_ps(m + 4, c1);
_mm_storeu_ps(m + 8, c2);
_mm_storeu_ps(m + 12, x0);
}
#endif
mat4 mat4_transpose(mat4 m) {
#ifdef LOVR_USE_SSE
__m128 c1 = _mm_loadu_ps(m + 0);
__m128 c2 = _mm_loadu_ps(m + 4);
__m128 c3 = _mm_loadu_ps(m + 8);
__m128 c4 = _mm_loadu_ps(m + 12);
_MM_TRANSPOSE4_PS(c1, c2, c3, c4);
_mm_storeu_ps(m + 0, c1);
_mm_storeu_ps(m + 4, c2);
_mm_storeu_ps(m + 8, c3);
_mm_storeu_ps(m + 12, c4);
__m128 c0 = _mm_loadu_ps(m + 0);
__m128 c1 = _mm_loadu_ps(m + 4);
__m128 c2 = _mm_loadu_ps(m + 8);
__m128 c3 = _mm_loadu_ps(m + 12);
_MM_TRANSPOSE4_PS(c0, c1, c2, c3);
_mm_storeu_ps(m + 0, c0);
_mm_storeu_ps(m + 4, c1);
_mm_storeu_ps(m + 8, c2);
_mm_storeu_ps(m + 12, c3);
return m;
#else
float a01 = m[1], a02 = m[2], a03 = m[3],

View File

@ -22,3 +22,9 @@ mat4 mat4_perspective(mat4 m, float near, float far, float fov, float aspect);
mat4 mat4_lookAt(mat4 m, vec3 from, vec3 to, vec3 up);
void mat4_transform(mat4 m, float* x, float* y, float* z);
void mat4_transformDirection(mat4 m, float* x, float* y, float* z);
#ifdef LOVR_USE_SSE
mat4 mat4_invertPose(mat4 m);
#else
#define mat4_invertPose mat4_invert
#endif