Skip to content

Commit

Permalink
Quad view test stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Dec 13, 2023
1 parent e1ac360 commit 46e9c98
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
4 changes: 4 additions & 0 deletions src/mods/VR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2549,6 +2549,10 @@ Matrix4x4f VR::get_projection_matrix(VRRuntime::Eye eye, bool flip) {

std::shared_lock _{get_runtime()->eyes_mtx};

if ((uint32_t)eye >= 2) {
return get_runtime()->projections[(uint32_t)eye];
}

if ((eye == VRRuntime::Eye::LEFT && !flip) || (eye == VRRuntime::Eye::RIGHT && flip)) {
return get_runtime()->projections[(uint32_t)VRRuntime::Eye::LEFT];
}
Expand Down
29 changes: 18 additions & 11 deletions src/mods/vr/FFakeStereoRenderingHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3845,12 +3845,14 @@ void FFakeStereoRenderingHook::adjust_view_rect(FFakeStereoRendering* stereo, in
return;
}

static bool ever_started_from_zero = false;
static bool index_starts_from_one = true;

if (index == 2) {
if (index == 2 && !ever_started_from_zero) {
index_starts_from_one = true;
} else if (index == 0) {
index_starts_from_one = false;
ever_started_from_zero = true;
}

// The purpose of this is to prevent the game from crashing in IDirect3D12CommandList::Close
Expand Down Expand Up @@ -3881,11 +3883,16 @@ void FFakeStereoRenderingHook::adjust_view_rect(FFakeStereoRendering* stereo, in
*h = VR::get()->get_hmd_height();
}

const auto true_index = index_starts_from_one ? ((index + 1) % 4) : (index % 4);

*w = *w / 2;

const auto true_index = index_starts_from_one ? ((index + 1) % 2) : (index % 2);
*x += *w * true_index;
if (true_index < 2) {
*w = *w / 8;
*x += *w * true_index;
} else {
*x += ((*w / 8) * 2);
*w = (*w - *x) / 2;
*x += *w * true_index;
}
}

__forceinline void FFakeStereoRenderingHook::calculate_stereo_view_offset(
Expand Down Expand Up @@ -3932,7 +3939,7 @@ __forceinline void FFakeStereoRenderingHook::calculate_stereo_view_offset(

const auto is_full_pass = view_index == 0 && !index_was_ever_two && !index_was_ever_negative;

auto true_index = index_starts_from_one ? ((view_index + 1) % 2) : (view_index % 2);
auto true_index = index_starts_from_one ? ((view_index + 1) % 4) : (view_index % 4);
const auto has_double_precision = g_hook->m_has_double_precision;
const auto rot_d = (Rotator<double>*)view_rotation;

Expand Down Expand Up @@ -4234,6 +4241,8 @@ __forceinline Matrix4x4f* FFakeStereoRenderingHook::calculate_stereo_projection_
}
}

auto true_index = index_starts_from_one ? ((view_index + 1) % 4) : (view_index % 4);

if (VR::get()->is_using_2d_screen()) {
float fov = 90.0f; // todo, get from FMinimalViewInfo

Expand Down Expand Up @@ -4266,8 +4275,6 @@ __forceinline Matrix4x4f* FFakeStereoRenderingHook::calculate_stereo_projection_
// SPDLOG_INFO("NearZ: {}", old_znear);

if (out != nullptr) {
auto true_index = index_starts_from_one ? ((view_index + 1) % 2) : (view_index % 2);

if (vr->is_using_afr()) {
true_index = g_frame_count % 2;
}
Expand Down Expand Up @@ -4449,7 +4456,7 @@ uint32_t FFakeStereoRenderingHook::get_desired_number_of_views_hook(FFakeStereoR
auto& vr = VR::get();

if (g_hook->m_sceneview_data.inside_post_init_properties) {
return 2;
return 4;
}

if (!is_stereo_enabled || (vr->is_using_afr() && !vr->is_splitscreen_compatibility_enabled())) {
Expand All @@ -4460,13 +4467,13 @@ uint32_t FFakeStereoRenderingHook::get_desired_number_of_views_hook(FFakeStereoR
!!g_hook->m_sceneview_data.constructor_hook && g_hook->m_has_view_extensions_installed)
{
// Only works correctly if view extensions are installed, so we can reset the view count to 1 without crashing
return 2;
return 4;
}

return 1;
}

return 2;
return 4;
}

// Only really necessary for 5.0.3 because for some reason negative view index gets passed into it
Expand Down
15 changes: 8 additions & 7 deletions src/mods/vr/runtimes/OpenXR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,18 +430,19 @@ VRRuntime::Error OpenXR::update_matrices(float nearz, float farz) {
std::unique_lock __{ this->eyes_mtx };
std::unique_lock ___{ this->pose_mtx };

for (auto i = 0; i < 2; ++i) {
const auto& pose = this->views[i].pose;
const auto& fov = this->views[i].fov;
for (auto i = 0; i < 4; ++i) {
const auto& pose = this->views[i % 2].pose;
const auto& fov = this->views[i % 2].fov;

// Update projection matrix
//XrMatrix4x4f_CreateProjection((XrMatrix4x4f*)&this->projections[i], GRAPHICS_D3D, tan(fov.angleLeft), tan(fov.angleRight), tan(fov.angleUp), tan(fov.angleDown), nearz, farz);

auto get_mat = [&](int eye) {
const auto top = tan(fov.angleUp);
const auto bottom = tan(fov.angleDown);
const auto left = tan(fov.angleLeft);
const auto right = tan(fov.angleRight);
const auto divisor = eye >= 2 ? 2.0f : 1.0f;
const auto top = tan(fov.angleUp / divisor);
const auto bottom = tan(fov.angleDown / divisor);
const auto left = tan(fov.angleLeft / divisor);
const auto right = tan(fov.angleRight / divisor);

float sum_rl = (right + left);
float sum_tb = (top + bottom);
Expand Down
2 changes: 1 addition & 1 deletion src/mods/vr/runtimes/VRRuntime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ struct VRRuntime {

std::optional<std::string> error{};

std::array<Matrix4x4f, 2> projections{};
std::array<Matrix4x4f, 4> projections{};
std::array<Matrix4x4f, 2> eyes{};
std::array<Matrix4x4f, 2> aim_matrices{};
std::array<Matrix4x4f, 2> grip_matrices{};
Expand Down

0 comments on commit 46e9c98

Please sign in to comment.