The open source OpenXR runtime
at prediction-2 52 lines 1.1 kB view raw
1// Copyright 2020-2023, Collabora Ltd. 2// 3// Author: Jakob Bornecrantz <jakob@collabora.com> 4// Author: Lubosz Sarnecki <lubosz.sarnecki@collabora.com> 5// 6// SPDX-License-Identifier: BSL-1.0 7 8#version 460 9 10 11layout (binding = 0, std140) uniform Config 12{ 13 vec4 post_transform; 14 vec4 to_tanget; 15 mat4 mvp; 16} ubo; 17 18layout (location = 0) out vec2 out_uv; 19 20out gl_PerVertex 21{ 22 vec4 gl_Position; 23}; 24 25vec2 pos[4] = { 26 vec2(0, 0), 27 vec2(0, 1), 28 vec2(1, 0), 29 vec2(1, 1), 30}; 31 32void main() 33{ 34 // We now get a unmodified UV position. 35 vec2 in_uv = pos[gl_VertexIndex % 4]; 36 37 // Turn the UV into tanget angle space. 38 vec2 pos = fma(in_uv, ubo.to_tanget.zw, ubo.to_tanget.xy); 39 40 // Flip to OpenXR coordinate system. 41 pos.y = -pos.y; 42 43 // Do timewarp by moving from a plane that is 1m in front of the 44 // origin of the projection layer into the view of the new position. 45 vec4 position = ubo.mvp * vec4(pos, -1.0f, 1.0f); 46 47 // To deal with OpenGL flip and sub image view. 48 vec2 uv = fma(in_uv, ubo.post_transform.zw, ubo.post_transform.xy); 49 50 gl_Position = position; 51 out_uv = uv; 52}