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

Commit

Permalink
Hologram: fix projection matrix
Browse files Browse the repository at this point in the history
Fix projection matrix for Vulkan clip space instead of patching things up
in VS.
  • Loading branch information
olvaffe authored and TonyBarbour committed Jan 27, 2016
1 parent 8feed9b commit 0dd3617
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
12 changes: 10 additions & 2 deletions demos/Hologram/Hologram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions demos/Hologram/Hologram.push_constant.vert
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 0 additions & 3 deletions demos/Hologram/Hologram.vert
Original file line number Diff line number Diff line change
Expand Up @@ -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.