Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
GameWin221 committed May 20, 2022
2 parents c4ef98c + d95a42f commit 17eca86
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 29 deletions.
12 changes: 8 additions & 4 deletions EruptionEngine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@
<LinkIncremental>true</LinkIncremental>
<IntDir>$(SolutionDir)Build\$(Platform)\$(Configuration)\Intermediates\</IntDir>
<OutDir>$(SolutionDir)Build\$(Platform)\$(Configuration)\</OutDir>
<PreBuildEventUseInBuild>true</PreBuildEventUseInBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)Build\$(Platform)\$(Configuration)\Intermediates\</IntDir>
<OutDir>$(SolutionDir)Build\$(Platform)\$(Configuration)\</OutDir>
<PreBuildEventUseInBuild>true</PreBuildEventUseInBuild>
</PropertyGroup>
<PropertyGroup Label="Vcpkg">
<VcpkgEnabled>false</VcpkgEnabled>
Expand Down Expand Up @@ -144,8 +146,8 @@
</Command>
</PostBuildEvent>
<PreBuildEvent>
<Command>cd $(SolutionDir)Shaders\
compile.bat</Command>
<Command>
</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand Down Expand Up @@ -177,8 +179,8 @@ compile.bat</Command>
</Command>
</PostBuildEvent>
<PreBuildEvent>
<Command>cd $(SolutionDir)Shaders\
compile.bat</Command>
<Command>
</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down Expand Up @@ -295,6 +297,8 @@ compile.bat</Command>
</ItemGroup>
<ItemGroup>
<None Include="EruptionEngine.ini" />
<None Include="Shaders\DepthFragment.frag" />
<None Include="Shaders\DepthVertex.vert" />
<None Include="Shaders\GeometryFragment.frag">
<FileType>Document</FileType>
</None>
Expand Down
2 changes: 2 additions & 0 deletions EruptionEngine.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@
<None Include="Shaders\LightingFrag.frag" />
<None Include="Shaders\FullscreenTriVert.vert" />
<None Include="Shaders\TonemapFrag.frag" />
<None Include="Shaders\DepthFragment.frag" />
<None Include="Shaders\DepthVertex.vert" />
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="Shaders\GeometryFragment.spv" />
Expand Down
3 changes: 3 additions & 0 deletions Shaders/DepthFragment.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#version 450

void main(){}
Binary file added Shaders/DepthFragment.spv
Binary file not shown.
Binary file added Shaders/DepthVertex.spv
Binary file not shown.
22 changes: 22 additions & 0 deletions Shaders/DepthVertex.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#version 450

layout(location = 0) in vec3 vPos;
layout(location = 1) in vec3 vNormal;
layout(location = 2) in vec3 vTangent;
layout(location = 3) in vec2 vTexcoord;

layout(set = 0, binding = 0) uniform CameraMatricesBufferObject
{
mat4 view;
mat4 proj;
} camera;

layout(push_constant) uniform PerObjectData
{
mat4 model;
} object;

void main()
{
gl_Position = camera.proj * camera.view * object.model * vec4(vPos, 1.0);
}
2 changes: 2 additions & 0 deletions Shaders/compile.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
%VULKAN_SDK%/Bin/glslc.exe FullscreenTriVert.vert -o FullscreenTriVert.spv
%VULKAN_SDK%/Bin/glslc.exe LightingFrag.frag -o LightingFrag.spv
%VULKAN_SDK%/Bin/glslc.exe TonemapFrag.frag -o TonemapFrag.spv
%VULKAN_SDK%/Bin/glslc.exe DepthFragment.frag -o DepthFragment.spv
%VULKAN_SDK%/Bin/glslc.exe DepthVertex.vert -o DepthVertex.spv

pause
6 changes: 3 additions & 3 deletions Source/Core/Eruption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ void Eruption::Init()
EN_LOG("Eruption::Init() - Started");

