Skip to content

Commit

Permalink
Convergence hotkey implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
oneup03 committed Jun 11, 2024
1 parent a5c3e84 commit 7889c07
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Only Windows was tested. It may build on Linux, but there are other solutions on
| `window_height` | `int` | The height of the application window. | `1080` |
| `aspect_ratio` | `float` | The aspect ratio used to calculate vertical FoV | `1.77778` |
| `fov` | `float` | The field of view (FoV) for the VR rendering. | `90.0` |
| `depth` | `float` | The max depth. Overrides VR's IPD field. | `0.065` |
| `convergence` | `float` | Where the left and right images converge. Adjusts frustum. | `0.0` |
| `depth` | `float` | The max depth. Overrides VR's IPD field. | `0.5` |
| `convergence` | `float` | Where the left and right images converge. Adjusts frustum. | `0.1` |
| `tab_enable` | `bool` | Enable or disable top-and-bottom (TaB) 3D output (Side by Side is default) | `false` |
| `half_enable` | `bool` | Enable or disable half SbS/TaB 3D output. | `true` |
| `ss_enable` | `bool` | Enable or disable supersampling. | `false` |
Expand All @@ -35,6 +35,8 @@ Only Windows was tested. It may build on Linux, but there are other solutions on
- Edit the `Steam\steamapps\common\SteamVR\drivers\vrto3d\resources\settings\default.vrsettings` as needed
- Run SteamVR
- Try launching a VR game
- Adjust Depth with `Ctrl+F3` and `Ctrl+F4`
- Adjust Convergence with `Ctrl+F5` and `Ctrl+F6`


## Notes
Expand All @@ -49,6 +51,7 @@ Only Windows was tested. It may build on Linux, but there are other solutions on
- OpenXR games/mods seem to be more likely to work and be stable than OpenVR ones
- HDR doesn't seem to work currently
- Several mods/games may override your supersample and other settings
- Depth and Convergence are saved to your `Steam\config\steamvr.vrsettings` when SteamVR is closed. There are only global settings, no per-game ones.


## Building
Expand Down
28 changes: 24 additions & 4 deletions vrto3d/src/hmd_device_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void MockControllerDeviceDriver::DebugRequest( const char *pchRequest, char *pch


//-----------------------------------------------------------------------------
// Purpose: Center position for Stereo 3D
// Purpose: Static Pose, Depth and Convergence Hotkeys
//-----------------------------------------------------------------------------
vr::DriverPose_t MockControllerDeviceDriver::GetPose()
{
Expand Down Expand Up @@ -256,11 +256,11 @@ void MockControllerDeviceDriver::PoseUpdateThread()
}
// Ctrl+F5 Decrease Convergence
if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) && (GetAsyncKeyState(VK_F5) & 0x8000)) {
stereo_display_component_->AdjustConvergence(-0.001f);
stereo_display_component_->AdjustConvergence(-0.001f, device_index_);
}
// Ctrl+F6 Increase Convergence
if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) && (GetAsyncKeyState(VK_F6) & 0x8000)) {
stereo_display_component_->AdjustConvergence(0.001f);
stereo_display_component_->AdjustConvergence(0.001f, device_index_);
}

// Update our pose every 30 milliseconds.
Expand Down Expand Up @@ -458,11 +458,31 @@ void StereoDisplayComponent::AdjustDepth(float delta, uint32_t device_index)
//-----------------------------------------------------------------------------
// Purpose: To update the Convergence value
//-----------------------------------------------------------------------------
void StereoDisplayComponent::AdjustConvergence(float delta)
void StereoDisplayComponent::AdjustConvergence(float delta, uint32_t device_index)
{
float cur_conv = GetConvergence();
float new_conv = cur_conv + delta;
while (!convergence_.compare_exchange_weak(cur_conv, new_conv, std::memory_order_relaxed));

float left, right, top, bottom;
vr::HmdRect2_t eyeLeft, eyeRight;

GetProjectionRaw(vr::Eye_Left, &left, &right, &top, &bottom);
eyeLeft.vTopLeft.v[0] = left;
eyeLeft.vTopLeft.v[1] = top;
eyeLeft.vBottomRight.v[0] = right;
eyeLeft.vBottomRight.v[1] = bottom;

GetProjectionRaw(vr::Eye_Right, &left, &right, &top, &bottom);
eyeRight.vTopLeft.v[0] = left;
eyeRight.vTopLeft.v[1] = top;
eyeRight.vBottomRight.v[0] = right;
eyeRight.vBottomRight.v[1] = bottom;

vr::VREvent_Data_t temp;

vr::VRServerDriverHost()->SetDisplayProjectionRaw(device_index, eyeLeft, eyeRight);
vr::VRServerDriverHost()->VendorSpecificEvent(device_index, vr::VREvent_LensDistortionChanged, temp, 0.0f);
}


Expand Down
3 changes: 1 addition & 2 deletions vrto3d/src/hmd_device_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class StereoDisplayComponent : public vr::IVRDisplayComponent
void GetWindowBounds( int32_t *pnX, int32_t *pnY, uint32_t *pnWidth, uint32_t *pnHeight ) override;
StereoDisplayDriverConfiguration GetConfig();
void AdjustDepth(float delta, uint32_t device_index);
void AdjustConvergence(float delta);
void AdjustConvergence(float delta, uint32_t device_index);
float GetDepth();
float GetConvergence();

Expand Down Expand Up @@ -93,7 +93,6 @@ class MockControllerDeviceDriver : public vr::ITrackedDeviceServerDriver
std::array< vr::VRInputComponentHandle_t, MyComponent_MAX > my_input_handles_{};
std::atomic< bool > is_active_;
std::atomic< uint32_t > device_index_;
std::atomic< int > frame_number_;

std::thread pose_update_thread_;
};
4 changes: 2 additions & 2 deletions vrto3d/vrto3d/resources/settings/default.vrsettings
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"window_height": 1080,
"aspect_ratio": 1.77778,
"fov": 90.0,
"depth": 0.065,
"convergence": 0.0,
"depth": 0.5,
"convergence": 0.1,
"tab_enable": false,
"half_enable": true,
"ss_enable": false,
Expand Down

0 comments on commit 7889c07

Please sign in to comment.