Skip to content

Commit

Permalink
Merge branch 'freeCam' into 'main'
Browse files Browse the repository at this point in the history
[REMIX-3342] Adds yaw and pitch keys to free cam navigation.

See merge request lightspeedrtx/dxvk-remix-nv!959
  • Loading branch information
MarkEHenderson committed Aug 16, 2024
2 parents 0bf8bb4 + 6e0d678 commit a2c207d
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 32 deletions.
13 changes: 12 additions & 1 deletion RtxOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Tables below enumerate all the options and their defaults set by RTX Remix. Note
|rtx.captureDebugImage|bool|False||
|rtx.captureEnableMultiframe|bool|False|Enables multi\-frame capturing\. THIS HAS NOT BEEN MAINTAINED AND SHOULD BE USED WITH EXTREME CAUTION\.|
|rtx.captureFramesPerSecond|int|24|Playback rate marked in the USD stage\.<br>Will eventually determine frequency with which game state is captured and written\. Currently every frame \-\- even those at higher frame rates \-\- are recorded\.|
|rtx.captureHotKey|unknown type|unknown type|Hotkey to trigger a capture without bringing up the menu\.|
|rtx.captureHotKey|unknown type|unknown type|Hotkey to trigger a capture without bringing up the menu\.<br>example override: 'rtx\.captureHotKey = CTRL, SHIFT, P'<br>Full list of key names available in src/util/util\_keybind\.h|
|rtx.captureInstances|bool|True|If true, an instanced snapshot of the game scene will be captured and exported to a USD stage, in addition to all meshes, textures, materials, etc\.<br>If false, only meshes, etc will be captured\.|
|rtx.captureMaxFrames|int|1|Max frames capturable when running a multi\-frame capture\. The capture can be toggled to completion manually\.|
|rtx.captureMeshBlendWeightDelta|float|0.01|Inter\-frame blend weight min delta warrants new time sample\.|
Expand Down Expand Up @@ -268,6 +268,17 @@ Tables below enumerate all the options and their defaults set by RTX Remix. Note
|rtx.forceCameraJitter|bool|False||
|rtx.forceCutoutAlpha|float|0.5|When an object is added to the cutout textures list it will have a cutout alpha mode forced on it, using this value for the alpha test\.<br>This is meant to improve the look of some legacy mode materials using low\-resolution textures and alpha blending instead of alpha cutout as this can cause blurry halos around edges due to the difficulty of handling this sort of blending in Remix\.<br>Such objects are generally better handled with actual replacement assets using fully opaque geometry replacements or alpha cutout with higher resolution textures, so this should only be relied on until proper replacements can be authored\.|
|rtx.forceHighResolutionReplacementTextures|bool|False|A flag to enable or disable forcing high resolution replacement textures\.<br>When enabled this mode overrides all other methods of mip calculation \(adaptive resolution and the minimum mipmap level\) and forces it to be 0 to always load in the highest quality of textures\.<br>This generally should not be used other than for various forms of debugging or visual comparisons as this mode will ignore any constraints on CPU or GPU memory which may starve the system or Remix of memory\.<br>Additionally, this setting must be set at startup and changing it will not take effect at runtime\.|
|rtx.freeCam.keyMoveBack|unknown type|unknown type|Move back in free camera mode\.<br>Example override: 'rtx\.rtx\.freeCam\.keyMoveBack = P'|
|rtx.freeCam.keyMoveDown|unknown type|unknown type|Move down in free camera mode\.<br>Example override: 'rtx\.rtx\.freeCam\.keyMoveDown = P'|
|rtx.freeCam.keyMoveFaster|unknown type|unknown type|Move faster in free camera mode\.<br>Example override: 'rtx\.rtx\.freeCam\.keyMoveForward = RSHIFT'|
|rtx.freeCam.keyMoveForward|unknown type|unknown type|Move forward in free camera mode\.<br>Example override: 'rtx\.rtx\.freeCam\.keyMoveForward = P'|
|rtx.freeCam.keyMoveLeft|unknown type|unknown type|Move left in free camera mode\.<br>Example override: 'rtx\.rtx\.freeCam\.keyMoveLeft = P'|
|rtx.freeCam.keyMoveRight|unknown type|unknown type|Move right in free camera mode\.<br>Example override: 'rtx\.rtx\.freeCam\.keyMoveRight = P'|
|rtx.freeCam.keyMoveUp|unknown type|unknown type|Move up in free camera mode\.<br>Example override: 'rtx\.rtx\.freeCam\.keyMoveUp = P'|
|rtx.freeCam.keyPitchDown|unknown type|unknown type|Pitch down in free camera mode\.<br>Example override: 'rtx\.rtx\.freeCam\.keyPitchDown = P'|
|rtx.freeCam.keyPitchUp|unknown type|unknown type|Pitch up in free camera mode\.<br>Example override: 'rtx\.rtx\.freeCam\.keyPitchUp = P'|
|rtx.freeCam.keyYawLeft|unknown type|unknown type|Yaw left in free camera mode\.<br>Example override: 'rtx\.rtx\.freeCam\.keyYawLeft = P'|
|rtx.freeCam.keyYawRight|unknown type|unknown type|Yaw right in free camera mode\.<br>Example override: 'rtx\.rtx\.freeCam\.keyYawRight = P'|
|rtx.freeCameraSpeed|float|200|Free camera speed \[GameUnits/s\]\.|
|rtx.froxelDepthSliceDistributionExponent|float|2|The exponent to use on depth values to nonlinearly distribute froxels away from the camera\. Higher values bias more froxels closer to the camera with 1 being linear\.|
|rtx.froxelDepthSlices|int|48|The z dimension of the froxel grid\. Must be constant after initialization\.|
Expand Down
10 changes: 7 additions & 3 deletions src/dxvk/imgui/dxvk_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3305,7 +3305,7 @@ namespace dxvk {
io.Fonts->SetTexID((ImTextureID)bd->FontDescriptorSet);
}

