adding post processing

This commit is contained in:
2025-05-31 18:03:36 +02:00
parent 88fead6cfc
commit 4319c4096b
18 changed files with 244 additions and 11 deletions

View File

@@ -4,7 +4,6 @@
#include <memory>
#include <string>
#include <string_view>
#include <map>
#include <Utils/NonOwningPtr.h>
@@ -24,11 +23,14 @@ namespace Scop
struct SceneDescriptor
{
std::shared_ptr<Shader> fragment_shader;
std::shared_ptr<Shader> post_process_shader = nullptr;
std::shared_ptr<BaseCamera> camera;
CullMode culling;
std::size_t post_process_data_size = 0;
bool render_3D_enabled = true;
bool render_2D_enabled = true;
bool render_skybox_enabled = true;
bool render_post_process_enabled = false;
};
class Scene
@@ -44,6 +46,13 @@ namespace Scop
bool wireframe = false;
};
struct PostProcessData
{
std::shared_ptr<DescriptorSet> set;
std::shared_ptr<UniformBuffer> data_buffer;
CPUBuffer data;
};
public:
Scene(std::string_view name, SceneDescriptor desc);
Scene(std::string_view name, SceneDescriptor desc, NonOwningPtr<Scene> parent);
@@ -67,6 +76,7 @@ namespace Scop
void SwitchToParent() const noexcept;
[[nodiscard]] inline ForwardData& GetForwardData() noexcept { return m_forward; }
[[nodiscard]] inline PostProcessData& GetPostProcessData() noexcept { return m_post_process; }
[[nodiscard]] inline const std::unordered_map<std::uint64_t, Actor>& GetActors() const noexcept { return m_actors; }
[[nodiscard]] inline const std::unordered_map<std::uint64_t, Sprite>& GetSprites() const noexcept { return m_sprites; }
[[nodiscard]] inline const std::string& GetName() const noexcept { return m_name; }
@@ -88,6 +98,7 @@ namespace Scop
private:
GraphicPipeline m_pipeline;
ForwardData m_forward;
PostProcessData m_post_process;
DepthImage m_depth;
SceneDescriptor m_descriptor;
std::shared_ptr<CubeTexture> p_skybox;

View File

@@ -87,7 +87,7 @@ namespace Scop
{
std::vector<VkFormat> candidates = { VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT };
VkFormat format = kvfFindSupportFormatInCandidates(RenderCore::Get().GetDevice(), candidates.data(), candidates.size(), VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
Image::Init(ImageType::Depth, width, height, format, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, is_multisampled, std::move(name));
Image::Init(ImageType::Depth, width, height, format, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, is_multisampled, std::move(name));
Image::TransitionLayout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
Image::CreateImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_DEPTH_BIT);
}

View File

@@ -85,6 +85,18 @@ namespace Scop
}
}, {}
);
static const Scop::ShaderLayout PostProcessShaderLayout(
{
{ 0,
Scop::ShaderSetLayout({
{ 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER },
{ 1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER },
{ 2, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER }
})
}
}, {}
);
}
#endif

View File

@@ -5,6 +5,7 @@
#include <Renderer/RenderPasses/SkyboxPass.h>
#include <Renderer/RenderPasses/ForwardPass.h>
#include <Renderer/RenderPasses/FinalPass.h>
#include <Renderer/RenderPasses/PostProcessPass.h>
#include <Renderer/RenderPasses/2DPass.h>
namespace Scop
@@ -21,6 +22,7 @@ namespace Scop
private:
SkyboxPass m_skybox;
Render2DPass m_2Dpass;
PostProcessPass m_post_process;
FinalPass m_final;
Texture m_main_render_texture;
ForwardPass m_forward;

View File

@@ -0,0 +1,28 @@
#ifndef __SCOP_POST_PROCESS_PASS__
#define __SCOP_POST_PROCESS_PASS__
#include <Renderer/Descriptor.h>
#include <Renderer/Pipelines/Shader.h>
#include <Renderer/Pipelines/Graphics.h>
namespace Scop
{
class PostProcessPass
{
public:
PostProcessPass() = default;
void Init();
void Pass(class Scene& scene, class Renderer& renderer, class Texture& render_target);
void Destroy();
[[nodiscard]] inline Texture& GetProcessTexture() noexcept { return m_render_texture; }
~PostProcessPass() = default;
private:
GraphicPipeline m_pipeline;
Texture m_render_texture;
std::shared_ptr<Shader> p_vertex_shader;
};
}
#endif

View File

@@ -26,6 +26,21 @@ namespace Scop
return buffer;
}
inline void Allocate(std::size_t size)
{
if(m_data != nullptr)
FatalError("cannot allocate an already allocated CPU buffer");
try
{
m_data = std::make_shared<std::uint8_t[]>(size);
m_size = size;
}
catch(...)
{
FatalError("memory allocation for a CPU buffer failed");
}
}
inline bool Empty() const { return m_size == 0; }
[[nodiscard]] inline std::size_t GetSize() const noexcept { return m_size; }