From ee3a4d6073421fd9e17e832dc9d10e151e6029ea Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Sun, 25 Sep 2022 23:08:03 -0400 Subject: [PATCH] remove color vertex data, mipmapping --- engine/xe_device.cpp | 16 +++++ engine/xe_device.hpp | 8 ++- engine/xe_image.cpp | 120 +++++++++++++++++++++++++++++++-- engine/xe_image.hpp | 4 ++ engine/xe_model.cpp | 9 +-- engine/xe_render_system.cpp | 29 +------- engine/xe_render_system.hpp | 3 - res/image/dirt.jpg | Bin 0 -> 5956 bytes res/shaders/simple_shader.frag | 2 +- res/shaders/simple_shader.vert | 7 +- src/chunk.cpp | 5 +- src/chunk.hpp | 6 +- src/first_app.cpp | 21 +----- src/simple_renderer.cpp | 7 +- src/simple_renderer.hpp | 7 -- 15 files changed, 158 insertions(+), 86 deletions(-) create mode 100644 res/image/dirt.jpg diff --git a/engine/xe_device.cpp b/engine/xe_device.cpp index d6d0713..f602e18 100755 --- a/engine/xe_device.cpp +++ b/engine/xe_device.cpp @@ -121,6 +121,7 @@ void Device::pickPhysicalDevice() { for (const auto &device : devices) { if (isDeviceSuitable(device)) { physicalDevice = device; + msaaSamples = getMaxUsableSampleCount(); break; } } @@ -133,6 +134,21 @@ void Device::pickPhysicalDevice() { std::cout << "Physical device: " << properties.deviceName << std::endl; } +VkSampleCountFlagBits Device::getMaxUsableSampleCount() { + VkPhysicalDeviceProperties physicalDeviceProperties; + vkGetPhysicalDeviceProperties(physicalDevice, &physicalDeviceProperties); + + VkSampleCountFlags counts = physicalDeviceProperties.limits.framebufferColorSampleCounts & physicalDeviceProperties.limits.framebufferDepthSampleCounts; + if (counts & VK_SAMPLE_COUNT_64_BIT) { return VK_SAMPLE_COUNT_64_BIT; } + if (counts & VK_SAMPLE_COUNT_32_BIT) { return VK_SAMPLE_COUNT_32_BIT; } + if (counts & VK_SAMPLE_COUNT_16_BIT) { return VK_SAMPLE_COUNT_16_BIT; } + if (counts & VK_SAMPLE_COUNT_8_BIT) { return VK_SAMPLE_COUNT_8_BIT; } + if (counts & VK_SAMPLE_COUNT_4_BIT) { return VK_SAMPLE_COUNT_4_BIT; } + if (counts & VK_SAMPLE_COUNT_2_BIT) { return VK_SAMPLE_COUNT_2_BIT; } + + return VK_SAMPLE_COUNT_1_BIT; +} + void Device::createLogicalDevice() { QueueFamilyIndices indices = findQueueFamilies(physicalDevice); diff --git a/engine/xe_device.hpp b/engine/xe_device.hpp index 42b0751..9825ff2 100755 --- a/engine/xe_device.hpp +++ b/engine/xe_device.hpp @@ -42,6 +42,7 @@ class Device { VkSurfaceKHR surface() { return surface_; } VkQueue graphicsQueue() { return graphicsQueue_; } VkQueue presentQueue() { return presentQueue_; } + VkPhysicalDeviceProperties getProperties() { return properties; } SwapChainSupportDetails getSwapChainSupport() { return querySwapChainSupport(physicalDevice); } uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties); @@ -56,11 +57,11 @@ class Device { VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &bufferMemory); + VkCommandBuffer beginSingleTimeCommands(); void endSingleTimeCommands(VkCommandBuffer commandBuffer); void copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size); - void copyBufferToImage( - VkBuffer buffer, VkImage image, uint32_t width, uint32_t height, uint32_t layerCount); + void copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height, uint32_t layerCount); void createImageWithInfo( const VkImageCreateInfo &imageInfo, @@ -86,6 +87,7 @@ class Device { void hasGflwRequiredInstanceExtensions(); bool checkDeviceExtensionSupport(VkPhysicalDevice device); SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device); + VkSampleCountFlagBits getMaxUsableSampleCount(); VkInstance instance; VkDebugUtilsMessengerEXT debugMessenger; @@ -98,6 +100,8 @@ class Device { VkQueue graphicsQueue_; VkQueue presentQueue_; + VkSampleCountFlagBits msaaSamples = VK_SAMPLE_COUNT_1_BIT; + const std::vector validationLayers = {"VK_LAYER_KHRONOS_validation"}; const std::vector deviceExtensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_MAINTENANCE1_EXTENSION_NAME}; }; diff --git a/engine/xe_image.cpp b/engine/xe_image.cpp index 8b6065c..419cbdd 100644 --- a/engine/xe_image.cpp +++ b/engine/xe_image.cpp @@ -13,9 +13,11 @@ namespace xe { Image::Image(Device &xeDevice, const std::string &filename) : xeDevice{xeDevice} { createTextureImage(filename); createTextureImageView(); + createTextureSampler(); } Image::~Image() { + vkDestroySampler(xeDevice.device(), textureSampler, nullptr); vkDestroyImage(xeDevice.device(), textureImage, nullptr); vkFreeMemory(xeDevice.device(), textureImageMemory, nullptr); vkDestroyImageView(xeDevice.device(), textureImageView, nullptr); @@ -25,6 +27,7 @@ void Image::createTextureImage(const std::string &filename) { int texWidth, texHeight, texChannels; stbi_uc* pixels = stbi_load(filename.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha); VkDeviceSize imageSize = texWidth * texHeight * 4; + mipLevels = static_cast(std::floor(std::log2(std::max(texWidth, texHeight)))) + 1; if (!pixels) { throw std::runtime_error("failed to load texture: " + filename); @@ -48,15 +51,17 @@ void Image::createTextureImage(const std::string &filename) { stbi_image_free(pixels); - createImage(texWidth, texHeight, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, textureImage, textureImageMemory); + createImage(texWidth, texHeight, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, textureImage, textureImageMemory); transitionImageLayout(textureImage, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); copyBufferToImage(stagingBuffer, textureImage, static_cast(texWidth), static_cast(texHeight)); - transitionImageLayout(textureImage, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + // transitionImageLayout(textureImage, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); vkDestroyBuffer(xeDevice.device(), stagingBuffer, nullptr); vkFreeMemory(xeDevice.device(), stagingBufferMemory, nullptr); + generateMipmaps(textureImage, VK_FORMAT_R8G8B8A8_SRGB, texWidth, texHeight, mipLevels); + } void Image::createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory) { @@ -67,7 +72,7 @@ void Image::createImage(uint32_t width, uint32_t height, VkFormat format, VkImag imageInfo.extent.width = width; imageInfo.extent.height = height; imageInfo.extent.depth = 1; - imageInfo.mipLevels = 1; + imageInfo.mipLevels = mipLevels; imageInfo.arrayLayers = 1; imageInfo.format = format; imageInfo.tiling = tiling; @@ -107,7 +112,7 @@ void Image::transitionImageLayout(VkImage image, VkFormat format, VkImageLayout barrier.image = image; barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; barrier.subresourceRange.baseMipLevel = 0; - barrier.subresourceRange.levelCount = 1; + barrier.subresourceRange.levelCount = mipLevels; barrier.subresourceRange.baseArrayLayer = 0; barrier.subresourceRange.layerCount = 1; @@ -142,6 +147,86 @@ void Image::transitionImageLayout(VkImage image, VkFormat format, VkImageLayout xeDevice.endSingleTimeCommands(commandBuffer); } +void Image::generateMipmaps(VkImage image, VkFormat imageFormat, int32_t texWidth, int32_t texHeight, uint32_t mipLevels) { + + VkCommandBuffer commandBuffer = xeDevice.beginSingleTimeCommands(); + + VkImageMemoryBarrier barrier{}; + barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barrier.image = image; + barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + barrier.subresourceRange.baseArrayLayer = 0; + barrier.subresourceRange.layerCount = 1; + barrier.subresourceRange.levelCount = 1; + + int32_t mipWidth = texWidth; + int32_t mipHeight = texHeight; + + for (uint32_t i = 1; i < mipLevels; i++) { + barrier.subresourceRange.baseMipLevel = i - 1; + barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; + barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; + + vkCmdPipelineBarrier(commandBuffer, + VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, + 0, nullptr, + 0, nullptr, + 1, &barrier); + + VkImageBlit blit{}; + blit.srcOffsets[0] = {0, 0, 0}; + blit.srcOffsets[1] = {mipWidth, mipHeight, 1}; + blit.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + blit.srcSubresource.mipLevel = i - 1; + blit.srcSubresource.baseArrayLayer = 0; + blit.srcSubresource.layerCount = 1; + blit.dstOffsets[0] = {0, 0, 0}; + blit.dstOffsets[1] = { mipWidth > 1 ? mipWidth / 2 : 1, mipHeight > 1 ? mipHeight / 2 : 1, 1 }; + blit.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + blit.dstSubresource.mipLevel = i; + blit.dstSubresource.baseArrayLayer = 0; + blit.dstSubresource.layerCount = 1; + + vkCmdBlitImage(commandBuffer, + image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + 1, &blit, + VK_FILTER_LINEAR); + + barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; + barrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + barrier.srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT; + barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; + + vkCmdPipelineBarrier(commandBuffer, + VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, + 0, nullptr, + 0, nullptr, + 1, &barrier); + + if (mipWidth > 1) mipWidth /= 2; + if (mipHeight > 1) mipHeight /= 2; + } + + barrier.subresourceRange.baseMipLevel = mipLevels - 1; + barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + barrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; + + vkCmdPipelineBarrier(commandBuffer, + VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, + 0, nullptr, + 0, nullptr, + 1, &barrier); + + xeDevice.endSingleTimeCommands(commandBuffer); + } + void Image::copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height) { VkCommandBuffer commandBuffer = xeDevice.beginSingleTimeCommands(); @@ -173,7 +258,7 @@ void Image::createTextureImageView() { viewInfo.format = VK_FORMAT_R8G8B8A8_SRGB; viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; viewInfo.subresourceRange.baseMipLevel = 0; - viewInfo.subresourceRange.levelCount = 1; + viewInfo.subresourceRange.levelCount = mipLevels; viewInfo.subresourceRange.baseArrayLayer = 0; viewInfo.subresourceRange.layerCount = 1; @@ -182,4 +267,29 @@ void Image::createTextureImageView() { } } +void Image::createTextureSampler() { + + VkSamplerCreateInfo samplerInfo{}; + samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + samplerInfo.magFilter = VK_FILTER_LINEAR; + samplerInfo.minFilter = VK_FILTER_LINEAR; + samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; + samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; + samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; + samplerInfo.anisotropyEnable = VK_TRUE; + samplerInfo.maxAnisotropy = xeDevice.getProperties().limits.maxSamplerAnisotropy; + samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; + samplerInfo.unnormalizedCoordinates = VK_FALSE; + samplerInfo.compareEnable = VK_FALSE; + samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS; + samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; + samplerInfo.minLod = 0.0f; + samplerInfo.maxLod = static_cast(mipLevels); + samplerInfo.mipLodBias = 0.0f; + + if (vkCreateSampler(xeDevice.device(), &samplerInfo, nullptr, &textureSampler) != VK_SUCCESS) { + throw std::runtime_error("failed to create texture sampler!"); + } +} + } \ No newline at end of file diff --git a/engine/xe_image.hpp b/engine/xe_image.hpp index a8e50ba..29f5d58 100644 --- a/engine/xe_image.hpp +++ b/engine/xe_image.hpp @@ -21,12 +21,16 @@ class Image { void createTextureImage(const std::string &filename); void createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory); void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout); + void generateMipmaps(VkImage image, VkFormat imageFormat, int32_t texWidth, int32_t texHeight, uint32_t mipLevels); void copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height); void createTextureImageView(); + void createTextureSampler(); Device &xeDevice; + uint32_t mipLevels; VkImage textureImage; + VkSampler textureSampler; VkImageView textureImageView; VkDeviceMemory textureImageMemory; diff --git a/engine/xe_model.cpp b/engine/xe_model.cpp index 48f9ad2..6720c13 100644 --- a/engine/xe_model.cpp +++ b/engine/xe_model.cpp @@ -117,7 +117,7 @@ void Model::Builder::loadModel(const std::string &filepath) { indices.clear(); vertexSize = 0; - bool vertex, color, normal, uvs; + bool vertex, normal, uvs; for (const auto &shape : shapes) { for (const auto &index : shape.mesh.indices) { @@ -127,11 +127,6 @@ void Model::Builder::loadModel(const std::string &filepath) { vertexData.push_back(attrib.vertices[3 * index.vertex_index + 1]); vertexData.push_back(attrib.vertices[3 * index.vertex_index + 2]); vertex = true; - - vertexData.push_back(attrib.colors[3 * index.vertex_index + 0]); - vertexData.push_back(attrib.colors[3 * index.vertex_index + 1]); - vertexData.push_back(attrib.colors[3 * index.vertex_index + 2]); - color = true; } if(index.normal_index >= 0) { @@ -152,8 +147,6 @@ void Model::Builder::loadModel(const std::string &filepath) { if(vertex) vertexSize += 12; - if(color) - vertexSize += 12; if(normal) vertexSize += 12; if(uvs) diff --git a/engine/xe_render_system.cpp b/engine/xe_render_system.cpp index a308874..b7cce7a 100644 --- a/engine/xe_render_system.cpp +++ b/engine/xe_render_system.cpp @@ -18,7 +18,6 @@ RenderSystem::RenderSystem( pushCunstantDataSize{pushCunstantDataSize}, uniformBindings{uniformBindings}, imageBindings{imageBindings} { - createTextureSampler(); createDescriptorSetLayout(); createUniformBuffers(); createDescriptorSets(); @@ -28,32 +27,8 @@ RenderSystem::RenderSystem( RenderSystem::~RenderSystem() { vkDestroyPipelineLayout(xeDevice.device(), pipelineLayout, nullptr); - vkDestroySampler(xeDevice.device(), textureSampler, nullptr); }; -void RenderSystem::createTextureSampler() { - VkSamplerCreateInfo samplerInfo{}; - samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; - samplerInfo.magFilter = VK_FILTER_LINEAR; - samplerInfo.minFilter = VK_FILTER_LINEAR; - samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; - samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; - samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; - samplerInfo.anisotropyEnable = VK_FALSE; - samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; - samplerInfo.unnormalizedCoordinates = VK_FALSE; - samplerInfo.compareEnable = VK_FALSE; - samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS; - samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; - samplerInfo.mipLodBias = 0.0f; - samplerInfo.minLod = 0.0f; - samplerInfo.maxLod = 0.0f; - - if (vkCreateSampler(xeDevice.device(), &samplerInfo, nullptr, &textureSampler) != VK_SUCCESS) { - throw std::runtime_error("failed to create texture sampler!"); - } -} - void RenderSystem::createDescriptorSetLayout() { DescriptorSetLayout::Builder builder{xeDevice}; @@ -62,7 +37,7 @@ void RenderSystem::createDescriptorSetLayout() { } for ( const auto &[binding, image]: imageBindings) { - builder.addBinding(binding, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, &textureSampler); + builder.addBinding(binding, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, &(image->textureSampler)); } xeDescriptorSetLayout = builder.build(); @@ -109,7 +84,7 @@ void RenderSystem::updateDescriptorSet(int frameIndex, bool allocate) { VkDescriptorImageInfo imageInfo{}; imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; imageInfo.imageView = image->textureImageView; - imageInfo.sampler = textureSampler; + imageInfo.sampler = image->textureSampler; writer.writeImage(binding, &imageInfo); } diff --git a/engine/xe_render_system.hpp b/engine/xe_render_system.hpp index c783610..045f6db 100644 --- a/engine/xe_render_system.hpp +++ b/engine/xe_render_system.hpp @@ -106,7 +106,6 @@ class RenderSystem { private: - void createTextureSampler(); void createDescriptorSetLayout(); void createUniformBuffers(); void createDescriptorSets(); @@ -127,8 +126,6 @@ class RenderSystem { std::vector descriptorSets; uint32_t pushCunstantDataSize; - - VkSampler textureSampler; VkPipelineLayout pipelineLayout; std::unique_ptr xePipeline; diff --git a/res/image/dirt.jpg b/res/image/dirt.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c3a679dd706a222b396c4e470985ff5991025b4b GIT binary patch literal 5956 zcmd5=dr(wm6u-N7m&fv078f+fY6Y!puTeARCCDW&Ek(ZrldFtw1HCh@_BG6OCutSFtc^4;&We9K~gdEw4?x%Zs& zo%1`tbMCqHH1zx}#pLEp$&m~ONix8X)N@;UDl0#G;*6>JsgA-qkC)7wTj*Fc=84e` zrL460^+Ly#+)0kyY1xw;i;|N@J?5BSHtV(Gg-aaij+D`so0T^~I^O13bgWRzq>f@HKAWSgPqi1Z)?X*T!{srN7#!N-u$uy9KR2vo;N zMuRLHO)`27(r?0Z$z(If4j(fyWKiC$(1iK+q~)tOh9ze1I24zEvTelJ*$c|UE%Aeg z+&6UOLk}yX9vSy!^7siUsaa2F=S-SBC3pIa=boSW!iz7xGH33qg+;|Br3=dzEq-Ik z(u%jmD8^+l zE{0RKnasn-gv3tF3!OE8P(sr3Fni|ejXMs7Cyvc;i<`aRq$PgDxN{@hF*ILf0}HJD ze?_JT#^Y*~B4q<4Pqs-esl~0S-N$Z?Q#4ibELF50o^@!dBK4kf9X!6AVpNq4?6hhi z+Fn;MaD^02eRS7Fi=r({AF3+b601;^o!$gh**@$#TDPuuYwC6DFnmOA>l=?pJ56YZ zooTnh-p*CbmY>lt*wx!9M|dFY=T?(ZvY@VhNCwiAqXZE}~R;ePo@lldMv zRKy3Bax*CM8KpY%} z0(#5#Vb?NI+6B^EFZi-k=?h{R+WW-~DV|Uc0><8x2og)29W>8rQ2yIa-Qk>9(e|Fm zK%4ad=OpvVvI_9pBos!1;7hY4gGDXs~ z`iNIST3V;7D4GKO_JDE|Yn_P&u@>y{T@(i41aq6M(CD=Tr#m-bbZf!grj^y~5w3(; zy4%EBkjEq&o*)&?HWgVEw3W|_aF9`uAf%ZPNQgj?;;Mm)s&@KJop(da?!KjuPH3Jx zt^+{cP0Vf5yHE*F!au?{0tpq^ScN0si~t+{3HNVKZz_lKh<1Xzb#?Vdzp}x%a6^+(>KF}S4_l)1?fp`zD>O28m;nGTt znZT9wJjx|u`bglUZUR`C40~0!;ufT!2myqE(OHhv5#!_)xVR;CcjMn}(1rZFu#kVG z4FwqW$lSsE6D19up_wn8WJD%yiRC`J28x>vWLDmdNi}ddMVt+m0Um24ypIlMxLk;J zGPuXu9s!$qWfg$R-JoJSEiu4mE1E_iDD_r16nLY32ElOUtU20_CfCLGB3r Chunk::getMesh() { delete chunkMesh.get(); xe::Model::Builder builder{}; builder.vertexData = vertexData; - builder.vertexSize = 44; + builder.vertexSize = 32; chunkMesh = std::make_shared(xe::Engine::getInstance()->getDevice(), builder); } return chunkMesh; @@ -123,9 +123,6 @@ void Chunk::addVerticies(uint32_t side, uint32_t x, uint32_t y, uint32_t z) { vertexData.push_back(px[side * 6 + i][0] + x); vertexData.push_back(px[side * 6 + i][1] + y); vertexData.push_back(px[side * 6 + i][2] + z); - vertexData.push_back(1.f); - vertexData.push_back(1.f); - vertexData.push_back(1.f); vertexData.push_back(nm[side][0]); vertexData.push_back(nm[side][1]); vertexData.push_back(nm[side][2]); diff --git a/src/chunk.hpp b/src/chunk.hpp index 5a50983..2fe78f0 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -108,10 +108,10 @@ const float nm[6][3] = { const float uv[6][2] = { + {1.f,1.f}, + {0.f,1.f}, + {0.f,0.f}, {0.f,0.f}, - {1.f,0.f}, - {0.f,1.f}, - {0.f,1.f}, {1.f,0.f}, {1.f,1.f} }; diff --git a/src/first_app.cpp b/src/first_app.cpp index b4aa3d5..80ee78c 100755 --- a/src/first_app.cpp +++ b/src/first_app.cpp @@ -11,8 +11,7 @@ FirstApp::~FirstApp() {} void FirstApp::run() { - std::shared_ptr image = xeEngine.loadImageFromFile("res/image/texture.png"); - std::shared_ptr image2 = xeEngine.loadImageFromFile("res/image/scaly.png"); + std::shared_ptr image = xeEngine.loadImageFromFile("res/image/dirt.jpg"); SimpleRenderer renderer{xeEngine, image.get()}; @@ -33,7 +32,7 @@ void FirstApp::run() { xeEngine.getCamera().setViewYXZ(viewerObject.transform.translation, viewerObject.transform.rotation); if(xeEngine.beginFrame()) { - renderer.render(gameObjects, xeEngine.getCamera(), image2.get()); + renderer.render(gameObjects, xeEngine.getCamera(), image.get()); xeEngine.endFrame(); } @@ -46,27 +45,13 @@ void FirstApp::run() { } void FirstApp::loadGameObjects() { - std::shared_ptr xeModel = xeEngine.loadModelFromFile("res/models/stanford-dragon.obj"); - - auto dragon = xe::GameObject::createGameObject(); - dragon.model = xeModel; - dragon.transform.translation = {.0f, .0f, 2.5f}; - dragon.transform.scale = {.5f, .5f, .5f}; - gameObjects.push_back(std::move(dragon)); - - auto dragon2 = xe::GameObject::createGameObject(); - dragon2.model = xeModel; - dragon2.transform.translation = {5.0f, .0f, -1.5f}; - dragon2.transform.rotation.y = glm::radians(90.f); - dragon2.transform.scale = {.35f, .35f, .35f}; - gameObjects.push_back(std::move(dragon2)); Chunk* chunk = Chunk::newChunk(0, 0, 123); chunk->createMesh(); auto chunkObject = xe::GameObject::createGameObject(); chunkObject.model = chunk->getMesh(); - chunkObject.transform.translation = {5.f, 5.f, 5.f}; + chunkObject.transform.translation = {0.f, 0.f, 0.f}; gameObjects.push_back(std::move(chunkObject)); } diff --git a/src/simple_renderer.cpp b/src/simple_renderer.cpp index 89d33b8..3efa9b8 100644 --- a/src/simple_renderer.cpp +++ b/src/simple_renderer.cpp @@ -5,10 +5,9 @@ namespace app { SimpleRenderer::SimpleRenderer(xe::Engine &xeEngine, xe::Image *xeImage) { xeRenderSystem = xe::RenderSystem::Builder(xeEngine, "res/shaders/simple_shader.vert.spv", "res/shaders/simple_shader.frag.spv") .addVertexBinding(0, 3, 0) // position - .addVertexBinding(1, 3, 12) // color - .addVertexBinding(2, 3, 24) // normal - .addVertexBinding(3, 2, 36) // uvs - .setVertexSize(sizeof(Vertex)) + .addVertexBinding(1, 3, 12) // normal + .addVertexBinding(2, 2, 24) // uvs + .setVertexSize(32) .addPushConstant(sizeof(PushConstant)) .addUniformBinding(0, sizeof(UniformBuffer)) .addTextureBinding(1, xeImage) diff --git a/src/simple_renderer.hpp b/src/simple_renderer.hpp index 501bafe..7c08001 100644 --- a/src/simple_renderer.hpp +++ b/src/simple_renderer.hpp @@ -16,13 +16,6 @@ struct PushConstant { alignas(16) glm::mat4 normalMatrix{1.f}; }; -struct Vertex { - glm::vec3 position; - glm::vec3 color; - glm::vec3 normal; - glm::vec2 uv; -}; - class SimpleRenderer { public: