Do things

This commit is contained in:
Bailey Harrison 2023-02-15 16:00:54 +00:00
parent 5890f94fe5
commit d76c8bb9cb
7 changed files with 45 additions and 17 deletions

View File

@ -2,6 +2,7 @@
layout(binding = 0) uniform UBO {
mat4 proj;
mat4 view;
} ubo;
layout( push_constant ) uniform Constants {

View File

@ -1,7 +1,8 @@
#version 450
layout(binding = 0) uniform UBO {
layout(set = 0, binding = 0) uniform UBO {
mat4 proj;
mat4 view;
} ubo;
layout( push_constant ) uniform Constants {

View File

@ -503,7 +503,7 @@ namespace engine {
}
// This is called not just on initialisation, but also when the window is resized.
static void createSwapchain(VkDevice device, VkPhysicalDevice physicalDevice, VmaAllocator allocator, std::vector<Queue> queues, SDL_Window* window, VkSurfaceKHR surface, bool vsync, Swapchain* swapchain)
static void createSwapchain(VkDevice device, VkPhysicalDevice physicalDevice, VmaAllocator allocator, std::vector<Queue> queues, SDL_Window* window, VkSurfaceKHR surface, bool vsync, bool useMSAA, Swapchain* swapchain)
{
[[maybe_unused]] VkResult res;
@ -636,7 +636,10 @@ namespace engine {
assert(res == VK_SUCCESS);
// Use multisample anti-aliasing
if (useMSAA)
swapchain->msaaSamples = getMaxSampleCount(physicalDevice);
else
swapchain->msaaSamples = VK_SAMPLE_COUNT_1_BIT;
// create depth buffer if old depth buffer is wrong size.
// Also do the same for the MSAA buffer.
@ -663,6 +666,8 @@ namespace engine {
* 0: color attachment with msaa samples,
* 1: depth attachment with msaa samples, used for fragment shading
* 2: present src (resolve) attachment with 1 sample, used for swapchain present
*
* if msaa is disabled, 0 is used for swapchain present and 2 is ignored
*/
VkAttachmentDescription colorAttachment{};
@ -673,7 +678,11 @@ namespace engine {
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
if (useMSAA) {
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
} else {
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
}
colorAttachmentRef.attachment = 0;
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
@ -709,7 +718,11 @@ namespace engine {
subpass.colorAttachmentCount = 1;
subpass.pColorAttachments = &colorAttachmentRef;
subpass.pDepthStencilAttachment = &depthAttachmentRef;
if (useMSAA) {
subpass.pResolveAttachments = &colorAttachmentResolveRef;
} else {
subpass.pResolveAttachments = nullptr;
}
VkSubpassDependency dependency{};
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
@ -723,7 +736,11 @@ namespace engine {
VkRenderPassCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
createInfo.attachmentCount = (uint32_t)attachments.size();
if (useMSAA) {
createInfo.attachmentCount = 3;
} else {
createInfo.attachmentCount = 2;
}
createInfo.pAttachments = attachments.data();
createInfo.subpassCount = 1;
createInfo.pSubpasses = &subpass;
@ -766,7 +783,12 @@ namespace engine {
VkFramebufferCreateInfo framebufferInfo{};
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
framebufferInfo.renderPass = swapchain->renderpass;
framebufferInfo.attachmentCount = (uint32_t)attachments.size();
if (useMSAA) {
framebufferInfo.attachmentCount = 3;
} else {
attachments[0] = swapchain->imageViews[i];
framebufferInfo.attachmentCount = 2;
}
framebufferInfo.pAttachments = attachments.data();
framebufferInfo.width = swapchain->extent.width;
framebufferInfo.height = swapchain->extent.height;
@ -1431,7 +1453,7 @@ namespace engine {
// Now make the swapchain
createSwapchain(pimpl->device, pimpl->physicalDevice, pimpl->allocator, pimpl->queues, window, pimpl->surface, pimpl->vsync, &pimpl->swapchain);
createSwapchain(pimpl->device, pimpl->physicalDevice, pimpl->allocator, pimpl->queues, window, pimpl->surface, pimpl->vsync, false, &pimpl->swapchain);
@ -1560,7 +1582,7 @@ namespace engine {
if (res == VK_ERROR_OUT_OF_DATE_KHR) {
// recreate swapchain
waitIdle();
createSwapchain(pimpl->device, pimpl->physicalDevice, pimpl->allocator, pimpl->queues, pimpl->window, pimpl->surface, pimpl->vsync, &pimpl->swapchain);
createSwapchain(pimpl->device, pimpl->physicalDevice, pimpl->allocator, pimpl->queues, pimpl->window, pimpl->surface, pimpl->vsync, false, &pimpl->swapchain);
return;
}
else {
@ -1693,7 +1715,7 @@ namespace engine {
if (res == VK_SUBOPTIMAL_KHR || res == VK_ERROR_OUT_OF_DATE_KHR) {
// recreate swapchain
waitIdle();
createSwapchain(pimpl->device, pimpl->physicalDevice, pimpl->allocator, pimpl->queues, pimpl->window, pimpl->surface, pimpl->vsync, &pimpl->swapchain);
createSwapchain(pimpl->device, pimpl->physicalDevice, pimpl->allocator, pimpl->queues, pimpl->window, pimpl->surface, pimpl->vsync, false, &pimpl->swapchain);
}
else {
assert(res == VK_SUCCESS);

View File

@ -36,7 +36,7 @@ namespace engine::resources {
}
vertFormat.stride = stride;
m_pipeline = m_gfx->createPipeline(vertPath, fragPath, vertFormat, sizeof(glm::mat4), alphaBlending, cullBackFace);
m_pipeline = m_gfx->createPipeline(vertPath, fragPath, vertFormat, sizeof(glm::mat4) * 2, alphaBlending, cullBackFace);
INFO("Loaded shader: {}, vertex attribs: {}", vertPath, vertFormat.attributeDescriptions.size());
}

View File

@ -58,7 +58,15 @@ namespace engine {
assert(r->mesh != nullptr);
assert(r->material->m_texture != nullptr);
gfx->updateUniformBuffer(r->material->getShader()->getPipeline(), &projMatrix, sizeof(projMatrix), 0);
struct {
glm::mat4 proj;
glm::mat4 view;
} uniform{};
uniform.proj = projMatrix;
uniform.view = viewMatrix;
gfx->updateUniformBuffer(r->material->getShader()->getPipeline(), &uniform, sizeof(glm::mat4) * 2, 0);
struct {
glm::mat4 model;
@ -84,7 +92,7 @@ namespace engine {
void RenderSystem::setCameraEntity(uint32_t entity)
{
{ m_camera.camEntity = entity; }
m_camera.camEntity = entity;
}
}

View File

@ -1,7 +1,5 @@
#include "window.hpp"
#include "log.hpp"
#include <iostream>
#include <stdexcept>

View File

@ -50,8 +50,6 @@ void CameraControllerSystem::onUpdate(float ts)
glm::vec3 dir = glm::normalize(glm::rotateY(glm::vec3{ 1.0f, 0.0f, 0.0f }, c->m_yaw) + glm::rotateY(glm::vec3{ 0.0f, 0.0f, 1.0f }, c->m_yaw));
const float slope = glm::dot(dir, norm);
INFO("slope: {}", slope);
bool isSliding = false;
if (c->justCollided) {