diff --git a/external/vcpkg b/external/vcpkg index 0bf1354..f9a99aa 160000 --- a/external/vcpkg +++ b/external/vcpkg @@ -1 +1 @@ -Subproject commit 0bf1354d6704ec797acea686d0250afc4036a082 +Subproject commit f9a99aa79c1309001e36572fa42d7d8edebfc451 diff --git a/res/shaders/BasePass.slang b/res/shaders/BasePass.slang index 9c7b74a..1c4f529 100644 --- a/res/shaders/BasePass.slang +++ b/res/shaders/BasePass.slang @@ -25,10 +25,10 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target { result += pLightEnv.directionalLights[i].illuminate(lightingParams, brdf); } - for(uint i = 0; i < lightCount; ++i) + for(uint i = 0; i < pLightEnv.numPointLights; ++i) { - uint lightIndex = pLightCullingData.lightIndexList[startOffset + i]; - result += pLightEnv.pointLights[lightIndex].illuminate(lightingParams, brdf); + //uint lightIndex = pLightCullingData.lightIndexList[startOffset + i]; + result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf); } result += brdf.evaluateAmbient(lightingParams.viewDir_WS); return float4(result, brdf.getAlpha()); diff --git a/res/shaders/EnvironmentMapping.slang b/res/shaders/EnvironmentMapping.slang index 3545fc6..f49a441 100644 --- a/res/shaders/EnvironmentMapping.slang +++ b/res/shaders/EnvironmentMapping.slang @@ -1,57 +1,57 @@ const static float3 vertices[] = { // Right + float3( 1, 1, 1), float3( 1, -1, 1), - float3( 1, 1, 1), - float3( 1, -1, -1), - - float3( 1, -1, -1), - float3( 1, 1, 1), float3( 1, 1, -1), + float3( 1, 1, -1), + float3( 1, -1, 1), + float3( 1, -1, -1), + // Left + float3(-1, 1, -1), float3(-1, -1, -1), - float3(-1, 1, -1), - float3(-1, -1, 1), - - float3(-1, -1, 1), - float3(-1, 1, -1), float3(-1, 1, 1), + float3(-1, 1, 1), + float3(-1, -1, -1), + float3(-1, -1, 1), + // Bottom - float3(-1, 1, 1), - float3(-1, 1, -1), - float3( 1, 1, 1), + float3(-1, -1, 1), + float3(-1, -1, -1), + float3( 1, -1, 1), - float3( 1, 1, 1), - float3(-1, 1, -1), - float3( 1, 1, -1), + float3( 1, -1, 1), + float3(-1, -1, -1), + float3( 1, -1, -1), // Top - float3(-1, -1, -1), - float3(-1, -1, 1), - float3( 1, -1, -1), - - float3( 1, -1, -1), - float3(-1, -1, 1), - float3( 1, -1, 1), - - // Back - float3(-1, -1, 1), + float3(-1, 1, -1), float3(-1, 1, 1), - float3( 1, -1, 1), + float3( 1, 1, -1), - float3( 1, -1, 1), + float3( 1, 1, -1), float3(-1, 1, 1), float3( 1, 1, 1), - // Front - float3( 1, -1, -1), - float3( 1, 1, -1), - float3(-1, -1, -1), + // Back + float3(-1, 1, 1), + float3(-1, -1, 1), + float3( 1, 1, 1), - float3(-1, -1, -1), + float3( 1, 1, 1), + float3(-1, -1, 1), + float3( 1, -1, 1), + + // Front float3( 1, 1, -1), + float3( 1, -1, -1), float3(-1, 1, -1), + + float3(-1, 1, -1), + float3( 1, -1, -1), + float3(-1, -1, -1), }; struct ViewParams diff --git a/res/shaders/FullscreenQuad.slang b/res/shaders/FullscreenQuad.slang index ada8674..ab135fb 100644 --- a/res/shaders/FullscreenQuad.slang +++ b/res/shaders/FullscreenQuad.slang @@ -7,9 +7,8 @@ struct QuadOutput [shader("vertex")] QuadOutput quadMain(uint vertexIndex : SV_VertexID) { - QuadOutput result; - result.uv = float2((vertexIndex << 1) & 2, vertexIndex & 2); + QuadOutput result; + result.uv = float2(vertexIndex & 2, (vertexIndex << 1) & 2); result.position = float4(result.uv * 2.0f + -1.0f, 0.0f, 1.0f); - result.uv.y = 1 - result.uv.y; return result; } \ No newline at end of file diff --git a/res/shaders/lib/Common.slang b/res/shaders/lib/Common.slang index 8d34d6b..c1bbf84 100644 --- a/res/shaders/lib/Common.slang +++ b/res/shaders/lib/Common.slang @@ -68,7 +68,7 @@ float4 screenToView(float4 screen) float2 texCoord = screen.xy / pViewParams.screenDimensions; // Convert to clip space - float4 clip = float4( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w); + float4 clip = float4( texCoord * 2.0f - 1.0f, screen.z, screen.w); return clipToView(clip); } @@ -94,7 +94,7 @@ float4 clipToScreen(float4 clip) float oz = 1; float pz = 0 - 1; float zf = pz * ndc.z + oz; - return float4(float2(texCoords.x, 1 - texCoords.y) * pViewParams.screenDimensions, zf, 1.0f); + return float4(texCoords * pViewParams.screenDimensions, zf, 1.0f); } struct Plane diff --git a/res/shaders/lib/LightEnv.slang b/res/shaders/lib/LightEnv.slang index dd8fd7d..9cb289f 100644 --- a/res/shaders/lib/LightEnv.slang +++ b/res/shaders/lib/LightEnv.slang @@ -337,7 +337,7 @@ struct CookTorrance : IBRDF float nDotL = max(dot(n, lightDir_WS), 0.0); float3 result = (k_d * baseColor / PI + specular) * nDotL * lightColor; - return result; + return baseColor; } [mutating] void transformNormal(float3x3 tangentToWorld) diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index bdf3ae1..cc56070 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -154,8 +154,6 @@ void BasePass::render() { // Base Rendering for (VertexData* vertexData : VertexData::getList()) { transparentData.addAll(vertexData->getTransparentData()); - vertexData->getInstanceDataSet()->updateBuffer(VertexData::CULLINGDATA_NAME, 0, cullingBuffer); - vertexData->getInstanceDataSet()->writeChanges(); permutation.setVertexData(vertexData->getTypeName()); for (const auto& materialData : vertexData->getMaterialData()) { // material not used for any active meshes, skip diff --git a/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp b/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp index 665a571..dec7386 100644 --- a/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp @@ -125,8 +125,6 @@ void DepthCullingPass::render() { permutation.setDepthCulling(getGlobals().useDepthCulling); for (VertexData* vertexData : VertexData::getList()) { permutation.setVertexData(vertexData->getTypeName()); - vertexData->getInstanceDataSet()->updateBuffer(VertexData::CULLINGDATA_NAME, 0, cullingBuffer); - vertexData->getInstanceDataSet()->writeChanges(); // Create Pipeline(VertexData) // Descriptors: // ViewData => global, static diff --git a/src/Engine/Graphics/Vulkan/Buffer.cpp b/src/Engine/Graphics/Vulkan/Buffer.cpp index deaaf94..ca1761d 100644 --- a/src/Engine/Graphics/Vulkan/Buffer.cpp +++ b/src/Engine/Graphics/Vulkan/Buffer.cpp @@ -104,7 +104,8 @@ void BufferAllocation::updateContents(uint64 regionOffset, uint64 regionSize, vo .flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT, .usage = VMA_MEMORY_USAGE_AUTO, }; - OBufferAllocation staging = new BufferAllocation(graphics, fmt::format("{0}UpdateStaging", name), stagingInfo, stagingAlloc, Gfx::QueueType::GRAPHICS); + OBufferAllocation staging = + new BufferAllocation(graphics, fmt::format("{0}UpdateStaging", name), stagingInfo, stagingAlloc, Gfx::QueueType::GRAPHICS); uint8* data; VK_CHECK(vmaMapMemory(graphics->getAllocator(), staging->allocation, (void**)&data)); @@ -306,7 +307,7 @@ void Buffer::createBuffer(uint64 size, uint32 destIndex) { command->bindResource(PBufferAllocation(buffers[destIndex])); vkCmdFillBuffer(command->getHandle(), buffers[destIndex]->buffer, 0, VK_WHOLE_SIZE, clearValue); buffers[destIndex]->pipelineBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); + VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); } } @@ -485,8 +486,8 @@ IndexBuffer::IndexBuffer(PGraphics graphics, const IndexBufferCreateInfo& create VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR, createInfo.sourceData.owner, false, createInfo.name) { getAlloc()->updateContents(createInfo.sourceData.offset, createInfo.sourceData.size, createInfo.sourceData.data); - //getAlloc()->pipelineBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_INDEX_READ_BIT, - // Gfx::SE_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR | Gfx::SE_PIPELINE_STAGE_VERTEX_INPUT_BIT); + // getAlloc()->pipelineBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_INDEX_READ_BIT, + // Gfx::SE_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR | Gfx::SE_PIPELINE_STAGE_VERTEX_INPUT_BIT); } IndexBuffer::~IndexBuffer() {} diff --git a/src/Engine/Graphics/Vulkan/Command.cpp b/src/Engine/Graphics/Vulkan/Command.cpp index 9b14b89..ea024bf 100644 --- a/src/Engine/Graphics/Vulkan/Command.cpp +++ b/src/Engine/Graphics/Vulkan/Command.cpp @@ -269,8 +269,7 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptor) { VkDescriptorSet setHandle = descriptorSet->getHandle(); Gfx::PPipelineLayout layout = pipeline != nullptr ? pipeline->getPipelineLayout() : rtPipeline->getPipelineLayout(); vkCmdBindDescriptorSets(handle, pipeline != nullptr ? VK_PIPELINE_BIND_POINT_GRAPHICS : VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, - pipeline->getLayout(), layout->findParameter(descriptorSet->getName()), 1, &setHandle, 0, - nullptr); + pipeline->getLayout(), layout->findParameter(descriptorSet->getName()), 1, &setHandle, 0, nullptr); } void RenderCommand::bindDescriptor(const Array& descriptorSets) { @@ -286,9 +285,9 @@ void RenderCommand::bindDescriptor(const Array& descriptorS for (auto& binding : descriptorSet->boundResources) { for (auto& res : binding) { - // partially bound descriptors can include nulls + // partially bound descriptors can include nulls if (res != nullptr) { - res->bind(); + res->bind(); boundResources.add(res); } } @@ -442,8 +441,7 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptor) { VkDescriptorSet setHandle = descriptorSet->getHandle(); vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), - pipeline->getPipelineLayout()->findParameter(descriptorSet->getName()), 1, &setHandle,0, - nullptr); + pipeline->getPipelineLayout()->findParameter(descriptorSet->getName()), 1, &setHandle, 0, nullptr); } void ComputeCommand::bindDescriptor(const Array& descriptorSets) { @@ -465,8 +463,8 @@ void ComputeCommand::bindDescriptor(const Array& descriptor } sets[pipeline->getPipelineLayout()->findParameter(descriptorSet->getName())] = descriptorSet->getHandle(); } - vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), 0, (uint32)descriptorSets.size(), sets, - 0, nullptr); + vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), 0, (uint32)descriptorSets.size(), sets, 0, + nullptr); delete[] sets; } diff --git a/src/Engine/Graphics/Vulkan/Descriptor.cpp b/src/Engine/Graphics/Vulkan/Descriptor.cpp index 42583fe..77187b1 100644 --- a/src/Engine/Graphics/Vulkan/Descriptor.cpp +++ b/src/Engine/Graphics/Vulkan/Descriptor.cpp @@ -161,6 +161,14 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() { if (cachedHandles[setIndex]->getHandle() == VK_NULL_HANDLE) { // If it hasnt been initialized, allocate it VK_CHECK(vkAllocateDescriptorSets(graphics->getDevice(), &allocInfo, &cachedHandles[setIndex]->setHandle)); + VkDebugUtilsObjectNameInfoEXT nameInfo = { + .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT, + .pNext = nullptr, + .objectType = VK_OBJECT_TYPE_DESCRIPTOR_SET, + .objectHandle = (uint64)cachedHandles[setIndex]->setHandle, + .pObjectName = name.c_str(), + }; + vkSetDebugUtilsObjectNameEXT(graphics->getDevice(), &nameInfo); } PDescriptorSet vulkanSet = cachedHandles[setIndex]; @@ -193,6 +201,7 @@ DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner) boundResources.resize(owner->getLayout()->getBindings().size()); for (uint32 i = 0; i < boundResources.size(); ++i) { boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount); + std::memset(boundResources[i].data(), 0, sizeof(PCommandBoundResource) * boundResources[i].size()); } constantData.resize(owner->getLayout()->constantsSize); } @@ -208,9 +217,10 @@ void DescriptorSet::updateBuffer(const std::string& mappingName, uint32 index, G PShaderBuffer vulkanBuffer = shaderBuffer.cast(); const auto& map = owner->getLayout()->mappings[mappingName]; uint32 binding = map.binding; - if (boundResources[binding][index] == vulkanBuffer->getAlloc() || vulkanBuffer->getAlloc() == nullptr) { + // if the buffer is empty + if (vulkanBuffer->getAlloc() == nullptr) return; - } + bufferInfos.add(VkDescriptorBufferInfo{ .buffer = vulkanBuffer->getHandle(), .offset = 0, @@ -234,9 +244,10 @@ void DescriptorSet::updateBuffer(const std::string& mappingName, uint32 index, G PVertexBuffer vulkanBuffer = indexBuffer.cast(); const auto& map = owner->getLayout()->mappings[mappingName]; uint32 binding = map.binding; - if (boundResources[binding][index] == vulkanBuffer->getAlloc() || vulkanBuffer->getAlloc() == nullptr) { + // if the buffer is empty + if (vulkanBuffer->getAlloc() == nullptr) return; - } + bufferInfos.add(VkDescriptorBufferInfo{ .buffer = vulkanBuffer->getHandle(), @@ -261,9 +272,9 @@ void DescriptorSet::updateBuffer(const std::string& mappingName, uint32 index, G PIndexBuffer vulkanBuffer = indexBuffer.cast(); const auto& map = owner->getLayout()->mappings[mappingName]; uint32 binding = map.binding; - if (boundResources[binding][index] == vulkanBuffer->getAlloc() || vulkanBuffer->getAlloc() == nullptr) { + // if the buffer is empty + if (vulkanBuffer->getAlloc() == nullptr) return; - } bufferInfos.add(VkDescriptorBufferInfo{ .buffer = vulkanBuffer->getHandle(), diff --git a/src/Engine/Graphics/Vulkan/Window.cpp b/src/Engine/Graphics/Vulkan/Window.cpp index 300ecbd..cb97ef2 100644 --- a/src/Engine/Graphics/Vulkan/Window.cpp +++ b/src/Engine/Graphics/Vulkan/Window.cpp @@ -295,8 +295,7 @@ Viewport::Viewport(PWindow owner, const ViewportCreateInfo& viewportInfo) : Gfx: handle.width = static_cast(sizeX); handle.height = static_cast(sizeY); handle.x = static_cast(offsetX); - handle.y = static_cast(offsetY) + handle.height; - handle.height = -handle.height; + handle.y = static_cast(offsetY); handle.minDepth = 1.f; handle.maxDepth = 0.f; } @@ -307,8 +306,7 @@ void Viewport::resize(uint32 newX, uint32 newY) { sizeX = newX; sizeY = newY; handle.width = static_cast(sizeX); - handle.y = static_cast(sizeY + offsetX); - handle.height = -static_cast(sizeY); + handle.height = static_cast(sizeY); } void Viewport::move(uint32 newOffsetX, uint32 newOffsetY) { diff --git a/src/Engine/Graphics/Window.cpp b/src/Engine/Graphics/Window.cpp index b33cc6d..d148dff 100644 --- a/src/Engine/Graphics/Window.cpp +++ b/src/Engine/Graphics/Window.cpp @@ -20,19 +20,13 @@ Viewport::~Viewport() {} Matrix4 Viewport::getProjectionMatrix() const { if (fieldOfView > 0.0f) { - // float h = 1.0 / tan(fieldOfView * 0.5); - // float w = h / (sizeX / static_cast(sizeY)); - // float zFar = 1000.0f; - // float zNear = 0.1f; - // float a = -zNear / (zFar - zNear); - // float b = (zNear * zFar) / (zFar - zNear); - // return Matrix4( - // w, 0, 0, 0, - // 0, -h, 0, 0, - // 0, 0, a, b, - // 0, 0, 1, 0 - //); - return glm::perspective(fieldOfView, sizeX / static_cast(sizeY), 0.1f, 1000.0f); + Matrix4 projectionMatrix = glm::perspective(fieldOfView, sizeX / static_cast(sizeY), 0.1f, 1000.0f); + Matrix4 correctionMatrix = Matrix4( + 1, 0, 0, 0, + 0, -1, 0, 0, + 0, 0, 1 / 2.f, 0, + 0, 0, 1 / 2.f, 1); + return correctionMatrix * projectionMatrix; } else { return glm::ortho(0.0f, (float)sizeX, (float)sizeY, 0.0f); } diff --git a/src/Engine/Scene/LightEnvironment.cpp b/src/Engine/Scene/LightEnvironment.cpp index fbbd1a6..e293840 100644 --- a/src/Engine/Scene/LightEnvironment.cpp +++ b/src/Engine/Scene/LightEnvironment.cpp @@ -28,6 +28,10 @@ LightEnvironment::LightEnvironment(Gfx::PGraphics graphics) .name = "irradianceMap", .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, }); + layout->addDescriptorBinding(Gfx::DescriptorBinding{ + .name = "irradianceSampler", + .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER, + }); layout->create(); directionalLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{ @@ -78,6 +82,7 @@ void LightEnvironment::commit() { set->updateConstants("numDirectionalLights", 0, &numDirectionalLights); set->updateBuffer("directionalLights", 0, directionalLights); set->updateTexture("irradianceMap", 0, environment->getIrradianceMap()); + set->updateSampler("irradianceSampler", 0, environmentSampler); set->writeChanges(); } diff --git a/src/Engine/System/CameraUpdater.cpp b/src/Engine/System/CameraUpdater.cpp index c561b76..a6ae03f 100644 --- a/src/Engine/System/CameraUpdater.cpp +++ b/src/Engine/System/CameraUpdater.cpp @@ -9,6 +9,6 @@ CameraUpdater::~CameraUpdater() {} void CameraUpdater::update(Component::Camera& camera, Component::Transform& transform) { Vector eyePos = transform.getPosition(); - Vector lookAt = eyePos - transform.getForward(); - camera.viewMatrix = glm::lookAtLH(eyePos, lookAt, Vector(0, 1, 0)); + Vector lookAt = eyePos + transform.getForward(); + camera.viewMatrix = glm::lookAt(eyePos, lookAt, Vector(0, 1, 0)); }