SpiecsEngine
 
Loading...
Searching...
No Matches
RayTracingRenderer.h
Go to the documentation of this file.
1/**
2* @file RayTracingRenderer.h.
3* @brief The RayTracingRenderer Class Definitions.
4* @author Spices.
5*/
6
7#pragma once
8#include "Core/Core.h"
9#include "Render/Renderer/Renderer.h"
10
11namespace Spices {
12
13 class VulkanRayTracing;
14
15 namespace RayTracingR {
16
18 {
19 std::array<SpicesShader::DirectionalLight, SpicesShader::DIRECTIONALLIGHT_BUFFER_MAXNUM> lights;
20 };
21
23 {
24 std::array<SpicesShader::PointLight, SpicesShader::POINTLIGHT_BUFFER_MAXNUM> lights;
25 };
26
28 {
30 };
31
32 }
33
34 /**
35 * @brief RayTracingRenderer Class.
36 * This class defines the ray tracing behaves.
37 */
39 {
40 public:
41
42 /**
43 * @brief Constructor Function.
44 * Init member variables.
45 * @param[in] rendererName The name of this Renderer.
46 * @param[in] vulkanState The core vulkan objects that in use.
47 * @param[in] descriptorPool The DescriptorPool.
48 * @param[in] device The VulkanDevice, used for format query.
49 * @param[in] rendererResourcePool The RendererResourcePool, RT Pool.
50 */
52 const std::string& rendererName ,
53 VulkanState& vulkanState ,
54 const std::shared_ptr<VulkanDescriptorPool>& descriptorPool ,
55 const std::shared_ptr<VulkanDevice>& device ,
56 const std::shared_ptr<RendererResourcePool>& rendererResourcePool
57 );
58
59 /**
60 * @brief Destructor Function.
61 */
62 virtual ~RayTracingRenderer() override;
63
64 /**
65 * @brief The interface is inherited from Renderer.
66 * @param[in] ts TimeStep.
67 * @param[in] frameInfo The current frame data.
68 */
69 virtual void Render(TimeStep& ts, FrameInfo& frameInfo) override;
70
71 /**
72 * @brief Get RayTracing AccelerationStructure.
73 * @return Returns RayTracing AccelerationStructure.
74 */
76
77 private:
78
79 /**
80 * @brief The interface is inherited from Renderer.
81 * Create specific render pass.
82 */
83 virtual void CreateRendererPass() override;
84
85 /**
86 * @brief The interface is inherited from Renderer.
87 * Create specific descriptor set for sub pass.
88 */
89 virtual void CreateDescriptorSet() override;
90
91 /**
92 * @breif This interface is called on world mark query tick (registry by MeshComponent).
93 */
94 virtual void OnMeshAddedWorld() override;
95
96 /**
97 * @brief The interface is inherited from Renderer.
98 * Create Material Specific Pipeline.
99 * @param[in] material Registry material.
100 * @param[in] layout VkPipelineLayout.
101 * @param[in] subPass Handled subPass.
102 */
103 virtual void CreatePipeline(
104 std::shared_ptr<Material> material ,
105 VkPipelineLayout& layout ,
106 std::shared_ptr<RendererSubPass> subPass
107 ) override;
108
109 private:
110
111 /**
112 * @brief Create BottomLevelAS with all MeshComponents.
113 * @param[in] frameInfo FrameInfo.
114 * @param[in] view Component View.
115 * @param[in] rayTracingInstance VulkanRayTracingInstance.
116 */
118 FrameInfo& frameInfo,
119 std::shared_ptr<std::vector<uint32_t>> view,
120 std::shared_ptr<VulkanRayTracing> rayTracingInstance
121 );
122
123 /**
124 * @brief Create TopLevelAS.
125 * @param[in] frameInfo FrameInfo.
126 * @param[in] view Component View.
127 * @param[in] rayTracingInstance VulkanRayTracingInstance.
128 * @param[in] update default false.
129 */
130 void CreateTopLevelAS(
131 FrameInfo& frameInfo,
132 std::shared_ptr<std::vector<uint32_t>> view,
133 std::shared_ptr<VulkanRayTracing> rayTracingInstance,
134 bool update = false
135 );
136
137 /**
138 * @brief Update TopLevelAS.
139 * @param[in] frameInfo FrameInfo.
140 * @param[in] rayTracingInstance VulkanRayTracingInstance.
141 * @param[in] update default true.
142 * @todo Event Queue.
143 */
144 void UpdateTopLevelAS(
145 FrameInfo& frameInfo,
146 std::shared_ptr<VulkanRayTracing> rayTracingInstance,
147 bool update = true
148 );
149
150 /**
151 * @brief Create Shader Binding Table.
152 * @param[in] rayTracingInstance VulkanRayTracingInstance.
153 */
154 void CreateRTShaderBindingTable(std::shared_ptr<VulkanRayTracing> rayTracingInstance);
155
156 private:
157
158 /**
159 * @brief Get HitGroupsCache.
160 * @return Returns HitGroupsCache.
161 */
163
164 /**
165 * @brief Set HitGroupsCache.
166 * @param[in] cache HitGroupsCache.
167 */
168 void SetHitGroupsCache(std::shared_ptr<std::unordered_map<std::string, uint32_t>> cache) { m_HitGroupsCache = cache; }
169
170 private:
171
172 /**
173 * @brief In Used VulkanRayTracing.
174 */
175 static std::shared_ptr<VulkanRayTracing> m_VulkanRayTracing;
176
177 /**
178 * @brief Hit groups cached data.
179 */
181 };
182}
#define SPICES_PROFILE_ZONEN(...)
#define SPICES_PROFILE_ZONE
static FrameInfo & Get()
Get FrameInfo.
Definition FrameInfo.cpp:14
RendererType m_RendererType
The renderer type of current world.
Definition FrameInfo.h:99
FrameInfo Class. This class defines the FrameInfo data.
Definition FrameInfo.h:32
Material Class. This class contains a branch of parameter and shader, also descriptor.
Definition Material.h:62
MeshComponent Class. This class defines the specific behaves of MeshComponent.
virtual void CreateDescriptorSet() override
The interface is inherited from Renderer. Create specific descriptor set for sub pass.
static std::shared_ptr< VulkanRayTracing > m_VulkanRayTracing
In Used VulkanRayTracing.
void CreateTopLevelAS(FrameInfo &frameInfo, std::shared_ptr< std::vector< uint32_t > > view, std::shared_ptr< VulkanRayTracing > rayTracingInstance, bool update=false)
Create TopLevelAS.
static VkAccelerationStructureKHR GetAccelerationStructure()
Get RayTracing AccelerationStructure.
void SetHitGroupsCache(std::shared_ptr< std::unordered_map< std::string, uint32_t > > cache)
Set HitGroupsCache.
virtual void CreatePipeline(std::shared_ptr< Material > material, VkPipelineLayout &layout, std::shared_ptr< RendererSubPass > subPass) override
The interface is inherited from Renderer. Create Material Specific Pipeline.
virtual void Render(TimeStep &ts, FrameInfo &frameInfo) override
The interface is inherited from Renderer.
RayTracingRenderer(const std::string &rendererName, VulkanState &vulkanState, const std::shared_ptr< VulkanDescriptorPool > &descriptorPool, const std::shared_ptr< VulkanDevice > &device, const std::shared_ptr< RendererResourcePool > &rendererResourcePool)
Constructor Function. Init member variables.
virtual void OnMeshAddedWorld() override
virtual ~RayTracingRenderer() override
Destructor Function.
std::shared_ptr< std::unordered_map< std::string, uint32_t > > GetHitGroupsCache()
Get HitGroupsCache.
std::shared_ptr< std::unordered_map< std::string, uint32_t > > m_HitGroupsCache
Hit groups cached data.
void CreateRTShaderBindingTable(std::shared_ptr< VulkanRayTracing > rayTracingInstance)
Create Shader Binding Table.
virtual void CreateRendererPass() override
The interface is inherited from Renderer. Create specific render pass.
void CreateBottomLevelAS(FrameInfo &frameInfo, std::shared_ptr< std::vector< uint32_t > > view, std::shared_ptr< VulkanRayTracing > rayTracingInstance)
Create BottomLevelAS with all MeshComponents.
void UpdateTopLevelAS(FrameInfo &frameInfo, std::shared_ptr< VulkanRayTracing > rayTracingInstance, bool update=true)
Update TopLevelAS.
RayTracingRenderer Class. This class defines the ray tracing behaves.
RendererResourcePool Class. This class is a pool of all framebuffer's attachment.
This Class Combines some data relative to sub pass. Usually as a member variable of RendererPass.
virtual void EndRenderPass() override
End this Renderer's RenderPass.
void TraceRays() const
Call vkCmdTraceRaysKHR here.
virtual void BeginRenderPass() override
Begin this Renderer's RenderPass.
This class helps to bind pipeline and bind buffer. Specific for RayTracing Renderer....
Definition Renderer.h:1558
RendererPassBuilder & EndSubPass()
End recording a sub pass.
void Build() const
Build the RendererPass.
RendererPassBuilder & AddSubPass(const std::string &subPassName, Querier::StatisticsFlags flags=Querier::ALL)
Add a new SubPass to Renderer Pass.
virtual void OnMeshAddedWorld()
Definition Renderer.cpp:86
Renderer(const std::string &rendererName, VulkanState &vulkanState, const std::shared_ptr< VulkanDescriptorPool > &DescriptorPool, const std::shared_ptr< VulkanDevice > &device, const std::shared_ptr< RendererResourcePool > &rendererResourcePool, bool isLoadDefaultMaterial=true)
Constructor Function. Init member variables.
Definition Renderer.cpp:16
void GetDirectionalLight(FrameInfo &frameInfo, std::array< SpicesShader::DirectionalLight, SpicesShader::DIRECTIONALLIGHT_BUFFER_MAXNUM > &dLightBuffer)
Get DirectionalLightComponent's render data in World.
Definition Renderer.cpp:371
void GetPointLight(FrameInfo &frameInfo, std::array< SpicesShader::PointLight, SpicesShader::POINTLIGHT_BUFFER_MAXNUM > &pLightBuffer)
Get PointLightComponent's render data in World.
Definition Renderer.cpp:445
Renderer Class. This class defines the basic behaves of renderer. When we add an new Renderer,...
Definition Renderer.h:57
SkyBoxComponent Class. This class defines the specific behaves of SkyBoxComponent.
This Class handles our engine time step during frames. Global Unique.
Definition TimeStep.h:22
TransformComponent Class. This class defines the specific behaves of TransformComponent.
VulkanDescriptorPool Class. This class is the wrapper of VkDescriptorPool.
VulkanInstance Class. This class defines the VulkanDevice behave. This class is just a wrapper of vkd...
Wrapper of Scene RayTracing (KHR/VK) Features and Data.
@ NeedUpdateTLAS
Definition World.h:49
World Class. This class defines the basic behaves of World. When we create an new world,...
Definition World.h:41
RendererType
Definition FrameInfo.h:22
std::array< SpicesShader::DirectionalLight, SpicesShader::DIRECTIONALLIGHT_BUFFER_MAXNUM > lights
std::array< SpicesShader::PointLight, SpicesShader::POINTLIGHT_BUFFER_MAXNUM > lights
This struct contains all Vulkan object in used global.
Definition VulkanUtils.h:74