Use proper mipmaps for distortion shader

This commit is contained in:
Patrick Nicolas
2024-09-11 23:41:10 +02:00
parent 97aa8e3947
commit 50747d8fd4
6 changed files with 2894 additions and 377 deletions
+16 -1
View File
@@ -87,6 +87,12 @@ static double foveate(double a, double b, double λ, double c, double x)
// df⁻¹(x)/dx = 1/scale for x = c
}
static double foveate_lod(double a, double b, double /*λ*/, double /*c*/, double x)
{
// derivate of foveate * scale
return std::max(0., log2(1 / (cos(a * x + b) * cos(a * x + b))));
}
static std::tuple<float, float> solve_foveation(float λ, float c)
{
// Compute a and b for the foveation function such that:
@@ -150,17 +156,20 @@ bool wivrn_hmd::wivrn_hmd_compute_distortion(xrt_device * xdev, uint32_t view_in
// result is in the input coordinates (from the application)
const auto & param = ((wivrn_hmd *)xdev)->foveation_parameters[view_index];
xrt_vec2 out;
xrt_vec2 lod;
if (param.x.scale < 1)
{
u = 2 * u - 1;
out.x = foveate(param.x.a, param.x.b, param.x.scale, param.x.center, u);
lod.x = foveate_lod(param.x.a, param.x.b, param.x.scale, param.x.center, u);
out.x = std::clamp<float>((1 + out.x) / 2, 0, 1);
}
else
{
out.x = u;
lod.x = 0;
}
if (param.y.scale < 1)
@@ -168,15 +177,19 @@ bool wivrn_hmd::wivrn_hmd_compute_distortion(xrt_device * xdev, uint32_t view_in
v = 2 * v - 1;
out.y = foveate(param.y.a, param.y.b, param.y.scale, param.y.center, v);
lod.y = foveate_lod(param.y.a, param.y.b, param.y.scale, param.y.center, v);
out.y = std::clamp<float>((1 + out.y) / 2, 0, 1);
}
else
{
out.y = v;
lod.y = 0;
}
U_LOG_W("%f %f (%f %f)", lod.x, lod.y, u, v);
result->r = out;
result->g = out;
result->g = lod;
result->b = out;
return true;
@@ -216,7 +229,9 @@ wivrn_hmd::wivrn_hmd(std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx,
const auto config = configuration::read_user_configuration();
auto eye_width = info.recommended_eye_width;
eye_width = ((eye_width + 3) / 4) * 4;
auto eye_height = info.recommended_eye_height;
eye_height = ((eye_height + 3) / 4) * 4;
// Setup info.
hmd->view_count = 2;