Fix how the lens vector is incorporated, fix formatting
This commit is contained in:
parent
7c6d7ef84d
commit
88a97542e0
|
|
@ -26,57 +26,60 @@ vec4 quatMul(vec4 q1, vec4 q2) {
|
||||||
float s = q1.w;
|
float s = q1.w;
|
||||||
vec3 v = vec3(q2.x, q2.y, q2.z);
|
vec3 v = vec3(q2.x, q2.y, q2.z);
|
||||||
float t = q2.w;
|
float t = q2.w;
|
||||||
return vec4(s*v + t*u + cross(u, v), s*t - dot(u, v));
|
return vec4(s * v + t * u + cross(u, v), s * t - dot(u, v));
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 quatConj(vec4 q) {
|
vec4 quatConj(vec4 q) {
|
||||||
return vec4(-q.x, -q.y, -q.z, q.w);
|
return vec4(-q.x, -q.y, -q.z, q.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 applyQuaternionToVector(vec4 q, vec3 v) {
|
vec3 applyQuaternionToVector(vec4 q, vec3 v) {
|
||||||
vec4 p = quatMul(quatMul(q, vec4(v, 0)), quatConj(q));
|
vec4 p = quatMul(quatMul(q, vec4(v, 0)), quatConj(q));
|
||||||
return p.xyz;
|
return p.xyz;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int day_in_seconds = 24 * 60 * 60;
|
const int day_in_seconds = 24 * 60 * 60;
|
||||||
|
|
||||||
vec3 applyLookAhead(
|
vec3 applyLookAhead(
|
||||||
in vec3 position,
|
in vec3 position,
|
||||||
in vec3 velocity,
|
in vec3 velocity,
|
||||||
in vec3 accel,
|
in vec3 accel,
|
||||||
in float t,
|
in float t,
|
||||||
in float t_squared) {
|
in float t_squared
|
||||||
return position + velocity * t + 0.5 * accel * t_squared;
|
) {
|
||||||
|
return position + velocity * t + 0.5 * accel * t_squared;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 rateOfChange(
|
vec3 rateOfChange(
|
||||||
in vec3 v1,
|
in vec3 v1,
|
||||||
in vec3 v2,
|
in vec3 v2,
|
||||||
in float delta_time) {
|
in float delta_time
|
||||||
return (v1 - v2) / delta_time;
|
) {
|
||||||
|
return (v1 - v2) / delta_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PS_IMU_Transform(vec4 pos, vec2 texcoord, out vec4 color) {
|
void PS_IMU_Transform(vec4 pos, vec2 texcoord, out vec4 color) {
|
||||||
float texcoord_x_min = 0.0;
|
float texcoord_x_min = 0.0;
|
||||||
float texcoord_x_max = 1.0;
|
float texcoord_x_max = 1.0;
|
||||||
float lens_y_offset = 0.0;
|
float lens_y_offset = 0.0;
|
||||||
float lens_z_offset = 0.0;
|
float lens_z_offset = 0.0;
|
||||||
float aspect_ratio = stage_aspect_ratio;
|
float aspect_ratio = stage_aspect_ratio;
|
||||||
|
|
||||||
if (enabled && sbs_enabled) {
|
if(enabled && sbs_enabled) {
|
||||||
bool right_display = texcoord.x > 0.5;
|
bool right_display = texcoord.x > 0.5;
|
||||||
aspect_ratio /= 2;
|
aspect_ratio /= 2;
|
||||||
|
|
||||||
lens_y_offset = lens_distance_ratio / 3;
|
lens_y_offset = lens_distance_ratio / 3;
|
||||||
if (right_display) lens_y_offset = -lens_y_offset;
|
if(right_display)
|
||||||
if (sbs_content) {
|
lens_y_offset = -lens_y_offset;
|
||||||
|
if(sbs_content) {
|
||||||
// source video is SBS, left-half of the screen goes to the left lens, right-half to the right lens
|
// source video is SBS, left-half of the screen goes to the left lens, right-half to the right lens
|
||||||
if (right_display)
|
if(right_display)
|
||||||
texcoord_x_min = 0.5;
|
texcoord_x_min = 0.5;
|
||||||
else
|
else
|
||||||
texcoord_x_max = 0.5;
|
texcoord_x_max = 0.5;
|
||||||
}
|
}
|
||||||
if (!sbs_mode_stretched) {
|
if(!sbs_mode_stretched) {
|
||||||
// if the content isn't stretched, assume it's centered in the middle 50% of the screen
|
// if the content isn't stretched, assume it's centered in the middle 50% of the screen
|
||||||
texcoord_x_min = max(0.25, texcoord_x_min);
|
texcoord_x_min = max(0.25, texcoord_x_min);
|
||||||
texcoord_x_max = min(0.75, texcoord_x_max);
|
texcoord_x_max = min(0.75, texcoord_x_max);
|
||||||
|
|
@ -86,7 +89,7 @@ void PS_IMU_Transform(vec4 pos, vec2 texcoord, out vec4 color) {
|
||||||
texcoord.x = (texcoord.x - (right_display ? 0.5 : 0.0)) * 2;
|
texcoord.x = (texcoord.x - (right_display ? 0.5 : 0.0)) * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!enabled || show_banner) {
|
if(!enabled || show_banner) {
|
||||||
// vec2 banner_size = vec2(800.0 / ReShade::ScreenSize.x, 200.0 / ReShade::ScreenSize.y); // Assuming ScreenWidth and ScreenHeight are defined
|
// vec2 banner_size = vec2(800.0 / ReShade::ScreenSize.x, 200.0 / ReShade::ScreenSize.y); // Assuming ScreenWidth and ScreenHeight are defined
|
||||||
|
|
||||||
// if (show_banner &&
|
// if (show_banner &&
|
||||||
|
|
@ -103,26 +106,20 @@ void PS_IMU_Transform(vec4 pos, vec2 texcoord, out vec4 color) {
|
||||||
// }
|
// }
|
||||||
// } else {
|
// } else {
|
||||||
// adjust texcoord back to the range that describes where the content is displayed
|
// adjust texcoord back to the range that describes where the content is displayed
|
||||||
float texcoord_width = texcoord_x_max - texcoord_x_min;
|
float texcoord_width = texcoord_x_max - texcoord_x_min;
|
||||||
texcoord.x = texcoord.x * texcoord_width + texcoord_x_min;
|
texcoord.x = texcoord.x * texcoord_width + texcoord_x_min;
|
||||||
|
|
||||||
color = texture2D(uDesktopTexture, texcoord);
|
color = texture2D(uDesktopTexture, texcoord);
|
||||||
// }
|
// }
|
||||||
} else {
|
} else {
|
||||||
float lens_fov_z_offset_rads = atan(lens_z_offset/screen_distance);
|
float fov_y_half_width = tan(half_fov_y_rads);
|
||||||
float fov_z_pos = tan(half_fov_z_rads - lens_fov_z_offset_rads) * screen_distance;
|
float fov_y_width = fov_y_half_width * 2;
|
||||||
float fov_z_neg = -tan(half_fov_z_rads + lens_fov_z_offset_rads) * screen_distance;
|
float fov_z_half_width = tan(half_fov_z_rads);
|
||||||
float fov_z_width = fov_z_pos - fov_z_neg;
|
float fov_z_width = fov_z_half_width * 2;
|
||||||
|
float vec_y = -texcoord.x * fov_y_width + fov_y_half_width;
|
||||||
float lens_fov_y_offset_rads = atan(lens_y_offset/screen_distance);
|
float vec_z = -texcoord.y * fov_z_width + fov_z_half_width;
|
||||||
float fov_y_pos = tan(half_fov_y_rads - lens_fov_y_offset_rads) * screen_distance;
|
vec3 lens_vector = vec3(lens_distance_ratio, lens_y_offset, lens_z_offset);
|
||||||
float fov_y_neg = -tan(half_fov_y_rads + lens_fov_y_offset_rads) * screen_distance;
|
vec3 texcoord_vector = vec3(1.0, vec_y, vec_z);
|
||||||
float fov_y_width = fov_y_pos - fov_y_neg;
|
|
||||||
float vec_x = screen_distance;
|
|
||||||
float vec_y = -texcoord.x * fov_y_width + fov_y_pos;
|
|
||||||
float vec_z = -texcoord.y * fov_z_width + fov_z_pos;
|
|
||||||
vec3 texcoord_vector = vec3(vec_x, vec_y, vec_z);
|
|
||||||
vec3 lens_vector = vec3(lens_distance_ratio, lens_y_offset, lens_z_offset);
|
|
||||||
|
|
||||||
// then rotate the vector using each of the snapshots provided
|
// then rotate the vector using each of the snapshots provided
|
||||||
vec3 rotated_vector_t0 = applyQuaternionToVector(imu_quat_data[0], texcoord_vector);
|
vec3 rotated_vector_t0 = applyQuaternionToVector(imu_quat_data[0], texcoord_vector);
|
||||||
|
|
@ -146,31 +143,30 @@ void PS_IMU_Transform(vec4 pos, vec2 texcoord, out vec4 color) {
|
||||||
float look_ahead_ms_squared = pow(look_ahead_ms, 2);
|
float look_ahead_ms_squared = pow(look_ahead_ms, 2);
|
||||||
|
|
||||||
// apply most recent velocity and acceleration to most recent position to get a predicted position
|
// apply most recent velocity and acceleration to most recent position to get a predicted position
|
||||||
vec3 res = applyLookAhead(rotated_vector_t0, velocity_t0, accel_t0, look_ahead_ms, look_ahead_ms_squared);
|
vec3 res = applyLookAhead(rotated_vector_t0, velocity_t0, accel_t0, look_ahead_ms, look_ahead_ms_squared) -
|
||||||
|
rotated_lens_vector;
|
||||||
|
|
||||||
bool looking_behind = res.x < 0.0;
|
bool looking_behind = res.x < 0.0;
|
||||||
|
|
||||||
// divide all values by x to scale the magnitude so x is exactly 1, and multiply by the final display distance
|
// divide all values by x to scale the magnitude so x is exactly 1, and multiply by the final display distance
|
||||||
// so the vector is pointing at a coordinate on the screen
|
// so the vector is pointing at a coordinate on the screen
|
||||||
float display_distance = (sbs_enabled ? display_north_offset : 1.0) - rotated_lens_vector.x;
|
float display_distance = (sbs_enabled ? display_north_offset : 1.0) - rotated_lens_vector.x;
|
||||||
res *= display_distance/res.x;
|
res *= display_distance / res.x;
|
||||||
|
res += rotated_lens_vector;
|
||||||
// adjust x and y by how much our lens moved from its original offset
|
|
||||||
res += rotated_lens_vector - lens_vector;
|
|
||||||
|
|
||||||
// deconstruct the rotated and scaled vector back to a texcoord (just inverse operations of the first conversion
|
// deconstruct the rotated and scaled vector back to a texcoord (just inverse operations of the first conversion
|
||||||
// above)
|
// above)
|
||||||
texcoord.x = (fov_y_pos - res.y) / fov_y_width;
|
texcoord.x = (fov_y_half_width - res.y) / fov_y_width;
|
||||||
texcoord.y = (fov_z_pos - res.z) / fov_z_width;
|
texcoord.y = (fov_z_half_width - res.z) / fov_z_width;
|
||||||
|
|
||||||
// apply the screen offsets now
|
// apply the screen offsets now
|
||||||
float texcoord_width = texcoord_x_max - texcoord_x_min;
|
float texcoord_width = texcoord_x_max - texcoord_x_min;
|
||||||
texcoord.x = texcoord.x * texcoord_width + texcoord_x_min;
|
texcoord.x = texcoord.x * texcoord_width + texcoord_x_min;
|
||||||
|
|
||||||
if (looking_behind || texcoord.x < texcoord_x_min || texcoord.y < 0.0 || texcoord.x > texcoord_x_max || texcoord.y > 1.0 || texcoord.x <= 0.005 && texcoord.y <= 0.005) {
|
if(looking_behind || texcoord.x < texcoord_x_min || texcoord.y < 0.0 || texcoord.x > texcoord_x_max || texcoord.y > 1.0 || texcoord.x <= 0.005 && texcoord.y <= 0.005) {
|
||||||
color = vec4(0, 0, 0, 1);
|
color = vec4(0, 0, 0, 1);
|
||||||
} else {
|
} else {
|
||||||
color = texture2D(uDesktopTexture, texcoord);
|
color = texture2D(uDesktopTexture, texcoord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue