comp: Add chromatic aberration correction to mesh

This commit is contained in:
pblack 2019-10-17 17:37:58 +13:00 committed by Jakob Bornecrantz
parent cd5153dead
commit e32902843c
5 changed files with 2098 additions and 1568 deletions

View file

@ -190,9 +190,9 @@ comp_distortion_init(struct comp_distortion *d,
d->distortion_model = distortion_model;
//! Add support for 3 channels as well.
//! Add support for 1 channels as well.
assert(parts->distortion.mesh.data == NULL ||
parts->distortion.mesh.num_uv_channels == 1);
parts->distortion.mesh.num_uv_channels == 3);
d->vbo_mesh.data = parts->distortion.mesh.data;
d->vbo_mesh.stride = parts->distortion.mesh.stride;
@ -385,23 +385,26 @@ comp_distortion_init_pipeline(struct comp_distortion *d,
fragment_shader_size = sizeof(shaders_vive_frag);
break;
case XRT_DISTORTION_MODEL_MESHUV:
// clang-format off
vertex_input_attribute_descriptions[0].binding = 0;
vertex_input_attribute_descriptions[0].location = 0;
vertex_input_attribute_descriptions[0].format =
VK_FORMAT_R32G32B32A32_SFLOAT;
vertex_input_attribute_descriptions[0].format = VK_FORMAT_R32G32B32A32_SFLOAT;
vertex_input_attribute_descriptions[0].offset = 0;
vertex_input_attribute_descriptions[1].binding = 0;
vertex_input_attribute_descriptions[1].location = 1;
vertex_input_attribute_descriptions[1].format = VK_FORMAT_R32G32B32A32_SFLOAT;
vertex_input_attribute_descriptions[1].offset = 16;
vertex_input_binding_description.binding = 0;
vertex_input_binding_description.inputRate =
VK_VERTEX_INPUT_RATE_VERTEX;
vertex_input_binding_description.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
vertex_input_binding_description.stride = d->vbo_mesh.stride;
vertex_input_state.vertexAttributeDescriptionCount = 1;
vertex_input_state.pVertexAttributeDescriptions =
vertex_input_attribute_descriptions;
vertex_input_state.vertexAttributeDescriptionCount = 2;
vertex_input_state.pVertexAttributeDescriptions = vertex_input_attribute_descriptions;
vertex_input_state.vertexBindingDescriptionCount = 1;
vertex_input_state.pVertexBindingDescriptions =
&vertex_input_binding_description;
vertex_input_state.pVertexBindingDescriptions = &vertex_input_binding_description;
// clang-format on
vertex_shader_code = shaders_mesh_vert;
vertex_shader_size = sizeof(shaders_mesh_vert);

View file

@ -28,23 +28,29 @@ layout (binding = 1, std140) uniform UBO
float WarpScale;
} ubo;
layout (location = 0) in vec2 inUV;
layout (location = 0) out vec4 outColor;
layout (location = 0) in vec2 in_ruv;
layout (location = 1) in vec2 in_guv;
layout (location = 2) in vec2 in_buv;
layout (location = 0) out vec4 out_color;
void main()
{
vec3 color = texture(texSampler, inUV).xyz;
float r = texture(texSampler, in_ruv).x;
float g = texture(texSampler, in_guv).y;
float b = texture(texSampler, in_buv).z;
#if 0
if (inUV.x < 0.0 || inUV.x > 1.0 || inUV.y < 0.0 || inUV.y > 1.0) {
if (in_ruv.x < 0.0 || in_ruv.x > 1.0 || in_ruv.y < 0.0 || in_ruv.y > 1.0) {
color = vec3(1.0, 0.0, 1.0);
} else {
float t = floor(inUV.x * 16) + floor(inUV.y * 16);
float t = floor(in_ruv.x * 16) + floor(in_ruv.y * 16);
bool isEven = mod(t, 2.0) == 0.0;
// color = color * float(isEven);
color = vec3(isEven, isEven, isEven);
}
#endif
outColor = vec4(color, 1.0);
out_color = vec4(r, g, b, 1.0);
}

View file

@ -5,8 +5,12 @@
#version 450
layout (location = 0) in vec4 pos_uv;
layout (location = 0) out vec2 out_uv;
layout (location = 0) in vec4 in_pos_ruv;
layout (location = 1) in vec4 in_guv_buv;
layout (location = 0) out vec2 out_ruv;
layout (location = 1) out vec2 out_guv;
layout (location = 2) out vec2 out_buv;
layout (binding = 2, std140) uniform ubo
{
@ -28,20 +32,27 @@ void main()
ubo_vp.rot.zw,
};
out_uv = pos_uv.zw;
vec2 pos = 2.0 * (in_pos_ruv.xy - vec2(0.5, 0.5));
vec2 pos = 2.0 * (pos_uv.xy - vec2(0.5, 0.5));
out_ruv = in_pos_ruv.zw;
out_guv = in_guv_buv.xy;
out_buv = in_guv_buv.zw;
// A hack for now.
if (ubo_vp.viewport_id == 1) {
pos.x = -pos.x;
out_uv.x = 1.0 - pos_uv.z;
out_ruv.x = 1.0 - out_ruv.x;
out_guv.x = 1.0 - out_guv.x;
out_buv.x = 1.0 - out_buv.x;
}
if (ubo_vp.flip_y) {
out_ruv.y = 1.0 - out_ruv.y;
out_guv.y = 1.0 - out_guv.y;
out_buv.y = 1.0 - out_buv.y;
}
pos = rot * pos;
gl_Position = vec4(pos, 0.0f, 1.0f);
if (ubo_vp.flip_y) {
out_uv.y = 1.0 - out_uv.y;
}
}

File diff suppressed because it is too large Load diff

View file

@ -759,10 +759,10 @@ psvr_device_create(struct hid_device_info *hmd_handle_info,
psvr->base.hmd->distortion.models = XRT_DISTORTION_MODEL_MESHUV;
psvr->base.hmd->distortion.preferred = XRT_DISTORTION_MODEL_MESHUV;
psvr->base.hmd->distortion.mesh.data = &psvr_both_uvs[0];
psvr->base.hmd->distortion.mesh.stride = sizeof(float) * 4;
psvr->base.hmd->distortion.mesh.num_uv_channels = 1;
psvr->base.hmd->distortion.mesh.stride = sizeof(float) * 8;
psvr->base.hmd->distortion.mesh.num_uv_channels = 3;
psvr->base.hmd->distortion.mesh.num_vertex =
ARRAY_SIZE(psvr_both_uvs) / 4;
ARRAY_SIZE(psvr_both_uvs) / 8;
psvr->fusion.rot.w = 1.0f;