diff --git a/aster/constants.h b/aster/constants.h index af7e39f..0889612 100644 --- a/aster/constants.h +++ b/aster/constants.h @@ -57,26 +57,22 @@ Recast(TFrom &&in) return reinterpret_cast(std::forward(in)); } -constexpr f32 -operator""_deg(long double degrees) +constexpr f32 operator""_deg(long double degrees) { return glm::radians(Cast(degrees)); } -constexpr f32 -operator""_deg(unsigned long long int degrees) +constexpr f32 operator""_deg(unsigned long long int degrees) { return glm::radians(Cast(degrees)); } -constexpr f32 -operator""_rad(long double rads) +constexpr f32 operator""_rad(long double rads) { return Cast(rads); } -constexpr f32 -operator""_rad(unsigned long long int rads) +constexpr f32 operator""_rad(unsigned long long int rads) { return Cast(rads); } @@ -84,10 +80,10 @@ operator""_rad(unsigned long long int rads) using glm::ivec2; using glm::ivec3; using glm::ivec4; +using glm::quat; using glm::vec2; using glm::vec3; using glm::vec4; -using glm::quat; using glm::mat2; using glm::mat3; diff --git a/aster/swapchain.cpp b/aster/swapchain.cpp index 82dcf4e..fbe53b4 100644 --- a/aster/swapchain.cpp +++ b/aster/swapchain.cpp @@ -13,8 +13,8 @@ Swapchain::Swapchain(const Window *window, const Device *device, NameString &&name) : m_Device(device) - , m_Name(std::move(name)) - , m_Format(vk::Format::eUndefined) + , m_Name(std::move(name)) + , m_Format(vk::Format::eUndefined) { this->Create(window); } @@ -26,12 +26,12 @@ Swapchain::~Swapchain() Swapchain::Swapchain(Swapchain &&other) noexcept : m_Device(other.m_Device) - , m_Swapchain(Take(other.m_Swapchain)) - , m_Name(std::move(other.m_Name)) - , m_Extent(other.m_Extent) - , m_Format(other.m_Format) - , m_Images(std::move(other.m_Images)) - , m_ImageViews(std::move(other.m_ImageViews)) + , m_Swapchain(Take(other.m_Swapchain)) + , m_Name(std::move(other.m_Name)) + , m_Extent(other.m_Extent) + , m_Format(other.m_Format) + , m_Images(std::move(other.m_Images)) + , m_ImageViews(std::move(other.m_ImageViews)) { } diff --git a/samples/00_util/gpu_resource_manager.cpp b/samples/00_util/gpu_resource_manager.cpp index a8bbad1..85495b1 100644 --- a/samples/00_util/gpu_resource_manager.cpp +++ b/samples/00_util/gpu_resource_manager.cpp @@ -23,7 +23,7 @@ TextureHandle TextureManager::Commit(Texture *texture) { ERROR_IF(!texture->IsValid() || !texture->IsOwned(), "Buffer must be valid and owned for commital") - THEN_ABORT(-1); + THEN_ABORT(-1); if (m_FreeHead != GpuResourceHandle::INVALID_HANDLE) { @@ -165,7 +165,7 @@ BufferManager::Release(const Device *device, const BufferHandle handle) void BufferManager::Destroy(const Device *device) { - for (auto& buffer : m_Buffers) + for (auto &buffer : m_Buffers) { buffer.Destroy(device); } @@ -275,7 +275,7 @@ GpuResourceManager::Release(TextureHandle handle) } TextureHandle -GpuResourceManager::Commit(Texture* texture) +GpuResourceManager::Commit(Texture *texture) { TextureHandle handle = m_TextureManager.Commit(texture); @@ -338,7 +338,7 @@ GpuResourceManager::GpuResourceManager(const Device *device, u16 maxSize) .maxAnisotropy = properties.limits.maxSamplerAnisotropy, .compareEnable = false, .minLod = 0, - .maxLod = vk::LodClampNone, + .maxLod = VK_LOD_CLAMP_NONE, .borderColor = vk::BorderColor::eFloatOpaqueBlack, .unnormalizedCoordinates = false, }; @@ -368,6 +368,18 @@ GpuResourceManager::GpuResourceManager(const Device *device, u16 maxSize) }; AbortIfFailed(device->m_Device.createDescriptorPool(&poolCreateInfo, nullptr, &m_DescriptorPool)); + vk::DescriptorBindingFlags bindingFlags = + vk::DescriptorBindingFlagBits::ePartiallyBound | vk::DescriptorBindingFlagBits::eUpdateAfterBind; + eastl::array layoutBindingFlags = { + bindingFlags, + bindingFlags, + }; + + vk::DescriptorSetLayoutBindingFlagsCreateInfo bindingFlagsCreateInfo = { + .bindingCount = Cast(layoutBindingFlags.size()), + .pBindingFlags = layoutBindingFlags.data(), + }; + eastl::vector immutableSamplers(texturesCount, m_ImmutableSampler); eastl::array descriptorLayoutBindings = { vk::DescriptorSetLayoutBinding{ @@ -384,7 +396,9 @@ GpuResourceManager::GpuResourceManager(const Device *device, u16 maxSize) .pImmutableSamplers = immutableSamplers.data(), }, }; + static_assert(layoutBindingFlags.size() == descriptorLayoutBindings.size()); const vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = { + .pNext = &bindingFlagsCreateInfo, .flags = vk::DescriptorSetLayoutCreateFlagBits::eUpdateAfterBindPool, .bindingCount = Cast(descriptorLayoutBindings.size()), .pBindings = descriptorLayoutBindings.data(), @@ -420,18 +434,18 @@ GpuResourceManager::~GpuResourceManager() } GpuResourceManager::GpuResourceManager(GpuResourceManager &&other) noexcept - : m_WriteInfos(std::move(other.m_WriteInfos)), - m_Writes(std::move(other.m_Writes)), - m_WriteOwner(std::move(other.m_WriteOwner)), - m_ImmutableSampler(other.m_ImmutableSampler), - m_BufferManager(std::move(other.m_BufferManager)), - m_TextureManager(std::move(other.m_TextureManager)), - m_Device(Take(other.m_Device)), - m_DescriptorPool(other.m_DescriptorPool), - m_SetLayout(other.m_SetLayout), - m_DescriptorSet(other.m_DescriptorSet), - m_CommitedBufferCount(other.m_CommitedBufferCount), - m_CommitedTextureCount(other.m_CommitedTextureCount) + : m_WriteInfos(std::move(other.m_WriteInfos)) + , m_Writes(std::move(other.m_Writes)) + , m_WriteOwner(std::move(other.m_WriteOwner)) + , m_ImmutableSampler(other.m_ImmutableSampler) + , m_BufferManager(std::move(other.m_BufferManager)) + , m_TextureManager(std::move(other.m_TextureManager)) + , m_Device(Take(other.m_Device)) + , m_DescriptorPool(other.m_DescriptorPool) + , m_SetLayout(other.m_SetLayout) + , m_DescriptorSet(other.m_DescriptorSet) + , m_CommitedBufferCount(other.m_CommitedBufferCount) + , m_CommitedTextureCount(other.m_CommitedTextureCount) { assert(!other.m_Device); } diff --git a/samples/00_util/gpu_resource_manager.h b/samples/00_util/gpu_resource_manager.h index 584218a..ec4238d 100644 --- a/samples/00_util/gpu_resource_manager.h +++ b/samples/00_util/gpu_resource_manager.h @@ -40,8 +40,7 @@ struct TextureManager u32 m_MaxCapacity; u32 m_FreeHead; - void - Init(u32 maxCapacity); + void Init(u32 maxCapacity); TextureHandle Commit(Texture *texture); Texture *Fetch(TextureHandle handle); void Release(const Device *device, TextureHandle handle); @@ -63,9 +62,8 @@ struct BufferManager struct GpuResourceManager { -private: - union WriteInfo - { + private: + union WriteInfo { vk::DescriptorBufferInfo uBufferInfo; vk::DescriptorImageInfo uImageInfo; vk::BufferView uBufferView; @@ -98,7 +96,7 @@ private: void EraseWrites(u32 handleIndex, HandleType handleType); -public: + public: const Device *m_Device; constexpr static u32 BUFFER_BINDING_INDEX = 0; diff --git a/samples/03_model_render/light_manager.cpp b/samples/03_model_render/light_manager.cpp index 5d54987..2c96b2e 100644 --- a/samples/03_model_render/light_manager.cpp +++ b/samples/03_model_render/light_manager.cpp @@ -14,8 +14,8 @@ struct Light vec3 um_Position; vec3 um_Direction; }; - f32 m_Range; // < 0.0 for invalid - u32 m_Color_; // LSB is used for flags. (R G B Flags) + f32 m_Range; // < 0.0 for invalid + u32 m_Color_; // LSB is used for flags. (R G B Flags) f32 m_Intensity; constexpr static u32 MAX_GEN = 0x40; @@ -150,7 +150,7 @@ LightManager::AddDirectional(const vec3 &direction, const vec3 &color) m_Lights.push_back(); m_Lights.push_back(); - if (m_MetaInfo.m_PointLightMaxCount > 0) // Edge Case: nullptr at size 0 + if (m_MetaInfo.m_PointLightMaxCount > 0) // Edge Case: nullptr at size 0 { Light *oldPointStart = m_Lights.data() + oldPointLightOffset; Light *newPointStart = oldPointStart + 2; @@ -175,7 +175,7 @@ LightManager::AddDirectional(const vec3 &direction, const vec3 &color) } LightHandle -LightManager::AddPoint(const vec3 & position, const vec3 &color, const f32 radius) +LightManager::AddPoint(const vec3 &position, const vec3 &color, const f32 radius) { assert(m_PointLightCount <= m_MetaInfo.m_PointLightMaxCount); assert(radius >= 0.0f); @@ -206,7 +206,7 @@ LightManager::AddPoint(const vec3 & position, const vec3 &color, const f32 radiu const u16 index = m_PointLightCount; Light *light = &m_Lights[index + m_MetaInfo.m_PointLightOffset]; - constexpr u8 gen = 0; // New light + constexpr u8 gen = 0; // New light light->m_Color_ = (ToColor32(color) & Light::COLOR_MASK) | Light::TYPE_POINT | gen; light->m_Range = radius; @@ -244,7 +244,6 @@ LightManager::RemoveLight(const LightHandle handle) { const u8 handleGen = handle.m_Generation; - if (handle.m_Type == Light::TYPE_DIRECTIONAL) { Light *lightSlot = &m_Lights[handle.m_Index]; diff --git a/samples/03_model_render/light_manager.h b/samples/03_model_render/light_manager.h index 872c0ca..6d4fc23 100644 --- a/samples/03_model_render/light_manager.h +++ b/samples/03_model_render/light_manager.h @@ -44,11 +44,11 @@ struct LightManager // We can use that with Offset = 0, and point light at further offsets. // This way we don't need to move point lights often. - BufferHandle m_LightBuffer; // 04 04 - u16 m_PointLightMaxCount; // 02 06 - u16 m_PointLightOffset; // 02 08 - u16 m_DirectionalLightMaxCount; // 02 10 - u16 m_UnusedPadding0 = 0; // 02 12 + BufferHandle m_LightBuffer; // 04 04 + u16 m_PointLightMaxCount; // 02 06 + u16 m_PointLightOffset; // 02 08 + u16 m_DirectionalLightMaxCount; // 02 10 + u16 m_UnusedPadding0 = 0; // 02 12 }; GpuResourceManager *m_ResourceManager; @@ -69,7 +69,7 @@ struct LightManager constexpr static u16 CAPACITY_MASK = ~(UPDATE_REQUIRED_BIT); LightHandle AddDirectional(const vec3 &direction, const vec3 &color); - LightHandle AddPoint(const vec3& position, const vec3 &color, f32 radius); + LightHandle AddPoint(const vec3 &position, const vec3 &color, f32 radius); void Update(); void RemoveLight(LightHandle handle); diff --git a/samples/03_model_render/model_loader.cpp b/samples/03_model_render/model_loader.cpp index 5ce5225..44e0598 100644 --- a/samples/03_model_render/model_loader.cpp +++ b/samples/03_model_render/model_loader.cpp @@ -14,12 +14,12 @@ #include "buffer.h" #include "device.h" +#include "gpu_resource_manager.h" #include "helpers.h" #include "image.h" -#include "gpu_resource_manager.h" -#include #include +#include vec4 VectorToVec4(const std::vector &vec) @@ -46,8 +46,7 @@ VectorToVec3(const std::vector &vec) } TextureHandle -ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBuffer, - tinygltf::Image *image) const +ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBuffer, tinygltf::Image *image) const { assert(image->component == 4); @@ -64,17 +63,17 @@ ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBu .dstAccessMask = vk::AccessFlagBits::eTransferWrite, .oldLayout = vk::ImageLayout::eUndefined, .newLayout = vk::ImageLayout::eTransferDstOptimal, - .srcQueueFamilyIndex = vk::QueueFamilyIgnored, - .dstQueueFamilyIndex = vk::QueueFamilyIgnored, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .image = texture.m_Image, .subresourceRange = - { - .aspectMask = vk::ImageAspectFlagBits::eColor, - .baseMipLevel = 0, - .levelCount = texture.GetMipLevels(), - .baseArrayLayer = 0, - .layerCount = 1, - }, + { + .aspectMask = vk::ImageAspectFlagBits::eColor, + .baseMipLevel = 0, + .levelCount = texture.GetMipLevels(), + .baseArrayLayer = 0, + .layerCount = 1, + }, }; vk::ImageMemoryBarrier nextMipBarrier = { @@ -82,17 +81,17 @@ ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBu .dstAccessMask = vk::AccessFlagBits::eTransferRead, .oldLayout = vk::ImageLayout::eTransferDstOptimal, .newLayout = vk::ImageLayout::eTransferSrcOptimal, - .srcQueueFamilyIndex = vk::QueueFamilyIgnored, - .dstQueueFamilyIndex = vk::QueueFamilyIgnored, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .image = texture.m_Image, .subresourceRange = - { - .aspectMask = vk::ImageAspectFlagBits::eColor, - .baseMipLevel = 0, - .levelCount = 1, - .baseArrayLayer = 0, - .layerCount = 1, - }, + { + .aspectMask = vk::ImageAspectFlagBits::eColor, + .baseMipLevel = 0, + .levelCount = 1, + .baseArrayLayer = 0, + .layerCount = 1, + }, }; vk::ImageMemoryBarrier imageReadyBarrier = { @@ -104,13 +103,13 @@ ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBu .dstQueueFamilyIndex = m_GraphicsQueueIndex, .image = texture.m_Image, .subresourceRange = - { - .aspectMask = vk::ImageAspectFlagBits::eColor, - .baseMipLevel = 0, - .levelCount = texture.GetMipLevels(), - .baseArrayLayer = 0, - .layerCount = 1, - }, + { + .aspectMask = vk::ImageAspectFlagBits::eColor, + .baseMipLevel = 0, + .levelCount = texture.GetMipLevels(), + .baseArrayLayer = 0, + .layerCount = 1, + }, }; vk::BufferImageCopy imageCopy = { @@ -118,12 +117,12 @@ ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBu .bufferRowLength = Cast(image->width), .bufferImageHeight = Cast(image->height), .imageSubresource = - { - .aspectMask = vk::ImageAspectFlagBits::eColor, - .mipLevel = 0, - .baseArrayLayer = 0, - .layerCount = 1, - }, + { + .aspectMask = vk::ImageAspectFlagBits::eColor, + .mipLevel = 0, + .baseArrayLayer = 0, + .layerCount = 1, + }, .imageOffset = {}, .imageExtent = texture.m_Extent, }; @@ -135,9 +134,7 @@ ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBu commandBuffer.pipelineBarrier(vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer, {}, 0, nullptr, 0, nullptr, 1, &nextMipBarrier); - auto calcNextMip = [](i32 prev) { - return eastl::max(prev / 2, 1); - }; + auto calcNextMip = [](i32 prev) { return eastl::max(prev / 2, 1); }; i32 prevMipWidth = Cast(texture.m_Extent.width); i32 prevMipHeight = Cast(texture.m_Extent.height); @@ -151,27 +148,29 @@ ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBu vk::ImageBlit blitRegion = { .srcSubresource = - { - .aspectMask = vk::ImageAspectFlagBits::eColor, - .mipLevel = prevMipLevel, - .baseArrayLayer = 0, - .layerCount = 1, - }, - .srcOffsets = std::array{ - vk::Offset3D{0, 0, 0}, - vk::Offset3D{prevMipWidth, prevMipHeight, 1}, - }, + { + .aspectMask = vk::ImageAspectFlagBits::eColor, + .mipLevel = prevMipLevel, + .baseArrayLayer = 0, + .layerCount = 1, + }, + .srcOffsets = + std::array{ + vk::Offset3D{0, 0, 0}, + vk::Offset3D{prevMipWidth, prevMipHeight, 1}, + }, .dstSubresource = - { - .aspectMask = vk::ImageAspectFlagBits::eColor, - .mipLevel = currentMipLevel, - .baseArrayLayer = 0, - .layerCount = 1, - }, - .dstOffsets = std::array{ - vk::Offset3D{0, 0, 0}, - vk::Offset3D{currentMipWidth, currentMipHeight, 1}, - }, + { + .aspectMask = vk::ImageAspectFlagBits::eColor, + .mipLevel = currentMipLevel, + .baseArrayLayer = 0, + .layerCount = 1, + }, + .dstOffsets = + std::array{ + vk::Offset3D{0, 0, 0}, + vk::Offset3D{currentMipWidth, currentMipHeight, 1}, + }, }; nextMipBarrier.subresourceRange.baseMipLevel = currentMipLevel; @@ -230,6 +229,7 @@ ModelLoader::LoadModel(cstr path, cstr name, bool batched) eastl::vector stagingBuffers; eastl::vector textureHandles; + // TODO: MetalRough and Occlusion Textures are non-sRGB if (!model.images.empty()) { u32 numImages = Cast(model.images.size()); @@ -407,7 +407,7 @@ ModelLoader::LoadModel(cstr path, cstr name, bool batched) usize byteOffset = (uvAccessor->byteOffset + uvBufferView->byteOffset); assert(uvAccessor->type == TINYGLTF_TYPE_VEC2 && - uvAccessor->componentType == TINYGLTF_COMPONENT_TYPE_FLOAT); + uvAccessor->componentType == TINYGLTF_COMPONENT_TYPE_FLOAT); { vec2 *data = Recast(uvBuffer->data.data() + byteOffset); vec2 *end = data + vertexCount; @@ -513,7 +513,8 @@ ModelLoader::LoadModel(cstr path, cstr name, bool batched) { if (model.defaultScene >= 0) { - eastl::function processNode = [&processNode, &model, &nodes, &meshPrimRanges, &meshPrimitives](i32 idx, i32 parent) -> void { + eastl::function processNode = [&processNode, &model, &nodes, &meshPrimRanges, + &meshPrimitives](i32 idx, i32 parent) -> void { const auto *node = &model.nodes[idx]; vec3 nodeTranslation = vec3{0.0f}; @@ -537,8 +538,8 @@ ModelLoader::LoadModel(cstr path, cstr name, bool batched) { nodeMatrix = glm::make_mat4(node->matrix.data()); } - const mat4 transform = - translate(mat4(1.0f), nodeTranslation) * mat4_cast(nodeRotation) * scale(mat4(1.0f), nodeScale) * nodeMatrix; + const mat4 transform = translate(mat4(1.0f), nodeTranslation) * mat4_cast(nodeRotation) * + scale(mat4(1.0f), nodeScale) * nodeMatrix; const i32 nodeArrayIndex = Cast(nodes.Add(transform, parent)); if (node->mesh >= 0) @@ -633,12 +634,14 @@ ModelLoader::LoadModel(cstr path, cstr name, bool batched) .m_NodeHandle = nodeHandle, }; - return Model{m_ResourceManager, std::move(textureHandles), std::move(nodes), - handles, indexBuffer, meshPrimitives, }; + return Model{ + m_ResourceManager, std::move(textureHandles), std::move(nodes), handles, indexBuffer, meshPrimitives, + }; } Model::Model(GpuResourceManager *resourceManager, eastl::vector &&textureHandles, Nodes &&nodes, - const ModelHandles &handles, const IndexBuffer &indexBuffer, const eastl::vector &meshPrimitives) + const ModelHandles &handles, const IndexBuffer &indexBuffer, + const eastl::vector &meshPrimitives) : m_ResourceManager(resourceManager) , m_TextureHandles(std::move(textureHandles)) , m_Nodes(std::move(nodes)) @@ -741,12 +744,13 @@ ModelLoader::~ModelLoader() } } -ModelLoader::ModelLoader(ModelLoader &&other) noexcept: m_ResourceManager(Take(other.m_ResourceManager)), - m_CommandPool(other.m_CommandPool), - m_CommandBuffer(other.m_CommandBuffer), - m_TransferQueue(other.m_TransferQueue), - m_TransferQueueIndex(other.m_TransferQueueIndex), - m_GraphicsQueueIndex(other.m_GraphicsQueueIndex) +ModelLoader::ModelLoader(ModelLoader &&other) noexcept + : m_ResourceManager(Take(other.m_ResourceManager)) + , m_CommandPool(other.m_CommandPool) + , m_CommandBuffer(other.m_CommandBuffer) + , m_TransferQueue(other.m_TransferQueue) + , m_TransferQueueIndex(other.m_TransferQueueIndex) + , m_GraphicsQueueIndex(other.m_GraphicsQueueIndex) { } diff --git a/samples/03_model_render/model_loader.h b/samples/03_model_render/model_loader.h index 38024bf..8db08da 100644 --- a/samples/03_model_render/model_loader.h +++ b/samples/03_model_render/model_loader.h @@ -30,15 +30,15 @@ struct MeshPrimitive struct Material { - vec4 m_AlbedoFactor; // 16 16 - vec3 m_EmissionFactor; // 12 28 - f32 m_MetalFactor; // 04 32 - f32 m_RoughFactor; // 04 36 - TextureHandle m_AlbedoTex; // 04 40 - TextureHandle m_NormalTex; // 04 44 - TextureHandle m_MetalRoughTex; // 04 48 - TextureHandle m_OcclusionTex; // 04 52 - TextureHandle m_EmissionTex; // 04 56 + vec4 m_AlbedoFactor; // 16 16 + vec3 m_EmissionFactor; // 12 28 + f32 m_MetalFactor; // 04 32 + f32 m_RoughFactor; // 04 36 + TextureHandle m_AlbedoTex; // 04 40 + TextureHandle m_NormalTex; // 04 44 + TextureHandle m_MetalRoughTex; // 04 48 + TextureHandle m_OcclusionTex; // 04 52 + TextureHandle m_EmissionTex; // 04 56 }; struct VertexData @@ -72,7 +72,8 @@ struct Model void Update(); Model(GpuResourceManager *resourceManager, eastl::vector &&textureHandles, Nodes &&nodes, - const ModelHandles& handles, const IndexBuffer &indexBuffer, const eastl::vector &meshPrimitives); + const ModelHandles &handles, const IndexBuffer &indexBuffer, + const eastl::vector &meshPrimitives); ~Model(); Model(Model &&other) noexcept; @@ -91,8 +92,8 @@ struct ModelLoader u32 m_TransferQueueIndex; u32 m_GraphicsQueueIndex; - TextureHandle LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBuffer, - tinygltf::Image *image) const; + TextureHandle + LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBuffer, tinygltf::Image *image) const; Model LoadModel(cstr path, cstr name = nullptr, bool batched = false); constexpr static auto ANormal = "NORMAL"; diff --git a/samples/03_model_render/model_render.cpp b/samples/03_model_render/model_render.cpp index 20acbff..cf1e624 100644 --- a/samples/03_model_render/model_render.cpp +++ b/samples/03_model_render/model_render.cpp @@ -18,9 +18,9 @@ #include "helpers.h" #include "light_manager.h" +#include "gpu_resource_manager.h" #include "model_loader.h" #include "pipeline_utils.h" -#include "gpu_resource_manager.h" #include #include @@ -53,18 +53,18 @@ main(int, char **) Features enabledDeviceFeatures = { .m_Vulkan10Features = {.samplerAnisotropy = true}, .m_Vulkan12Features = - { - .descriptorIndexing = true, - .shaderSampledImageArrayNonUniformIndexing = true, - .shaderStorageBufferArrayNonUniformIndexing = true, - .shaderStorageImageArrayNonUniformIndexing = true, - .descriptorBindingUniformBufferUpdateAfterBind = true, // Not related to Bindless - .descriptorBindingSampledImageUpdateAfterBind = true, - .descriptorBindingStorageImageUpdateAfterBind = true, - .descriptorBindingStorageBufferUpdateAfterBind = true, - .descriptorBindingPartiallyBound = true, - .runtimeDescriptorArray = true, - }, + { + .descriptorIndexing = true, + .shaderSampledImageArrayNonUniformIndexing = true, + .shaderStorageBufferArrayNonUniformIndexing = true, + .shaderStorageImageArrayNonUniformIndexing = true, + .descriptorBindingUniformBufferUpdateAfterBind = true, // Not related to Bindless + .descriptorBindingSampledImageUpdateAfterBind = true, + .descriptorBindingStorageImageUpdateAfterBind = true, + .descriptorBindingStorageBufferUpdateAfterBind = true, + .descriptorBindingPartiallyBound = true, + .runtimeDescriptorArray = true, + }, .m_Vulkan13Features = {.dynamicRendering = true}, }; @@ -285,11 +285,11 @@ main(int, char **) for (auto &prim : model.m_MeshPrimitives) { - cmd.pushConstants(pipeline.m_Layout, vk::ShaderStageFlagBits::eAll, pcbOffset, - sizeof prim.m_MaterialIdx, &prim.m_MaterialIdx); + cmd.pushConstants(pipeline.m_Layout, vk::ShaderStageFlagBits::eAll, pcbOffset, sizeof prim.m_MaterialIdx, + &prim.m_MaterialIdx); pcbOffset += sizeof prim.m_MaterialIdx; - cmd.pushConstants(pipeline.m_Layout, vk::ShaderStageFlagBits::eAll, pcbOffset, - sizeof prim.m_TransformIdx, &prim.m_TransformIdx); + cmd.pushConstants(pipeline.m_Layout, vk::ShaderStageFlagBits::eAll, pcbOffset, sizeof prim.m_TransformIdx, + &prim.m_TransformIdx); pcbOffset += sizeof prim.m_TransformIdx; cmd.drawIndexed(prim.m_IndexCount, 1, prim.m_FirstIndex, Cast(prim.m_VertexOffset), 0); } diff --git a/samples/03_model_render/pipeline_utils.cpp b/samples/03_model_render/pipeline_utils.cpp index 2414424..e67b674 100644 --- a/samples/03_model_render/pipeline_utils.cpp +++ b/samples/03_model_render/pipeline_utils.cpp @@ -6,8 +6,8 @@ #include "pipeline_utils.h" #include "device.h" -#include "helpers.h" #include "gpu_resource_manager.h" +#include "helpers.h" #include "swapchain.h" #include diff --git a/samples/03_model_render/shader/model.ps.hlsl b/samples/03_model_render/shader/model.ps.hlsl index c38d844..9e1560b 100644 --- a/samples/03_model_render/shader/model.ps.hlsl +++ b/samples/03_model_render/shader/model.ps.hlsl @@ -15,14 +15,27 @@ struct FS_Output float4 GetAlbedo(int MaterialIdx, float2 UV) { - uint albedoTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][MaterialIdx].AlbedoTex; - if (albedoTexId == INVALID_HANDLE) + uint AlbedoTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][MaterialIdx].AlbedoTex; + if (AlbedoTexId == INVALID_HANDLE) { return (float4) MaterialsBuffer[PushConstant.MaterialBufferHandle][MaterialIdx].AlbedoFactor; } else { - return Textures[albedoTexId].Sample(ImmutableSamplers[albedoTexId], UV); + return Textures[AlbedoTexId].Sample(ImmutableSamplers[AlbedoTexId], UV); + } +} + +float2 GetMetalRough(int MaterialIdx, float2 UV) +{ + uint MetalRoughTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][MaterialIdx].MetalRoughTex; + if (MetalRoughTexId == INVALID_HANDLE) + { + return float2(MaterialsBuffer[PushConstant.MaterialBufferHandle][MaterialIdx].MetalFactor, MaterialsBuffer[PushConstant.MaterialBufferHandle][MaterialIdx].RoughFactor); + } + else + { + return Textures[MetalRoughTexId].Sample(ImmutableSamplers[MetalRoughTexId], UV).bg; // Metal in Blue, Roughness in Green } } @@ -91,6 +104,7 @@ FS_Output main(FS_Input StageInput) float3 Position = StageInput.InPosition.xyz; float4 ObjColor = PushConstant.MaterialIdx < 0 ? StageInput.InColor : GetAlbedo(PushConstant.MaterialIdx, StageInput.InUV0); + float2 MetalRough = PushConstant.MaterialIdx < 0 ? float2(0.0f, 0.0f) : GetMetalRough(PushConstant.MaterialIdx, StageInput.InUV0); float3 Diffuse = GetDirectionalLightInfluence(Normal) + GetPointLightInfluence(Position, Normal);