From 17beaf8aa90e0af16c5fbd8e9a044066b18364dd Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sat, 23 Jan 2021 23:56:17 +0000 Subject: [PATCH] u/distortion: A stab in the dark to try and improve Index chromatic aberration --- src/xrt/auxiliary/util/u_distortion_mesh.c | 4 ++++ src/xrt/auxiliary/util/u_distortion_mesh.h | 4 ++-- src/xrt/drivers/ohmd/oh_device.c | 6 ++++++ src/xrt/drivers/survive/survive_driver.c | 7 +++---- src/xrt/drivers/vive/vive_config.c | 7 +++---- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/xrt/auxiliary/util/u_distortion_mesh.c b/src/xrt/auxiliary/util/u_distortion_mesh.c index ef56bd2bb..bf423851e 100644 --- a/src/xrt/auxiliary/util/u_distortion_mesh.c +++ b/src/xrt/auxiliary/util/u_distortion_mesh.c @@ -144,6 +144,10 @@ u_compute_distortion_vive(struct u_vive_values *values, float u, float v, struct float r2 = m_vec2_dot(texCoord, texCoord); float d_inv = ((r2 * val.coefficients[i][2] + val.coefficients[i][1]) * r2 + val.coefficients[i][0]) * r2 + 1.0; + + // The scaled part of DISTORT_DPOLY3_SCALED, seems to improve chromatic abberation. + d_inv -= val.coefficients[i][3]; + float d = 1.0 / d_inv; struct xrt_vec2 offset = {0.5, 0.5}; diff --git a/src/xrt/auxiliary/util/u_distortion_mesh.h b/src/xrt/auxiliary/util/u_distortion_mesh.h index d476b1902..a878b6668 100644 --- a/src/xrt/auxiliary/util/u_distortion_mesh.h +++ b/src/xrt/auxiliary/util/u_distortion_mesh.h @@ -75,8 +75,8 @@ struct u_vive_values //! r/g/b struct xrt_vec2 center[3]; - //! r/g/b, a/b/c - float coefficients[3][3]; + //! r/g/b, a/b/c/d + float coefficients[3][4]; }; /*! diff --git a/src/xrt/drivers/ohmd/oh_device.c b/src/xrt/drivers/ohmd/oh_device.c index 956703072..9c1f93a18 100644 --- a/src/xrt/drivers/ohmd/oh_device.c +++ b/src/xrt/drivers/ohmd/oh_device.c @@ -634,32 +634,38 @@ oh_device_create(ohmd_context *ctx, ohmd_device *dev, const char *prod) ohd->distortion.vive[0].coefficients[0][0] = -0.188236068524731f; ohd->distortion.vive[0].coefficients[0][1] = -0.221086205321053f; ohd->distortion.vive[0].coefficients[0][2] = -0.2537849057915209f; + ohd->distortion.vive[0].coefficients[0][3] = 0.0f; // blue ohd->distortion.vive[0].coefficients[1][0] = -0.07316590815739493f; ohd->distortion.vive[0].coefficients[1][1] = -0.02332400789561968f; ohd->distortion.vive[0].coefficients[1][2] = 0.02469959434698275f; + ohd->distortion.vive[0].coefficients[1][3] = 0.0f; // red ohd->distortion.vive[0].coefficients[2][0] = -0.02223805567703767f; ohd->distortion.vive[0].coefficients[2][1] = -0.04931309279533211f; ohd->distortion.vive[0].coefficients[2][2] = -0.07862881939243466f; + ohd->distortion.vive[0].coefficients[2][3] = 0.0f; // right // green ohd->distortion.vive[1].coefficients[0][0] = -0.1906209981894497f; ohd->distortion.vive[1].coefficients[0][1] = -0.2248896677207884f; ohd->distortion.vive[1].coefficients[0][2] = -0.2721364516782803f; + ohd->distortion.vive[1].coefficients[0][3] = 0.0f; // blue ohd->distortion.vive[1].coefficients[1][0] = -0.07346071902951497f; ohd->distortion.vive[1].coefficients[1][1] = -0.02189527566250131f; ohd->distortion.vive[1].coefficients[1][2] = 0.0581378652359256f; + ohd->distortion.vive[1].coefficients[1][3] = 0.0f; // red ohd->distortion.vive[1].coefficients[2][0] = -0.01755850332081247f; ohd->distortion.vive[1].coefficients[2][1] = -0.04517245633373419f; ohd->distortion.vive[1].coefficients[2][2] = -0.0928909347763f; + ohd->distortion.vive[1].coefficients[2][3] = 0.0f; // clang-format on ohd->base.compute_distortion = compute_distortion_vive; diff --git a/src/xrt/drivers/survive/survive_driver.c b/src/xrt/drivers/survive/survive_driver.c index 2b2d5292a..b90d3abb5 100644 --- a/src/xrt/drivers/survive/survive_driver.c +++ b/src/xrt/drivers/survive/survive_driver.c @@ -895,16 +895,15 @@ _json_get_int(const cJSON *json, const char *name) static void _get_color_coeffs(struct u_vive_values *values, const cJSON *coeffs, uint8_t eye, uint8_t channel) { - // this is 4 on index, all values populated - // assert(coeffs->length == 8); - // only 3 coeffs contain values + // For Vive this is 8 with only 3 populated. + // For Index this is 4 with all values populated. const cJSON *item = NULL; size_t i = 0; cJSON_ArrayForEach(item, coeffs) { values->coefficients[channel][i] = (float)item->valuedouble; ++i; - if (i == 3) { + if (i == 4) { break; } } diff --git a/src/xrt/drivers/vive/vive_config.c b/src/xrt/drivers/vive/vive_config.c index 9f4f8c78a..c7e58b3d1 100644 --- a/src/xrt/drivers/vive/vive_config.c +++ b/src/xrt/drivers/vive/vive_config.c @@ -30,16 +30,15 @@ static void _get_color_coeffs(struct u_vive_values *values, const cJSON *coeffs, uint8_t eye, uint8_t channel) { - // this is 4 on index, all values populated - // assert(coeffs->length == 8); - // only 3 coeffs contain values + // For Vive this is 8 with only 3 populated. + // For Index this is 4 with all values populated. const cJSON *item = NULL; size_t i = 0; cJSON_ArrayForEach(item, coeffs) { values->coefficients[channel][i] = (float)item->valuedouble; ++i; - if (i == 3) { + if (i == 4) { break; } }