mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 12:46:12 +00:00
c/render: Add graphics layer shaders
This commit is contained in:
parent
bcccfc2f21
commit
73639f7b37
|
@ -95,6 +95,9 @@ if(XRT_HAVE_VULKAN)
|
|||
shaders/mesh.vert
|
||||
shaders/layer.frag
|
||||
shaders/layer.vert
|
||||
shaders/layer_projection.vert
|
||||
shaders/layer_quad.vert
|
||||
shaders/layer_shared.frag
|
||||
shaders/equirect1.vert
|
||||
shaders/equirect1.frag
|
||||
shaders/equirect2.vert
|
||||
|
|
|
@ -78,6 +78,12 @@ extern "C" {
|
|||
//! How many distortion images we have, one for each channel (3 rgb) and per view, total 6.
|
||||
#define RENDER_DISTORTION_NUM_IMAGES (6)
|
||||
|
||||
//! Which binding does the layer projection and quad shader has it's UBO on.
|
||||
#define RENDER_BINDING_LAYER_SHARED_UBO 0
|
||||
|
||||
//! Which binding does the shared layer fragment shader has it's source on.
|
||||
#define RENDER_BINDING_LAYER_SHARED_SRC 1
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
|
@ -144,6 +150,14 @@ struct render_shaders
|
|||
|
||||
VkShaderModule layer_vert;
|
||||
VkShaderModule layer_frag;
|
||||
|
||||
/*
|
||||
* New layer renderer.
|
||||
*/
|
||||
|
||||
VkShaderModule layer_projection_vert;
|
||||
VkShaderModule layer_quad_vert;
|
||||
VkShaderModule layer_shared_frag;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
@ -838,6 +852,26 @@ struct render_gfx_mesh_ubo_data
|
|||
struct xrt_matrix_4x4 transform;
|
||||
};
|
||||
|
||||
/*!
|
||||
* UBO data that is sent to the layer projection shader.
|
||||
*/
|
||||
struct render_gfx_layer_projection_data
|
||||
{
|
||||
struct xrt_normalized_rect post_transform;
|
||||
struct xrt_normalized_rect to_tanget;
|
||||
struct xrt_matrix_4x4 mvp;
|
||||
};
|
||||
|
||||
/*!
|
||||
* UBO data that is sent to the layer quad shader.
|
||||
*/
|
||||
struct render_gfx_layer_quad_data
|
||||
{
|
||||
struct xrt_normalized_rect post_transform;
|
||||
struct xrt_matrix_4x4 mvp;
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
* @name Drawing functions
|
||||
* @{
|
||||
|
|
|
@ -36,6 +36,9 @@
|
|||
#include "shaders/equirect1.vert.h"
|
||||
#include "shaders/equirect2.frag.h"
|
||||
#include "shaders/equirect2.vert.h"
|
||||
#include "shaders/layer_projection.vert.h"
|
||||
#include "shaders/layer_quad.vert.h"
|
||||
#include "shaders/layer_shared.frag.h"
|
||||
#include "shaders/mesh.frag.h"
|
||||
#include "shaders/mesh.vert.h"
|
||||
|
||||
|
@ -129,6 +132,10 @@ render_shaders_load(struct render_shaders *s, struct vk_bundle *vk)
|
|||
LOAD(layer_vert);
|
||||
LOAD(layer_frag);
|
||||
|
||||
LOAD(layer_projection_vert);
|
||||
LOAD(layer_quad_vert);
|
||||
LOAD(layer_shared_frag);
|
||||
|
||||
VK_DEBUG(vk, "Shaders loaded!");
|
||||
|
||||
return true;
|
||||
|
@ -154,5 +161,9 @@ render_shaders_close(struct render_shaders *s, struct vk_bundle *vk)
|
|||
D(ShaderModule, s->layer_vert);
|
||||
D(ShaderModule, s->layer_frag);
|
||||
|
||||
D(ShaderModule, s->layer_projection_vert);
|
||||
D(ShaderModule, s->layer_quad_vert);
|
||||
D(ShaderModule, s->layer_shared_frag);
|
||||
|
||||
VK_DEBUG(vk, "Shaders destroyed!");
|
||||
}
|
||||
|
|
49
src/xrt/compositor/shaders/layer_projection.vert
Normal file
49
src/xrt/compositor/shaders/layer_projection.vert
Normal file
|
@ -0,0 +1,49 @@
|
|||
// Copyright 2023, Collabora Ltd.
|
||||
// Author: Jakob Bornecrantz <jakob@collabora.com>
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
#version 460
|
||||
|
||||
|
||||
layout (binding = 0, std140) uniform Config
|
||||
{
|
||||
vec4 post_transform;
|
||||
vec4 to_tanget;
|
||||
mat4 mvp;
|
||||
} ubo;
|
||||
|
||||
layout (location = 0) out vec2 out_uv;
|
||||
|
||||
out gl_PerVertex
|
||||
{
|
||||
vec4 gl_Position;
|
||||
};
|
||||
|
||||
vec2 pos[4] = {
|
||||
vec2(0, 0),
|
||||
vec2(0, 1),
|
||||
vec2(1, 0),
|
||||
vec2(1, 1),
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
// We now get a unmodified UV position.
|
||||
vec2 in_uv = pos[gl_VertexIndex % 4];
|
||||
|
||||
// Turn the UV into tanget angle space.
|
||||
vec2 pos = fma(in_uv, ubo.to_tanget.zw, ubo.to_tanget.xy);
|
||||
|
||||
// Flip to OpenXR coordinate system.
|
||||
pos.y = -pos.y;
|
||||
|
||||
// Do timewarp by moving from a plane that is 1m in front of the
|
||||
// origin of the projection layer into the view of the new position.
|
||||
vec4 position = ubo.mvp * vec4(pos, -1.0f, 1.0f);
|
||||
|
||||
// To deal with OpenGL flip and sub image view.
|
||||
vec2 uv = fma(in_uv, ubo.post_transform.zw, ubo.post_transform.xy);
|
||||
|
||||
gl_Position = position;
|
||||
out_uv = uv;
|
||||
}
|
47
src/xrt/compositor/shaders/layer_quad.vert
Normal file
47
src/xrt/compositor/shaders/layer_quad.vert
Normal file
|
@ -0,0 +1,47 @@
|
|||
// Copyright 2023, Collabora Ltd.
|
||||
// Author: Jakob Bornecrantz <jakob@collabora.com>
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
#version 460
|
||||
|
||||
|
||||
layout (binding = 0, std140) uniform Config
|
||||
{
|
||||
vec4 post_transform;
|
||||
mat4 mvp;
|
||||
} ubo;
|
||||
|
||||
layout (location = 0) out vec2 out_uv;
|
||||
|
||||
out gl_PerVertex
|
||||
{
|
||||
vec4 gl_Position;
|
||||
};
|
||||
|
||||
vec2 pos[4] = {
|
||||
vec2(0, 0),
|
||||
vec2(0, 1),
|
||||
vec2(1, 0),
|
||||
vec2(1, 1),
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
// We now get a unmodified UV position.
|
||||
vec2 in_uv = pos[gl_VertexIndex % 4];
|
||||
|
||||
// Center the quad at origin.
|
||||
vec2 pos = in_uv - 0.5;
|
||||
|
||||
// Flip to OpenXR coordinate system.
|
||||
pos.y = -pos.y;
|
||||
|
||||
// Place quad in the center of the mvp, it will scale it.
|
||||
vec4 position = ubo.mvp * vec4(pos, 0.0f, 1.0f);
|
||||
|
||||
// To deal with OpenGL flip and sub image view.
|
||||
vec2 uv = fma(in_uv, ubo.post_transform.zw, ubo.post_transform.xy);
|
||||
|
||||
gl_Position = position;
|
||||
out_uv = uv;
|
||||
}
|
17
src/xrt/compositor/shaders/layer_shared.frag
Normal file
17
src/xrt/compositor/shaders/layer_shared.frag
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2023, Collabora Ltd.
|
||||
// Author: Jakob Bornecrantz <jakob@collabora.com>
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
#version 460
|
||||
|
||||
|
||||
layout (binding = 1) uniform sampler2D image;
|
||||
|
||||
layout (location = 0) in vec2 uv;
|
||||
layout (location = 0) out vec4 out_color;
|
||||
|
||||
|
||||
void main ()
|
||||
{
|
||||
out_color = texture(image, uv);
|
||||
}
|
Loading…
Reference in a new issue