Monado OpenXR Runtime
Loading...
Searching...
No Matches
u_distortion_mesh.h
Go to the documentation of this file.
1// Copyright 2019, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Code to generate disortion meshes.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @author Moshi Turner <moshiturner@protonmail.com>
8 * @ingroup aux_distortion
9 */
10
11#pragma once
12
13#include "xrt/xrt_device.h"
14#include "xrt/xrt_defines.h"
15
16#include "util/u_distortion.h"
17
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23
24/*
25 *
26 * Panotools distortion
27 *
28 */
29
30/*!
31 * Values to create a distortion mesh from panotools values.
32 *
33 * @ingroup aux_distortion
34 */
36{
37 //! Panotools universal distortion k (reverse order from OpenHMD).
38 float distortion_k[5];
39 //! Panotools post distortion scale, <r, g, b>.
40 float aberration_k[3];
41 //! Panotools warp scale.
42 float scale;
43 //! Center of the lens.
45 //! Viewport size.
47};
48
49/*!
50 * Distortion correction implementation for Panotools distortion values.
51 *
52 * @ingroup aux_distortion
53 */
54void
55u_compute_distortion_panotools(struct u_panotools_values *values, float u, float v, struct xrt_uv_triplet *result);
56
57
58/*
59 *
60 * Vive, Vive Pro & Index distortion
61 *
62 */
63
64/*!
65 * Values to create a distortion mesh from Vive configuration values.
66 *
67 * @ingroup aux_distortion
68 */
70{
71 float aspect_x_over_y;
72 float grow_for_undistort;
73 struct xrt_vec2 intrinsic_focus;
74 struct xrt_vec2 intrinsic_center;
75
76 float undistort_r2_cutoff;
77
78 //! r/g/b
79 struct xrt_vec2 center[3];
80
81 //! r/g/b, a/b/c/d
82 float coefficients[3][4];
83};
84
85/*!
86 * Distortion correction implementation for the Vive, Vive Pro, Valve Index
87 * distortion values found in the HMD configuration.
88 *
89 * @ingroup aux_distortion
90 */
91void
92u_compute_distortion_vive(struct u_vive_values *values, float u, float v, struct xrt_uv_triplet *result);
93
94
95/*
96 *
97 * Cardboard mesh distortion parameters.
98 *
99 */
100
101/*!
102 * Distortion correction implementation for the Cardboard devices.
103 *
104 * @ingroup aux_distortion
105 */
106void
108 float u,
109 float v,
110 struct xrt_uv_triplet *result);
111
112
113/*
114 *
115 * Values for North Star 2D/Polynomial distortion correction.
116 *
117 */
118
120{
121 float x_coefficients_left[16];
122 float x_coefficients_right[16];
123 float y_coefficients_left[16];
124 float y_coefficients_right[16];
125 struct xrt_fov fov[2]; // left, right
126 float ipd;
127};
128
129/*!
130 * Distortion correction implementation for North Star 2D/Polynomial.
131 *
132 * @ingroup aux_distortion
133 */
134void
135u_compute_distortion_ns_p2d(struct u_ns_p2d_values *values, int view, float u, float v, struct xrt_uv_triplet *result);
136
137/*
138 *
139 * Values for Moshi Turner's North Star distortion correction.
140 *
141 */
143{
144 int number_of_ipds;
145 float *ipds;
146 int num_grid_points_u;
147 int num_grid_points_v;
148 struct xrt_vec2 *grid[2];
149 struct xrt_fov fov[2]; // left, right
150 float ipd;
151};
152
153/*!
154 * Moshi Turner's North Star distortion correction implementation
155 *
156 * @ingroup aux_distortion
157 */
158void
160 struct u_ns_meshgrid_values *values, int view, float u, float v, struct xrt_uv_triplet *result);
161
162/*
163 *
164 * Windows Mixed Reality distortion
165 *
166 */
167
169{
170 struct xrt_vec2_i32 display_size;
171
172 /* X/Y center of the distortion (pixels) */
173 struct xrt_vec2 eye_center;
174
175 /* k1,k2,k3 params for radial distortion as
176 * per the radial distortion model in
177 * https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html */
178 double k[3];
179};
180
182{
183 //! Inverse affine transform to move from (undistorted) pixels
184 //! to image plane / normalised image coordinates
186
187 //! tan(angle) FoV min/max for X and Y in the input texture
189 struct xrt_vec2 tex_y_range;
190
191 //! Hack values for WMR devices with weird distortions
192 int32_t y_offset;
193
194 struct u_poly_3k_distortion_values channels[3];
195};
196
197void
198u_compute_distortion_poly_3k(
199 struct u_poly_3k_eye_values *values, uint32_t view, float u, float v, struct xrt_uv_triplet *result);
200
201/*
202 * Compute the visible area bounds by calculating the X/Y limits of a
203 * crosshair through the distortion center, and back-project to the render FoV,
204 */
205void
206u_compute_distortion_bounds_poly_3k(const struct xrt_matrix_3x3 *inv_affine_xform,
207 struct u_poly_3k_distortion_values *values,
208 int view,
209 struct xrt_fov *out_fov,
210 struct xrt_vec2 *out_tex_x_range,
211 struct xrt_vec2 *out_tex_y_range);
212
213
214/*
215 *
216 * Rift-style distortion
217 *
218 */
219
220#define U_RIFT_CHROMATIC_ABBERATION_COUNT 4
221
223{
224 //! Size of the display, in meters.
226 //! The gap in meters between the two viewports. Zero in all real hardware.
228
229 //! Size of the display, in pixels.
231
232 //! The distance between the lens centers, in meters.
234 //! The distance from the top of the panel to lens centers, in meters.
236
237 //! The diameter of the lens
239};
240
242{
243 //! Distance from the lens surface
245
246 //! The catmull-rom coeffecients.
247 const float *k;
248 //! The amount of coeffecients in use.
250
251 //! Color fringing correction
252 float chromatic_abberation[U_RIFT_CHROMATIC_ABBERATION_COUNT];
253 //! The tan-angle radius the last entry of @ref k corresponds to.
254 float max_r;
255 //! How many metres across the panel one unit of tan-gent covers, measured at the centre of the lens.
257};
258
259/*!
260 * Oculus Rift distortion implementation.
261 */
262void
263u_compute_distortion_rift(const struct u_rift_panel *panel,
264 const struct u_rift_eye_profile *profile,
265 uint32_t view,
266 float u,
267 float v,
268 struct xrt_uv_triplet *result);
269
270
271/*
272 *
273 * None distortion
274 *
275 */
276
277/*!
278 * Helper function for none distortion devices.
279 *
280 * @ingroup aux_distortion
281 */
283u_distortion_mesh_none(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result);
284
285
286/*
287 *
288 * Mesh generation functions.
289 *
290 */
291
292/*!
293 * Given a @ref xrt_device generates meshes by calling
294 * xdev->compute_distortion(), populates `xdev->hmd_parts.distortion.mesh` &
295 * `xdev->hmd_parts.distortion.models`.
296 *
297 * @relatesalso xrt_device
298 * @ingroup aux_distortion
299 */
300void
302
303/*!
304 * Given a @ref xrt_device generates a no distortion mesh, populates
305 * `xdev->hmd_parts.distortion.mesh` & `xdev->hmd_parts.distortion.models`.
306 *
307 * @relatesalso xrt_device
308 * @ingroup aux_distortion
309 */
310void
312
313/*!
314 * Given a @ref xrt_device generates a no distortion mesh, also sets
315 * `xdev->compute_distortion()` and populates `xdev->hmd_parts.distortion.mesh`
316 * & `xdev->hmd_parts.distortion.models`.
317 *
318 * @relatesalso xrt_device
319 * @ingroup aux_distortion
320 */
321void
323
324
325#ifdef __cplusplus
326}
327#endif
void u_distortion_mesh_fill_in_none(struct xrt_device *xdev)
Given a xrt_device generates a no distortion mesh, populates xdev->hmd_parts.distortion....
Definition u_distortion_mesh.c:560
void u_distortion_mesh_fill_in_compute(struct xrt_device *xdev)
Given a xrt_device generates meshes by calling xdev->compute_distortion(), populates xdev->hmd_parts....
Definition u_distortion_mesh.c:598
void u_compute_distortion_cardboard(struct u_cardboard_distortion_values *values, float u, float v, struct xrt_uv_triplet *result)
Distortion correction implementation for the Cardboard devices.
Definition u_distortion_mesh.c:235
void u_distortion_mesh_set_none(struct xrt_device *xdev)
Given a xrt_device generates a no distortion mesh, also sets xdev->compute_distortion() and populates...
Definition u_distortion_mesh.c:574
void u_compute_distortion_ns_p2d(struct u_ns_p2d_values *values, int view, float u, float v, struct xrt_uv_triplet *result)
Distortion correction implementation for North Star 2D/Polynomial.
Definition u_distortion_mesh.c:291
xrt_result_t u_distortion_mesh_none(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result)
Helper function for none distortion devices.
Definition u_distortion_mesh.c:548
void u_compute_distortion_vive(struct u_vive_values *values, float u, float v, struct xrt_uv_triplet *result)
Distortion correction implementation for the Vive, Vive Pro, Valve Index distortion values found in t...
Definition u_distortion_mesh.c:129
void u_compute_distortion_ns_meshgrid(struct u_ns_meshgrid_values *values, int view, float u, float v, struct xrt_uv_triplet *result)
Moshi Turner's North Star distortion correction implementation.
Definition u_distortion_mesh.c:329
void u_compute_distortion_panotools(struct u_panotools_values *values, float u, float v, struct xrt_uv_triplet *result)
Distortion correction implementation for Panotools distortion values.
Definition u_distortion_mesh.c:198
enum xrt_result xrt_result_t
Result type used across Monado.
Values to create a distortion mesh from cardboard values.
Definition u_distortion.h:87
Definition u_distortion_mesh.h:143
Definition u_distortion_mesh.h:120
Values to create a distortion mesh from panotools values.
Definition u_distortion_mesh.h:36
struct xrt_vec2 viewport_size
Viewport size.
Definition u_distortion_mesh.h:46
float scale
Panotools warp scale.
Definition u_distortion_mesh.h:42
float distortion_k[5]
Panotools universal distortion k (reverse order from OpenHMD).
Definition u_distortion_mesh.h:38
float aberration_k[3]
Panotools post distortion scale, <r, g, b>.
Definition u_distortion_mesh.h:40
struct xrt_vec2 lens_center
Center of the lens.
Definition u_distortion_mesh.h:44
Definition u_distortion_mesh.h:169
Definition u_distortion_mesh.h:182
int32_t y_offset
Hack values for WMR devices with weird distortions.
Definition u_distortion_mesh.h:192
struct xrt_vec2 tex_x_range
tan(angle) FoV min/max for X and Y in the input texture
Definition u_distortion_mesh.h:188
struct xrt_matrix_3x3 inv_affine_xform
Inverse affine transform to move from (undistorted) pixels to image plane / normalised image coordina...
Definition u_distortion_mesh.h:185
Definition u_distortion_mesh.h:242
float chromatic_abberation[4]
Color fringing correction.
Definition u_distortion_mesh.h:252
float eye_relief_m
Distance from the lens surface.
Definition u_distortion_mesh.h:244
float max_r
The tan-angle radius the last entry of k corresponds to.
Definition u_distortion_mesh.h:254
const float * k
The catmull-rom coeffecients.
Definition u_distortion_mesh.h:247
int k_count
The amount of coeffecients in use.
Definition u_distortion_mesh.h:249
float meters_per_tan_angle
How many metres across the panel one unit of tan-gent covers, measured at the centre of the lens.
Definition u_distortion_mesh.h:256
Definition u_distortion_mesh.h:223
float eye_gap_m
The gap in meters between the two viewports. Zero in all real hardware.
Definition u_distortion_mesh.h:227
float lens_center_from_panel_top
The distance from the top of the panel to lens centers, in meters.
Definition u_distortion_mesh.h:235
float lens_center_separation_m
The distance between the lens centers, in meters.
Definition u_distortion_mesh.h:233
float lens_diameter_m
The diameter of the lens.
Definition u_distortion_mesh.h:238
struct xrt_vec2 size_m
Size of the display, in meters.
Definition u_distortion_mesh.h:225
struct xrt_vec2 size_px
Size of the display, in pixels.
Definition u_distortion_mesh.h:230
Values to create a distortion mesh from Vive configuration values.
Definition u_distortion_mesh.h:70
float coefficients[3][4]
r/g/b, a/b/c/d
Definition u_distortion_mesh.h:82
struct xrt_vec2 center[3]
r/g/b
Definition u_distortion_mesh.h:79
A single HMD or input device.
Definition xrt_device.h:357
Describes a projection matrix fov.
Definition xrt_defines.h:533
A tightly packed 3x3 matrix of floats.
Definition xrt_defines.h:580
Represents a uv triplet for distortion, basically just three xrt_vec2.
Definition xrt_defines.h:300
A 2 element vector with 32 bit integers.
Definition xrt_defines.h:383
A 2 element vector with single floats.
Definition xrt_defines.h:279
Code to handle distortion parameters and fov.
void u_compute_distortion_rift(const struct u_rift_panel *panel, const struct u_rift_eye_profile *profile, uint32_t view, float u, float v, struct xrt_uv_triplet *result)
Oculus Rift distortion implementation.
Definition u_distortion_mesh_rift.c:315
Common defines and enums for XRT.
Header defining an xrt display or controller device.