Skip to content
This repository was archived by the owner on Jul 29, 2021. It is now read-only.

Commit 0dd3617

Browse files
olvaffeTonyBarbour
authored andcommitted
Hologram: fix projection matrix
Fix projection matrix for Vulkan clip space instead of patching things up in VS.
1 parent 8feed9b commit 0dd3617

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

demos/Hologram/Hologram.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,12 +585,20 @@ void Hologram::prepare_framebuffers(VkSwapchainKHR swapchain)
585585

586586
void Hologram::update_projection()
587587
{
588-
float aspect = static_cast<float>(extent_.width) / static_cast<float>(extent_.height);
589588
const glm::vec3 center(0.0f);
590589
const glm::vec3 up(0.f, 0.0f, 1.0f);
591590
const glm::mat4 view = glm::lookAt(eye_pos_, center, up);
591+
592+
float aspect = static_cast<float>(extent_.width) / static_cast<float>(extent_.height);
592593
const glm::mat4 projection = glm::perspective(0.4f, aspect, 0.1f, 100.0f);
593-
view_projection_ = projection * view;
594+
595+
// Vulkan clip space has inverted Y and half Z.
596+
const glm::mat4 clip(1.0f, 0.0f, 0.0f, 0.0f,
597+
0.0f, -1.0f, 0.0f, 0.0f,
598+
0.0f, 0.0f, 0.5f, 0.0f,
599+
0.0f, 0.0f, 0.5f, 1.0f);
600+
601+
view_projection_ = clip * projection * view;
594602
}
595603

596604
void Hologram::step_object(Object &obj, float obj_time, FrameData &data) const

demos/Hologram/Hologram.push_constant.vert

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ void main()
1313
{
1414
vec4 pos = matrices.mvp * vec4(in_pos, 1.0);
1515

16-
pos.y = -pos.y;
17-
pos.z = (pos.z + pos.w) / 2.0;
18-
1916
gl_Position = pos;
2017
color = in_color;
2118
}

demos/Hologram/Hologram.vert

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ void main()
1313
{
1414
vec4 pos = matrices.mvp * vec4(in_pos, 1.0);
1515

16-
pos.y = -pos.y;
17-
pos.z = (pos.z + pos.w) / 2.0;
18-
1916
gl_Position = pos;
2017
color = in_color;
2118
}

0 commit comments

Comments
 (0)