Permalink
Browse files

Hologram: fix projection matrix

Fix projection matrix for Vulkan clip space instead of patching things up
in VS.
  • Loading branch information...
olvaffe authored and Tony-LunarG committed Jan 26, 2016
1 parent 8feed9b commit 0dd36179880238014512c0637b0ba9f41febe803
Showing with 10 additions and 8 deletions.
  1. +10 −2 demos/Hologram/Hologram.cpp
  2. +0 −3 demos/Hologram/Hologram.push_constant.vert
  3. +0 −3 demos/Hologram/Hologram.vert
@@ -585,12 +585,20 @@ void Hologram::prepare_framebuffers(VkSwapchainKHR swapchain)
void Hologram::update_projection()
{
- float aspect = static_cast<float>(extent_.width) / static_cast<float>(extent_.height);
const glm::vec3 center(0.0f);
const glm::vec3 up(0.f, 0.0f, 1.0f);
const glm::mat4 view = glm::lookAt(eye_pos_, center, up);
+
+ float aspect = static_cast<float>(extent_.width) / static_cast<float>(extent_.height);
const glm::mat4 projection = glm::perspective(0.4f, aspect, 0.1f, 100.0f);
- view_projection_ = projection * view;
+
+ // Vulkan clip space has inverted Y and half Z.
+ const glm::mat4 clip(1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 0.5f, 0.0f,
+ 0.0f, 0.0f, 0.5f, 1.0f);
+
+ view_projection_ = clip * projection * view;
}
void Hologram::step_object(Object &obj, float obj_time, FrameData &data) const
@@ -13,9 +13,6 @@ void main()
{
vec4 pos = matrices.mvp * vec4(in_pos, 1.0);
- pos.y = -pos.y;
- pos.z = (pos.z + pos.w) / 2.0;
-
gl_Position = pos;
color = in_color;
}
@@ -13,9 +13,6 @@ void main()
{
vec4 pos = matrices.mvp * vec4(in_pos, 1.0);
- pos.y = -pos.y;
- pos.z = (pos.z + pos.w) / 2.0;
-
gl_Position = pos;
color = in_color;
}

0 comments on commit 0dd3617

Please sign in to comment.