bool ImGUI::checkHotkeyState(const VirtualKeys& virtKeys) {
bool ImGUI::checkHotkeyState(const VirtualKeys& virtKeys, const bool allowContinuousPress) {
bool result = false;
if(virtKeys.size() > 0) {
auto& io = ImGui::GetIO();
Expand All @@ -3318,8 +3318,12 @@ namespace dxvk {
} else if(vk.val == VK_MENU) {
result = result && io.KeyAlt;
} else {
result =
result && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGui_ImplWin32_VirtualKeyToImGuiKey(vk.val)), false);
ImGuiKey key = ImGui::GetKeyIndex(ImGui_ImplWin32_VirtualKeyToImGuiKey(vk.val));
if (allowContinuousPress) {
result = result && ImGui::IsKeyDown(key);
} else {
result = result && ImGui::IsKeyPressed(key, false);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dxvk/imgui/dxvk_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace dxvk {

static void AddTexture(const XXH64_hash_t hash, const Rc<DxvkImageView>& imageView);
static void ReleaseTexture(const XXH64_hash_t hash);
static bool checkHotkeyState(const VirtualKeys& virtKeys);
static bool checkHotkeyState(const VirtualKeys& virtKeys, const bool allowContinuousPress = false);

void switchMenu(UIType type, bool force = false);

Expand Down
66 changes: 40 additions & 26 deletions src/dxvk/rtx_render/rtx_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "../../util/util_math.h"
#include "../../util/util_vector.h"
#include "../../util/util_matrix.h"
#include "../imgui/dxvk_imgui.h"
#include "rtx_camera.h"
#include <windows.h>
#include "rtx_options.h"
Expand Down Expand Up @@ -376,7 +377,6 @@ namespace dxvk
m_prevRunningTime = currTime;

// Perform custom camera controls logic
float speed = elapsedSec.count() * RtxOptions::Get()->getSceneScale() * freeCameraSpeed();

float moveLeftRight = 0;
float moveBackForward = 0;
Expand All @@ -388,10 +388,6 @@ namespace dxvk
}

if (!ImGui::GetIO().WantCaptureMouse && (flags & (int)RtCamera::UpdateFlag::UpdateFreeCamera) != 0) {
// Speed booster
if (ImGui::IsKeyDown(ImGuiKey_LeftShift)) {
speed *= 4;
}

// Typical WASD controls with EQ up-down
bool isKeyAvailable =
Expand All @@ -400,31 +396,49 @@ namespace dxvk
!ImGui::IsKeyDown(ImGuiKey_LeftAlt) &&
!ImGui::IsKeyDown(ImGuiKey_RightAlt) && !lockFreeCamera();

if (!isKeyAvailable) {
speed = 0;
}

float coordSystemScale = m_context.isLHS ? -1.f : 1.f;

if (ImGui::IsKeyDown(ImGuiKey_A)) {
moveLeftRight -= speed;
}
if (ImGui::IsKeyDown(ImGuiKey_D)) {
moveLeftRight += speed;
}
if (ImGui::IsKeyDown(ImGuiKey_W)) {
moveBackForward += coordSystemScale * speed;
}
if (ImGui::IsKeyDown(ImGuiKey_S)) {
moveBackForward -= coordSystemScale * speed;
}
if (ImGui::IsKeyDown(ImGuiKey_E)) {
moveDownUp += speed;
}
if (ImGui::IsKeyDown(ImGuiKey_Q)) {
moveDownUp -= speed;
if (isKeyAvailable) {
float speed = elapsedSec.count() * RtxOptions::Get()->getSceneScale() * freeCameraSpeed();
float angularSpeed = elapsedSec.count() * M_PI;
// Speed booster
if (dxvk::ImGUI::checkHotkeyState(RtxOptions::FreeCam::keyMoveFaster(), true)) {
speed *= 4;
}
if (dxvk::ImGUI::checkHotkeyState(RtxOptions::FreeCam::keyMoveForward(), true)) {
moveBackForward += coordSystemScale * speed;
}
if (dxvk::ImGUI::checkHotkeyState(RtxOptions::FreeCam::keyMoveLeft(), true)) {
moveLeftRight -= speed;
}
if (dxvk::ImGUI::checkHotkeyState(RtxOptions::FreeCam::keyMoveBack(), true)) {
moveBackForward -= coordSystemScale * speed;
}
if (dxvk::ImGUI::checkHotkeyState(RtxOptions::FreeCam::keyMoveRight(), true)) {
moveLeftRight += speed;
}
if (dxvk::ImGUI::checkHotkeyState(RtxOptions::FreeCam::keyMoveUp(), true)) {
moveDownUp += speed;
}
if (dxvk::ImGUI::checkHotkeyState(RtxOptions::FreeCam::keyMoveDown(), true)) {
moveDownUp -= speed;
}
if (dxvk::ImGUI::checkHotkeyState(RtxOptions::FreeCam::keyPitchDown(), true)) {
freeCameraPitchRef() -= angularSpeed;
}
if (dxvk::ImGUI::checkHotkeyState(RtxOptions::FreeCam::keyPitchUp(), true)) {
freeCameraPitchRef() += angularSpeed;
}
if (dxvk::ImGUI::checkHotkeyState(RtxOptions::FreeCam::keyYawLeft(), true)) {
freeCameraYawRef() += angularSpeed;
}
if (dxvk::ImGUI::checkHotkeyState(RtxOptions::FreeCam::keyYawRight(), true)) {
freeCameraYawRef() -= angularSpeed;
}
}



POINT p;
if (GetCursorPos(&p)) {
if (!lockFreeCamera() && ImGui::IsMouseDown(ImGuiMouseButton_Left) && ((m_mouseX != p.x) || (m_mouseY != p.y))) {
Expand Down
17 changes: 16 additions & 1 deletion src/dxvk/rtx_render/rtx_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,19 @@ namespace dxvk {
RTX_OPTION_ENV("rtx", bool, enableAlwaysCalculateAABB, false, "RTX_ALWAYS_CALCULATE_AABB", "Calculate an Axis Aligned Bounding Box for every draw call.\n This may improve instance tracking across frames for skinned and vertex shaded calls.");

// Camera
struct FreeCam{
RTX_OPTION("rtx.freeCam", VirtualKeys, keyMoveFaster, {VirtualKey{VK_LSHIFT}}, "Move faster in free camera mode.\nExample override: 'rtx.rtx.freeCam.keyMoveForward = RSHIFT'");
RTX_OPTION("rtx.freeCam", VirtualKeys, keyMoveForward, {VirtualKey{'W'}}, "Move forward in free camera mode.\nExample override: 'rtx.rtx.freeCam.keyMoveForward = P'");
RTX_OPTION("rtx.freeCam", VirtualKeys, keyMoveLeft, {VirtualKey{'A'}}, "Move left in free camera mode.\nExample override: 'rtx.rtx.freeCam.keyMoveLeft = P'");
RTX_OPTION("rtx.freeCam", VirtualKeys, keyMoveBack, {VirtualKey{'S'}}, "Move back in free camera mode.\nExample override: 'rtx.rtx.freeCam.keyMoveBack = P'");
RTX_OPTION("rtx.freeCam", VirtualKeys, keyMoveRight, {VirtualKey{'D'}}, "Move right in free camera mode.\nExample override: 'rtx.rtx.freeCam.keyMoveRight = P'");
RTX_OPTION("rtx.freeCam", VirtualKeys, keyMoveUp, {VirtualKey{'E'}}, "Move up in free camera mode.\nExample override: 'rtx.rtx.freeCam.keyMoveUp = P'");
RTX_OPTION("rtx.freeCam", VirtualKeys, keyMoveDown, {VirtualKey{'Q'}}, "Move down in free camera mode.\nExample override: 'rtx.rtx.freeCam.keyMoveDown = P'");
RTX_OPTION("rtx.freeCam", VirtualKeys, keyPitchDown, {VirtualKey{'I'}}, "Pitch down in free camera mode.\nExample override: 'rtx.rtx.freeCam.keyPitchDown = P'");
RTX_OPTION("rtx.freeCam", VirtualKeys, keyPitchUp, {VirtualKey{'K'}}, "Pitch up in free camera mode.\nExample override: 'rtx.rtx.freeCam.keyPitchUp = P'");
RTX_OPTION("rtx.freeCam", VirtualKeys, keyYawLeft, {VirtualKey{'J'}}, "Yaw left in free camera mode.\nExample override: 'rtx.rtx.freeCam.keyYawLeft = P'");
RTX_OPTION("rtx.freeCam", VirtualKeys, keyYawRight, {VirtualKey{'L'}}, "Yaw right in free camera mode.\nExample override: 'rtx.rtx.freeCam.keyYawRight = P'");
} freeCam;
RW_RTX_OPTION_ENV("rtx", bool, shakeCamera, false, "RTX_FREE_CAMERA_ENABLE_ANIMATION", "Enables animation of the free camera.");
RTX_OPTION_ENV("rtx", CameraAnimationMode, cameraAnimationMode, CameraAnimationMode::CameraShake_Pitch, "RTX_FREE_CAMERA_ANIMATION_MODE", "Free camera's animation mode.");
RTX_OPTION_ENV("rtx", int, cameraShakePeriod, 20, "RTX_FREE_CAMERA_ANIMATION_PERIOD", "Period of the free camera's animation.");
Expand Down Expand Up @@ -865,7 +878,9 @@ namespace dxvk {
"If false, the hotkeys behave as expected. The user must manually open the menu in order to change any values.");
inline static const VirtualKeys kDefaultCaptureMenuKeyBinds{VirtualKey{VK_CONTROL},VirtualKey{VK_SHIFT},VirtualKey{'Q'}};
RTX_OPTION("rtx", VirtualKeys, captureHotKey, kDefaultCaptureMenuKeyBinds,
"Hotkey to trigger a capture without bringing up the menu.");
"Hotkey to trigger a capture without bringing up the menu.\n"
"example override: 'rtx.captureHotKey = CTRL, SHIFT, P'\n"
"Full list of key names available in src/util/util_keybind.h");
RTX_OPTION("rtx", bool, captureInstances, true,
"If true, an instanced snapshot of the game scene will be captured and exported to a USD stage, in addition to all meshes, textures, materials, etc.\n"
"If false, only meshes, etc will be captured.");
Expand Down

0 comments on commit a2c207d

Please sign in to comment.