···185185 struct xrt_vec2 scale;
186186};
187187188188-static void
189189-calc_uv_to_tanangle(struct xrt_device *xdev, uint32_t view, struct xrt_normalized_rect *out_rect)
190190-{
191191- const struct xrt_fov fov = xdev->hmd->distortion.fov[view];
192192-193193- const double tan_left = tan(fov.angle_left);
194194- const double tan_right = tan(fov.angle_right);
195195-196196- const double tan_down = tan(fov.angle_down);
197197- const double tan_up = tan(fov.angle_up);
198198-199199- const double tan_width = tan_right - tan_left;
200200- const double tan_height = tan_up - tan_down;
201201-202202- /*
203203- * I do not know why we have to calculate the offsets like this, but
204204- * this one is the one that seems to work with what is currently in the
205205- * calc timewarp matrix function and the distortion shader. It works
206206- * with Index (unbalanced left and right angles) and WMR (unbalanced up
207207- * and down angles) so here it is. In so far it matches what the gfx
208208- * and non-timewarp compute pipeline produces.
209209- */
210210- const double tan_offset_x = ((tan_right + tan_left) - tan_width) / 2;
211211- const double tan_offset_y = (-(tan_up + tan_down) - tan_height) / 2;
212212-213213- struct xrt_normalized_rect transform = {
214214- .x = (float)tan_offset_x,
215215- .y = (float)tan_offset_y,
216216- .w = (float)tan_width,
217217- .h = (float)tan_height,
218218- };
219219-220220- *out_rect = transform;
221221-}
222222-223188XRT_CHECK_RESULT static VkResult
224189create_and_fill_in_distortion_buffer_for_view(struct vk_bundle *vk,
225190 struct xrt_device *xdev,
···326291327292 static_assert(RENDER_DISTORTION_NUM_IMAGES == 6, "Wrong number of distortion images!");
328293329329- calc_uv_to_tanangle(xdev, 0, &r->distortion.uv_to_tanangle[0]);
330330- calc_uv_to_tanangle(xdev, 1, &r->distortion.uv_to_tanangle[1]);
294294+ render_calc_uv_to_tangent_lengths_rect(&xdev->hmd->distortion.fov[0], &r->distortion.uv_to_tanangle[0]);
295295+ render_calc_uv_to_tangent_lengths_rect(&xdev->hmd->distortion.fov[1], &r->distortion.uv_to_tanangle[1]);
331296332297333298 /*
+18
src/xrt/compositor/render/render_interface.h
···8484 const struct xrt_pose *new_pose,
8585 struct xrt_matrix_4x4 *matrix);
86868787+/*!
8888+ * This function constructs a transformation in the form of a normalized rect
8989+ * that lets you go from a UV coordinate on a projection plane to the a point on
9090+ * the tangent plane. An example is that the UV coordinate `(0, 0)` would be
9191+ * transformed to `(tan(angle_left), tan(fov.angle_up))`. The tangent plane (aka
9292+ * tangent space) is really the tangent of the angle, aka length at unit distance.
9393+ *
9494+ * For the trivial case of an fov with 45 degrees angles, that is where the
9595+ * tangent length are `1` (aka `tan(45)`), the transformation would go from
9696+ * `[0 .. 1]` to `[-1 .. 1]` the expected returns are `x = -1`, `y = -1`,
9797+ * `w = 2` and `h = 2`.
9898+ *
9999+ * param fov The fov of the projection image.
100100+ * param[out] out_rect Transformation from UV to tangent lengths.
101101+ */
102102+void
103103+render_calc_uv_to_tangent_lengths_rect(const struct xrt_fov *fov, struct xrt_normalized_rect *out_rect);
104104+8710588106/*
89107 *
+42
src/xrt/compositor/render/render_util.c
···8080#endif
8181}
82828383+8484+/*
8585+ *
8686+ * 'Exported' functions.
8787+ *
8888+ */
8989+8390void
8491render_calc_time_warp_matrix(const struct xrt_pose *src_pose,
8592 const struct xrt_fov *src_fov,
···115122 matrix->v[i] = (float)result.v[i];
116123 }
117124}
125125+126126+void
127127+render_calc_uv_to_tangent_lengths_rect(const struct xrt_fov *fov, struct xrt_normalized_rect *out_rect)
128128+{
129129+ const struct xrt_fov copy = *fov;
130130+131131+ const double tan_left = tan(copy.angle_left);
132132+ const double tan_right = tan(copy.angle_right);
133133+134134+ const double tan_down = tan(copy.angle_down);
135135+ const double tan_up = tan(copy.angle_up);
136136+137137+ const double tan_width = tan_right - tan_left;
138138+ const double tan_height = tan_up - tan_down;
139139+140140+ /*
141141+ * I do not know why we have to calculate the offsets like this, but
142142+ * this one is the one that seems to work with what is currently in the
143143+ * calc timewarp matrix function and the distortion shader. It works
144144+ * with Index (unbalanced left and right angles) and WMR (unbalanced up
145145+ * and down angles) so here it is. In so far it matches what the gfx
146146+ * and non-timewarp compute pipeline produces.
147147+ */
148148+ const double tan_offset_x = ((tan_right + tan_left) - tan_width) / 2;
149149+ const double tan_offset_y = (-(tan_up + tan_down) - tan_height) / 2;
150150+151151+ struct xrt_normalized_rect transform = {
152152+ .x = (float)tan_offset_x,
153153+ .y = (float)tan_offset_y,
154154+ .w = (float)tan_width,
155155+ .h = (float)tan_height,
156156+ };
157157+158158+ *out_rect = transform;
159159+}