en::WindowInfo windowInfo{};
windowInfo.title = "Eruption Engine v0.5.2";
windowInfo.resizable = true;
windowInfo.title = "Eruption Engine v0.5.3";
windowInfo.resizable = true;
windowInfo.fullscreen = false;
windowInfo.size = glm::ivec2(1920, 1080);
windowInfo.size = glm::ivec2(1920, 1080);

m_Window = new en::Window(windowInfo);

Expand Down
9 changes: 7 additions & 2 deletions Source/Renderer/Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ namespace en
pipelineInfo.pushConstantRanges = m_PushConstantRanges;
pipelineInfo.useVertexBindings = m_UseVertexBindings;
pipelineInfo.enableDepthTest = m_EnableDepthTest;
pipelineInfo.enableDepthWrite = m_EnableDepthWrite;
pipelineInfo.blendEnable = m_BlendEnable;
pipelineInfo.compareOp = m_CompareOp;
pipelineInfo.cullMode = m_CullMode;
pipelineInfo.polygonMode = m_PolygonMode;

Expand Down Expand Up @@ -160,8 +162,11 @@ namespace en

m_UseVertexBindings = pipeline.useVertexBindings;
m_EnableDepthTest = pipeline.enableDepthTest;
m_EnableDepthWrite = pipeline.enableDepthWrite;
m_BlendEnable = pipeline.blendEnable;

m_CompareOp = pipeline.compareOp;

m_CullMode = pipeline.cullMode;
m_PolygonMode = pipeline.polygonMode;

Expand Down Expand Up @@ -249,8 +254,8 @@ namespace en
VkPipelineDepthStencilStateCreateInfo depthStencil{};
depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
depthStencil.depthTestEnable = pipeline.enableDepthTest;
depthStencil.depthWriteEnable = VK_TRUE;
depthStencil.depthCompareOp = VK_COMPARE_OP_LESS;
depthStencil.depthWriteEnable = pipeline.enableDepthWrite;
depthStencil.depthCompareOp = pipeline.compareOp;
depthStencil.depthBoundsTestEnable = VK_FALSE;
depthStencil.minDepthBounds = 0.0f;
depthStencil.maxDepthBounds = 1.0f;
Expand Down
8 changes: 7 additions & 1 deletion Source/Renderer/Pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ namespace en
std::vector<VkPushConstantRange> pushConstantRanges;

bool useVertexBindings = false;
bool enableDepthTest = false;
bool enableDepthTest = false;
bool enableDepthWrite = true;
bool blendEnable = false;

VkCompareOp compareOp = VK_COMPARE_OP_LESS;

VkCullModeFlags cullMode = VK_CULL_MODE_BACK_BIT;
VkPolygonMode polygonMode = VK_POLYGON_MODE_FILL;
};
Expand Down Expand Up @@ -81,8 +84,11 @@ namespace en

bool m_UseVertexBindings;
bool m_EnableDepthTest;
bool m_EnableDepthWrite;
bool m_BlendEnable;

VkCompareOp m_CompareOp;

