client: support XR_META_foveation_eye_tracked (#1123)
This commit is contained in:
@@ -404,11 +404,6 @@ xrt_result_t compositor::layer_commit(xrt_graphics_sync_handle_t sync_handle)
|
||||
|
||||
cmd.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1);
|
||||
|
||||
if (session.get_info().eye_gaze)
|
||||
{
|
||||
auto now = os_monotonic_get_ns();
|
||||
session.add_tracking_request(device_id::EYE_GAZE, frame.rendering.desired_present_time_ns, now, now);
|
||||
}
|
||||
view_info.foveation = foveation.foveate(
|
||||
vk.device,
|
||||
cmd,
|
||||
@@ -815,14 +810,9 @@ void compositor::set_framerate(float hz)
|
||||
encoder->set_framerate(hz);
|
||||
}
|
||||
|
||||
void compositor::update_tracking(const from_headset::tracking & tracking)
|
||||
void compositor::update_foveation(const from_headset::foveation & packet)
|
||||
{
|
||||
foveation.update_tracking(tracking);
|
||||
}
|
||||
|
||||
void compositor::update_foveation_center_override(const from_headset::override_foveation_center & center)
|
||||
{
|
||||
foveation.update_foveation_center_override(center);
|
||||
foveation.update_foveation(packet);
|
||||
}
|
||||
|
||||
void compositor::resume()
|
||||
|
||||
@@ -188,8 +188,7 @@ public:
|
||||
void set_framerate(float hz);
|
||||
|
||||
void set_bitrate(uint32_t);
|
||||
void update_tracking(const from_headset::tracking &);
|
||||
void update_foveation_center_override(const from_headset::override_foveation_center &);
|
||||
void update_foveation(const from_headset::foveation &);
|
||||
|
||||
void resume();
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#include "foveation.h"
|
||||
|
||||
#include "driver/xrt_cast.h"
|
||||
#include "utils/wivrn_vk_bundle.h"
|
||||
#include "vk/specialization_constants.h"
|
||||
#include "wivrn_packets.h"
|
||||
@@ -261,32 +260,6 @@ static std::tuple<float, float> solve_foveation(float λ, float c)
|
||||
return {a, b(a)};
|
||||
}
|
||||
|
||||
static bool is_zero_quat(xrt_quat q)
|
||||
{
|
||||
return q.x == 0 and q.y == 0 and q.z == 0 and q.w == 0;
|
||||
}
|
||||
|
||||
static xrt_vec2 yaw_pitch(xrt_quat q)
|
||||
{
|
||||
if (is_zero_quat(q))
|
||||
return xrt_vec2{};
|
||||
|
||||
float sine_theta = std::clamp(-2.0f * (q.y * q.z - q.w * q.x), -1.0f, 1.0f);
|
||||
|
||||
float pitch = std::asin(sine_theta);
|
||||
|
||||
if (std::abs(sine_theta) > 0.99999f)
|
||||
{
|
||||
float scale = std::copysign(2.0, sine_theta);
|
||||
return {scale * std::atan2(-q.z, q.w), pitch};
|
||||
}
|
||||
|
||||
return {
|
||||
std::atan2(2.0f * (q.x * q.z + q.w * q.y),
|
||||
q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z),
|
||||
pitch};
|
||||
}
|
||||
|
||||
static float angles_to_center(float e, float l, float r)
|
||||
{
|
||||
e = tan(e);
|
||||
@@ -299,17 +272,6 @@ static float angles_to_center(float e, float l, float r)
|
||||
return res;
|
||||
}
|
||||
|
||||
static float convergence_angle(float distance, float eye_x, float gaze_yaw)
|
||||
{
|
||||
float target_x = distance * std::sin(gaze_yaw);
|
||||
float target_z = distance * std::cos(gaze_yaw);
|
||||
|
||||
float dx = target_x - eye_x;
|
||||
float dz = target_z;
|
||||
|
||||
return std::atan2(dx, dz);
|
||||
}
|
||||
|
||||
static void fill_param_2d(
|
||||
float c,
|
||||
size_t foveated_dim,
|
||||
@@ -357,11 +319,6 @@ namespace wivrn
|
||||
|
||||
void foveation::compute_params()
|
||||
{
|
||||
auto e = yaw_pitch(gaze);
|
||||
|
||||
if (manual_foveation.enabled)
|
||||
e.y = manual_foveation.pitch;
|
||||
|
||||
for (size_t i = 0; i < 2; ++i)
|
||||
{
|
||||
const auto & fov = last.fovs[i];
|
||||
@@ -369,9 +326,7 @@ void foveation::compute_params()
|
||||
size_t extent_w = std::abs(last.src[i].extent.w);
|
||||
if (foveated_size.width < extent_w)
|
||||
{
|
||||
auto distance = manual_foveation.enabled ? manual_foveation.distance : convergence_distance;
|
||||
auto angle_x = convergence_angle(distance, eye_x[i], -e.x);
|
||||
auto center = angles_to_center(angle_x, fov.angle_left, fov.angle_right);
|
||||
const float center = angles_to_center(last.foveation_angles[i].x, fov.angle_left, fov.angle_right);
|
||||
fill_param_2d(center, foveated_size.width, extent_w, params[i].x);
|
||||
}
|
||||
else
|
||||
@@ -380,13 +335,7 @@ void foveation::compute_params()
|
||||
size_t extent_h = std::abs(last.src[i].extent.h);
|
||||
if (foveated_size.height < extent_h)
|
||||
{
|
||||
auto angle_y = -e.y;
|
||||
if (is_zero_quat(gaze) and not manual_foveation.enabled)
|
||||
{
|
||||
// Natural gaze is not straight forward, adjust the angle
|
||||
angle_y += angle_offset;
|
||||
}
|
||||
auto center = angles_to_center(-angle_y, fov.angle_up, fov.angle_down);
|
||||
const float center = angles_to_center(last.foveation_angles[i].y, fov.angle_up, fov.angle_down);
|
||||
fill_param_2d(center, foveated_size.height, extent_h, params[i].y);
|
||||
}
|
||||
else
|
||||
@@ -396,11 +345,6 @@ void foveation::compute_params()
|
||||
|
||||
foveation::foveation(wivrn::vk_bundle & bundle, vk::Extent3D foveated_size) :
|
||||
foveated_size(foveated_size),
|
||||
// normal sight line is between 10° and 15° below horizontal
|
||||
// https://apps.dtic.mil/sti/tr/pdf/AD0758339.pdf pages 393-394
|
||||
// testing shows 10° looks better
|
||||
angle_offset(10 * M_PI / 180),
|
||||
convergence_distance(1 /* meter*/),
|
||||
gpu_buffer(
|
||||
bundle.device,
|
||||
{
|
||||
@@ -427,35 +371,10 @@ foveation::foveation(wivrn::vk_bundle & bundle, vk::Extent3D foveated_size) :
|
||||
bundle.name(descriptor_set, "foveation descriptor set");
|
||||
}
|
||||
|
||||
void foveation::update_tracking(const from_headset::tracking & tracking)
|
||||
void foveation::update_foveation(const from_headset::foveation & packet)
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
|
||||
const uint8_t orientation_ok = from_headset::pose_flags::orientation_valid | from_headset::pose_flags::orientation_tracked;
|
||||
|
||||
if (tracking.view_flags & XR_VIEW_STATE_POSITION_VALID_BIT)
|
||||
{
|
||||
eye_x[0] = tracking.views[0].pose.position.x;
|
||||
eye_x[1] = tracking.views[1].pose.position.x;
|
||||
}
|
||||
|
||||
for (const auto & pose: tracking.device_poses)
|
||||
{
|
||||
if (pose.device != device_id::EYE_GAZE)
|
||||
continue;
|
||||
|
||||
if ((pose.flags & orientation_ok) != orientation_ok)
|
||||
return;
|
||||
|
||||
gaze = xrt_cast(pose.pose.orientation);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void foveation::update_foveation_center_override(const from_headset::override_foveation_center & center)
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
manual_foveation = center;
|
||||
foveation_angles = packet.angles;
|
||||
}
|
||||
|
||||
static void fill_ubo(
|
||||
@@ -495,10 +414,6 @@ static bool operator==(const T & a, const T & b)
|
||||
static_assert(std::has_unique_object_representations_v<T>);
|
||||
return std::memcmp(&a, &b, sizeof(T)) == 0;
|
||||
}
|
||||
static bool operator==(const xrt_quat & a, const xrt_quat & b)
|
||||
{
|
||||
return a.x == b.x and a.y == b.y and a.z == b.z and a.w == b.w;
|
||||
}
|
||||
static bool operator==(const xrt_fov & a, const xrt_fov & b)
|
||||
{
|
||||
return a.angle_left == b.angle_left and a.angle_right == b.angle_right and a.angle_up == b.angle_up and a.angle_down == b.angle_down;
|
||||
@@ -516,21 +431,17 @@ void foveation::update_ubo(
|
||||
last.src[1] == src_rect[1] and
|
||||
last.fovs[0] == src_fov[0] and
|
||||
last.fovs[1] == src_fov[1] and
|
||||
(last.gaze == gaze or manual_foveation.enabled) and // Ignore the gaze if foveation center is overridden
|
||||
std::abs(last.eye_x[0] - eye_x[0]) < 0.0005 and
|
||||
std::abs(last.eye_x[1] - eye_x[1]) < 0.0005 and
|
||||
last.manual_foveation.enabled == manual_foveation.enabled and
|
||||
std::abs(last.manual_foveation.pitch - manual_foveation.pitch) < 0.0005 and
|
||||
std::abs(last.manual_foveation.distance - manual_foveation.distance) < 0.0005)
|
||||
last.foveation_angles[0].x == foveation_angles[0].x and
|
||||
last.foveation_angles[0].y == foveation_angles[0].y and
|
||||
last.foveation_angles[1].x == foveation_angles[1].x and
|
||||
last.foveation_angles[1].y == foveation_angles[1].y)
|
||||
return;
|
||||
|
||||
last = {
|
||||
.gaze = gaze,
|
||||
.flip_y = flip_y,
|
||||
.src = {src_rect[0], src_rect[1]},
|
||||
.fovs = {src_fov[0], src_fov[1]},
|
||||
.eye_x = {eye_x[0], eye_x[1]},
|
||||
.manual_foveation = manual_foveation,
|
||||
.foveation_angles = foveation_angles,
|
||||
};
|
||||
|
||||
compute_params();
|
||||
|
||||
@@ -39,15 +39,7 @@ class foveation
|
||||
std::mutex mutex;
|
||||
|
||||
const vk::Extent3D foveated_size; // per eye
|
||||
|
||||
// Natural vertical gaze angle
|
||||
const float angle_offset;
|
||||
// Optionally defined from environment variables
|
||||
const float convergence_distance;
|
||||
|
||||
float eye_x[2] = {}; // eye x position
|
||||
xrt_quat gaze = {};
|
||||
from_headset::override_foveation_center manual_foveation = {};
|
||||
std::array<XrVector2f, 2> foveation_angles = {};
|
||||
std::array<to_headset::foveation_parameter, 2> params;
|
||||
|
||||
buffer_allocation gpu_buffer;
|
||||
@@ -62,13 +54,10 @@ class foveation
|
||||
// parameters used for last computation
|
||||
struct P
|
||||
{
|
||||
xrt_quat gaze = {};
|
||||
bool flip_y = false;
|
||||
xrt_rect src[2] = {};
|
||||
xrt_fov fovs[2] = {};
|
||||
float eye_x[2] = {};
|
||||
|
||||
from_headset::override_foveation_center manual_foveation = {};
|
||||
std::array<XrVector2f, 2> foveation_angles = {};
|
||||
};
|
||||
P last;
|
||||
|
||||
@@ -82,11 +71,9 @@ class foveation
|
||||
std::array<xrt_fov, 2> src_fov);
|
||||
|
||||
public:
|
||||
foveation(wivrn::vk_bundle &,
|
||||
vk::Extent3D foveated_size);
|
||||
foveation(wivrn::vk_bundle &, vk::Extent3D foveated_size);
|
||||
|
||||
void update_tracking(const from_headset::tracking &);
|
||||
void update_foveation_center_override(const from_headset::override_foveation_center &);
|
||||
void update_foveation(const from_headset::foveation &);
|
||||
|
||||
std::array<to_headset::foveation_parameter, 2> foveate(
|
||||
vk::raii::Device &,
|
||||
|
||||
@@ -675,7 +675,6 @@ void wivrn_session::operator()(const from_headset::tracking & tracking)
|
||||
|
||||
if (eye_tracker)
|
||||
eye_tracker->update_tracking(tracking, offset);
|
||||
compositor.update_tracking(tracking);
|
||||
|
||||
if (android_face_tracker)
|
||||
android_face_tracker->update_tracking(tracking, offset);
|
||||
@@ -685,9 +684,9 @@ void wivrn_session::operator()(const from_headset::tracking & tracking)
|
||||
htc_face_tracker->update_tracking(tracking, offset);
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(from_headset::override_foveation_center && foveation_center)
|
||||
void wivrn_session::operator()(const from_headset::foveation & packet)
|
||||
{
|
||||
compositor.update_foveation_center_override(foveation_center);
|
||||
compositor.update_foveation(packet);
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(from_headset::derived_pose && derived)
|
||||
|
||||
@@ -166,6 +166,7 @@ public:
|
||||
void operator()(const from_headset::settings_changed &);
|
||||
void operator()(from_headset::handshake &&) {}
|
||||
void operator()(const from_headset::tracking &);
|
||||
void operator()(const from_headset::foveation &);
|
||||
void operator()(from_headset::derived_pose &&);
|
||||
void operator()(from_headset::hand_tracking &&);
|
||||
void operator()(from_headset::meta_body &&);
|
||||
@@ -182,7 +183,6 @@ public:
|
||||
void operator()(from_headset::user_presence_changed &&);
|
||||
void operator()(from_headset::refresh_rate_changed &&);
|
||||
void operator()(from_headset::stream_tab_changed &&);
|
||||
void operator()(from_headset::override_foveation_center &&);
|
||||
void operator()(from_headset::get_application_list &&);
|
||||
void operator()(const from_headset::start_app &);
|
||||
void operator()(const from_headset::get_running_applications &);
|
||||
|
||||
Reference in New Issue
Block a user