The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

c/render: Expose uv to tangent lengths function

Also document it better.

+62 -37
+2 -37
src/xrt/compositor/render/render_distortion.c
··· 185 185 struct xrt_vec2 scale; 186 186 }; 187 187 188 - static void 189 - calc_uv_to_tanangle(struct xrt_device *xdev, uint32_t view, struct xrt_normalized_rect *out_rect) 190 - { 191 - const struct xrt_fov fov = xdev->hmd->distortion.fov[view]; 192 - 193 - const double tan_left = tan(fov.angle_left); 194 - const double tan_right = tan(fov.angle_right); 195 - 196 - const double tan_down = tan(fov.angle_down); 197 - const double tan_up = tan(fov.angle_up); 198 - 199 - const double tan_width = tan_right - tan_left; 200 - const double tan_height = tan_up - tan_down; 201 - 202 - /* 203 - * I do not know why we have to calculate the offsets like this, but 204 - * this one is the one that seems to work with what is currently in the 205 - * calc timewarp matrix function and the distortion shader. It works 206 - * with Index (unbalanced left and right angles) and WMR (unbalanced up 207 - * and down angles) so here it is. In so far it matches what the gfx 208 - * and non-timewarp compute pipeline produces. 209 - */ 210 - const double tan_offset_x = ((tan_right + tan_left) - tan_width) / 2; 211 - const double tan_offset_y = (-(tan_up + tan_down) - tan_height) / 2; 212 - 213 - struct xrt_normalized_rect transform = { 214 - .x = (float)tan_offset_x, 215 - .y = (float)tan_offset_y, 216 - .w = (float)tan_width, 217 - .h = (float)tan_height, 218 - }; 219 - 220 - *out_rect = transform; 221 - } 222 - 223 188 XRT_CHECK_RESULT static VkResult 224 189 create_and_fill_in_distortion_buffer_for_view(struct vk_bundle *vk, 225 190 struct xrt_device *xdev, ··· 326 291 327 292 static_assert(RENDER_DISTORTION_NUM_IMAGES == 6, "Wrong number of distortion images!"); 328 293 329 - calc_uv_to_tanangle(xdev, 0, &r->distortion.uv_to_tanangle[0]); 330 - calc_uv_to_tanangle(xdev, 1, &r->distortion.uv_to_tanangle[1]); 294 + render_calc_uv_to_tangent_lengths_rect(&xdev->hmd->distortion.fov[0], &r->distortion.uv_to_tanangle[0]); 295 + render_calc_uv_to_tangent_lengths_rect(&xdev->hmd->distortion.fov[1], &r->distortion.uv_to_tanangle[1]); 331 296 332 297 333 298 /*
+18
src/xrt/compositor/render/render_interface.h
··· 84 84 const struct xrt_pose *new_pose, 85 85 struct xrt_matrix_4x4 *matrix); 86 86 87 + /*! 88 + * This function constructs a transformation in the form of a normalized rect 89 + * that lets you go from a UV coordinate on a projection plane to the a point on 90 + * the tangent plane. An example is that the UV coordinate `(0, 0)` would be 91 + * transformed to `(tan(angle_left), tan(fov.angle_up))`. The tangent plane (aka 92 + * tangent space) is really the tangent of the angle, aka length at unit distance. 93 + * 94 + * For the trivial case of an fov with 45 degrees angles, that is where the 95 + * tangent length are `1` (aka `tan(45)`), the transformation would go from 96 + * `[0 .. 1]` to `[-1 .. 1]` the expected returns are `x = -1`, `y = -1`, 97 + * `w = 2` and `h = 2`. 98 + * 99 + * param fov The fov of the projection image. 100 + * param[out] out_rect Transformation from UV to tangent lengths. 101 + */ 102 + void 103 + render_calc_uv_to_tangent_lengths_rect(const struct xrt_fov *fov, struct xrt_normalized_rect *out_rect); 104 + 87 105 88 106 /* 89 107 *
+42
src/xrt/compositor/render/render_util.c
··· 80 80 #endif 81 81 } 82 82 83 + 84 + /* 85 + * 86 + * 'Exported' functions. 87 + * 88 + */ 89 + 83 90 void 84 91 render_calc_time_warp_matrix(const struct xrt_pose *src_pose, 85 92 const struct xrt_fov *src_fov, ··· 115 122 matrix->v[i] = (float)result.v[i]; 116 123 } 117 124 } 125 + 126 + void 127 + render_calc_uv_to_tangent_lengths_rect(const struct xrt_fov *fov, struct xrt_normalized_rect *out_rect) 128 + { 129 + const struct xrt_fov copy = *fov; 130 + 131 + const double tan_left = tan(copy.angle_left); 132 + const double tan_right = tan(copy.angle_right); 133 + 134 + const double tan_down = tan(copy.angle_down); 135 + const double tan_up = tan(copy.angle_up); 136 + 137 + const double tan_width = tan_right - tan_left; 138 + const double tan_height = tan_up - tan_down; 139 + 140 + /* 141 + * I do not know why we have to calculate the offsets like this, but 142 + * this one is the one that seems to work with what is currently in the 143 + * calc timewarp matrix function and the distortion shader. It works 144 + * with Index (unbalanced left and right angles) and WMR (unbalanced up 145 + * and down angles) so here it is. In so far it matches what the gfx 146 + * and non-timewarp compute pipeline produces. 147 + */ 148 + const double tan_offset_x = ((tan_right + tan_left) - tan_width) / 2; 149 + const double tan_offset_y = (-(tan_up + tan_down) - tan_height) / 2; 150 + 151 + struct xrt_normalized_rect transform = { 152 + .x = (float)tan_offset_x, 153 + .y = (float)tan_offset_y, 154 + .w = (float)tan_width, 155 + .h = (float)tan_height, 156 + }; 157 + 158 + *out_rect = transform; 159 + }