VkCullModeFlags m_CullMode;
VkPolygonMode m_PolygonMode;
};
Expand Down
1 change: 1 addition & 0 deletions Source/Renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace en
{
m_Backend.BeginRender();

m_Backend.DepthPass();
m_Backend.GeometryPass();
m_Backend.LightingPass();
m_Backend.PostProcessPass();
Expand Down
121 changes: 116 additions & 5 deletions Source/Renderer/RendererBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ namespace en

CreateSwapchain();

EN_SUCCESS("Created swapchain!")
EN_SUCCESS("Created swapchain!")

CreateDepthBufferAttachments();

EN_SUCCESS("Created depth attachments!")

CreateGBufferAttachments();

Expand All @@ -39,9 +43,17 @@ namespace en

EN_SUCCESS("Created command buffer!")

InitDepthPipeline();

EN_SUCCESS("Created depth pipeline!")

InitGeometryPipeline();

EN_SUCCESS("Created geometry pipeline!")
EN_SUCCESS("Created geometry pipeline!")

CreateDepthBufferHandle();

EN_SUCCESS("Created depth buffer handle!")

CreateGBufferHandle();

Expand Down Expand Up @@ -139,6 +151,41 @@ namespace en
if (vkBeginCommandBuffer(m_CommandBuffer, &beginInfo) != VK_SUCCESS)
EN_ERROR("VulkanRendererBackend::BeginRender() - Failed to begin recording command buffer!");
}
void VulkanRendererBackend::DepthPass()
{
if (m_SkipFrame || !m_Scene) return;

static std::vector<VkClearValue> clearValues(1);
clearValues[0].depthStencil = { 1.0f, 0 };

m_DepthPipeline->Bind(m_CommandBuffer, m_DepthBuffer->m_Framebuffer, m_Swapchain.extent, clearValues);

// Bind the m_MainCamera once per geometry pass
m_MainCamera->Bind(m_CommandBuffer, m_DepthPipeline->m_Layout, m_CameraMatrices.get());

for (const auto& sceneObjectPair : m_Scene->m_SceneObjects)
{
SceneObject* object = sceneObjectPair.second.get();

if (!object->m_Active || !object->m_Mesh->m_Active) continue;

// Bind object data (model matrix) once per SceneObject in the m_RenderQueue
object->GetObjectData().Bind(m_CommandBuffer, m_DepthPipeline->m_Layout);

for (const auto& subMesh : object->m_Mesh->m_SubMeshes)
{
if (!subMesh.m_Active) continue;

// Bind SubMesh buffers and material once for each SubMesh in the sceneObject->m_Mesh->m_SubMeshes vector
subMesh.m_VertexBuffer->Bind(m_CommandBuffer);
subMesh.m_IndexBuffer->Bind(m_CommandBuffer);

vkCmdDrawIndexed(m_CommandBuffer, subMesh.m_IndexBuffer->GetIndicesCount(), 1, 0, 0, 0);
}
}

m_DepthPipeline->Unbind(m_CommandBuffer);
}
void VulkanRendererBackend::GeometryPass()
{
if (m_SkipFrame || !m_Scene) return;
Expand All @@ -148,6 +195,7 @@ namespace en
clearValues[1].color = m_BlackClearValue.color;
clearValues[2].color = m_BlackClearValue.color;
clearValues[3].depthStencil = { 1.0f, 0 };
clearValues[3].color = { 0.0f, 0.0f, 0.0f };

m_GeometryPipeline->Bind(m_CommandBuffer, m_GBuffer->m_Framebuffer, m_Swapchain.extent, clearValues);

Expand Down Expand Up @@ -343,15 +391,24 @@ namespace en

m_Swapchain.Destroy(m_Ctx->m_LogicalDevice);

m_GBuffer->m_Attachments[3] = Framebuffer::Attachment{};

m_GBuffer->Destroy();
m_DepthBuffer->Destroy();
m_HDRFramebuffer->Destroy();

CreateSwapchain();

CreateDepthBufferAttachments();

CreateGBufferAttachments();

m_DepthPipeline->Resize(m_Swapchain.extent);

m_GeometryPipeline->Resize(m_Swapchain.extent);

CreateDepthBufferHandle();

CreateGBufferHandle();

CreateLightingHDRFramebuffer();
Expand Down Expand Up @@ -471,6 +528,56 @@ namespace en
}
}

