Make rendering perspective correct
This commit is contained in:
parent
4378a90f74
commit
354487878e
2 changed files with 18 additions and 1 deletions
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
layout(location = 0) in vec3 inPosition;
|
layout(location = 0) in vec3 inPosition;
|
||||||
|
|
||||||
|
layout(push_constant) uniform PushConstants {
|
||||||
|
mat4 mvp;
|
||||||
|
} pushConstants;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = vec4(inPosition, 1.0);
|
gl_Position = pushConstants.mvp * vec4(inPosition, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "worldpass.h"
|
#include "worldpass.h"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
|
@ -19,6 +20,12 @@ void WorldPass::render(World& world, VkCommandBuffer commandBuffer) {
|
||||||
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_);
|
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_);
|
||||||
|
|
||||||
for(const auto& mesh : world.meshes) {
|
for(const auto& mesh : world.meshes) {
|
||||||
|
glm::mat4 mvp;
|
||||||
|
mvp = glm::perspective(glm::radians(75.0f), 640.0f / 480.0f, 0.1f, 100.0f);
|
||||||
|
mvp *= glm::lookAt(glm::vec3(2), glm::vec3(0), glm::vec3(0, -1, 0));
|
||||||
|
|
||||||
|
vkCmdPushConstants(commandBuffer, pipelineLayout_, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::mat4), &mvp);
|
||||||
|
|
||||||
VkDeviceSize offsets[] = {0};
|
VkDeviceSize offsets[] = {0};
|
||||||
vkCmdBindVertexBuffers(commandBuffer, 0, 1, &mesh->vertexBuffer, offsets);
|
vkCmdBindVertexBuffers(commandBuffer, 0, 1, &mesh->vertexBuffer, offsets);
|
||||||
vkCmdBindIndexBuffer(commandBuffer, mesh->indexBuffer, 0, VK_INDEX_TYPE_UINT32);
|
vkCmdBindIndexBuffer(commandBuffer, mesh->indexBuffer, 0, VK_INDEX_TYPE_UINT32);
|
||||||
|
@ -97,8 +104,14 @@ void WorldPass::createPipeline() {
|
||||||
dynamicState.dynamicStateCount = dynamicStates.size();
|
dynamicState.dynamicStateCount = dynamicStates.size();
|
||||||
dynamicState.pDynamicStates = dynamicStates.data();
|
dynamicState.pDynamicStates = dynamicStates.data();
|
||||||
|
|
||||||
|
VkPushConstantRange mvpPushConstant = {};
|
||||||
|
mvpPushConstant.size = sizeof(glm::mat4);
|
||||||
|
mvpPushConstant.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
|
||||||
|
|
||||||
VkPipelineLayoutCreateInfo pipelineLayoutInfo = {};
|
VkPipelineLayoutCreateInfo pipelineLayoutInfo = {};
|
||||||
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
||||||
|
pipelineLayoutInfo.pushConstantRangeCount = 1;
|
||||||
|
pipelineLayoutInfo.pPushConstantRanges = &mvpPushConstant;
|
||||||
|
|
||||||
vkCreatePipelineLayout(renderer_.getDevice(), &pipelineLayoutInfo, nullptr, &pipelineLayout_);
|
vkCreatePipelineLayout(renderer_.getDevice(), &pipelineLayoutInfo, nullptr, &pipelineLayout_);
|
||||||
|
|
||||||
|
|
Reference in a new issue