void VulkanRendererBackend::CreateDepthBufferHandle()
{
m_DepthBuffer->CreateFramebuffer(m_DepthPipeline->m_RenderPass);
}
void VulkanRendererBackend::CreateDepthBufferAttachments()
{
if (!m_DepthBuffer)
m_DepthBuffer = std::make_unique<Framebuffer>();

Framebuffer::AttachmentInfo depth{};
depth.format = FindDepthFormat();
depth.imageFinalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
depth.imageAspectFlags = VK_IMAGE_ASPECT_DEPTH_BIT;
depth.imageUsageFlags = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;

m_DepthBuffer->CreateSampler();
m_DepthBuffer->CreateAttachments({ depth }, m_Swapchain.extent.width, m_Swapchain.extent.height);
}
void VulkanRendererBackend::InitDepthPipeline()
{
m_DepthPipeline = std::make_unique<Pipeline>();

Pipeline::Attachment depthAttachment{ FindDepthFormat(), VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 0U };

Pipeline::RenderPassInfo renderPassInfo{};
renderPassInfo.depthAttachment = depthAttachment;

m_DepthPipeline->CreateRenderPass(renderPassInfo);

Shader vShader("Shaders/DepthVertex.spv", ShaderType::Vertex);
Shader fShader("Shaders/DepthFragment.spv", ShaderType::Fragment);

VkPushConstantRange objectPushConstant{};
objectPushConstant.offset = 0U;
objectPushConstant.size = sizeof(PerObjectData);
objectPushConstant.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;

Pipeline::PipelineInfo pipelineInfo{};
pipelineInfo.vShader = &vShader;
pipelineInfo.fShader = &fShader;
pipelineInfo.extent = m_Swapchain.extent;
pipelineInfo.descriptorLayouts = { CameraMatricesBuffer::GetLayout() };
pipelineInfo.pushConstantRanges = { objectPushConstant };
pipelineInfo.enableDepthTest = true;
pipelineInfo.useVertexBindings = true;

m_DepthPipeline->CreatePipeline(pipelineInfo);
m_DepthPipeline->CreateSyncSemaphore();
}

void VulkanRendererBackend::InitGeometryPipeline()
{
m_GeometryPipeline = std::make_unique<Pipeline>();
Expand All @@ -482,7 +589,7 @@ namespace en
{m_GBuffer->m_Attachments[2].format, VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_UNDEFINED , VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 2U}
};

Pipeline::Attachment depthAttachment{ m_GBuffer->m_Attachments[3].format , VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 3U };
Pipeline::Attachment depthAttachment{ m_GBuffer->m_Attachments[3].format, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 3U };

Pipeline::RenderPassInfo renderPassInfo{};
renderPassInfo.colorAttachments = colorAttachments;
Expand All @@ -494,8 +601,8 @@ namespace en
Shader fShader("Shaders/GeometryFragment.spv", ShaderType::Fragment);

VkPushConstantRange objectPushConstant{};
objectPushConstant.offset = 0U;
objectPushConstant.size = sizeof(PerObjectData);
objectPushConstant.offset = 0U;
objectPushConstant.size = sizeof(PerObjectData);
objectPushConstant.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;

Pipeline::PipelineInfo pipelineInfo{};
Expand All @@ -505,6 +612,8 @@ namespace en
pipelineInfo.descriptorLayouts = { CameraMatricesBuffer::GetLayout(), Material::GetLayout() };
pipelineInfo.pushConstantRanges = { objectPushConstant };
pipelineInfo.enableDepthTest = true;
pipelineInfo.enableDepthWrite = false;
pipelineInfo.compareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
pipelineInfo.useVertexBindings = true;

m_GeometryPipeline->CreatePipeline(pipelineInfo);
Expand Down Expand Up @@ -668,6 +777,8 @@ namespace en

m_GBuffer->CreateSampler();
m_GBuffer->CreateAttachments({ albedo , position, normal, depth }, m_Swapchain.extent.width, m_Swapchain.extent.height);

m_GBuffer->m_Attachments[3] = m_DepthBuffer->m_Attachments[0];
}

void VulkanRendererBackend::CreateLightingHDRFramebuffer()
Expand Down
Loading

0 comments on commit 17eca86

Please sign in to comment.