Skip to content

Commit c34f41e

Browse files
committed
-Dev: VXGI and new Enviroment Pass
1 parent aec0798 commit c34f41e

37 files changed

+437
-616
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ The main feautures of the library are:
2525

2626
- Forward and Deferred pipelines support.
2727
- PBR, Phong and other types of materials abstractions.
28-
- Scene and scene objects abstractions.
29-
- On the fly shader compiling.
3028
- Raytracing Support (Shadows, AO).
29+
- Global Illumination with Voxel Cone Tracing.
30+
- On the fly shader compiling.
31+
- Diffuse and Specular IBL.
32+
- Physically Based Bloom.
33+
- Ray Marched SSR.
34+
- Scene and scene objects abstractions.
3135
- Texture loading with mipmapping.
32-
- Dynamic renderer states for some graphic features.
3336
- Multipass (depth pass for shadows, SSAO and post-processing).
37+
- Dynamic renderer states for some graphic features.
3438
- Vulkan object and functionality abstraction.
35-
- IBL.
36-
- Physically Based Bloom.
37-
- Ray Marched SSR.
3839
- Simple to use user interface.
3940
- Easy to distribute source code.
40-
- Global Illumination with Voxel Cone Tracing (wip)
4141

4242
This project is a work in progress. It has a long way until becoming a decent library, there are no fancy features for now, but all the basics are here. Eventually, with time, I will be adding more advanced functionality.
4343

include/engine/core/passes/composition_pass.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ class CompositionPass : public GraphicPass
128128

129129
void update_uniforms(uint32_t frameIndex, Scene* const scene);
130130

131-
void set_envmap_descriptor(Graphics::Image env, Graphics::Image irr);
132-
133131
void update();
134132

135133
void cleanup();

include/engine/core/passes/enviroment_pass.h

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ VULKAN_ENGINE_NAMESPACE_BEGIN
1515

1616
namespace Core {
1717

18+
/*
19+
This pass does three things:
20+
- Performs a first renderpass to convert the HDRi image into a enviroment cubemap.
21+
- Performs a second renderpass to compute the diuffuse irradiance cubemap.
22+
- Performs a third renderpass to compute the specular irradiance cubemap.
23+
*/
1824
class EnviromentPass : public GraphicPass
1925
{
2026
ColorFormatType m_format;
@@ -24,15 +30,18 @@ class EnviromentPass : public GraphicPass
2430
Extent2D m_irradianceResolution;
2531

2632
public:
27-
EnviromentPass(Graphics::Device* ctx,
28-
ColorFormatType format,
29-
Extent2D extent,
30-
uint32_t irradianceResolution,
31-
Mesh* vignette)
32-
: BasePass(ctx, extent, 2, CUBEMAP_FACES, false)
33+
EnviromentPass(Graphics::Device* ctx, Mesh* vignette)
34+
: BasePass(ctx, {1, 1}, 2, CUBEMAP_FACES, false)
3335
, m_vignette(vignette)
34-
, m_format(format)
35-
, m_irradianceResolution({irradianceResolution, irradianceResolution}) {
36+
, m_format(SRGBA_32F)
37+
, m_irradianceResolution({1, 1}) {
38+
}
39+
40+
inline uint32_t get_irradiance_resolution() const {
41+
return m_irradianceResolution.width;
42+
}
43+
inline void set_irradiance_resolution(uint32_t res) {
44+
m_irradianceResolution = {res, res};
3645
}
3746

3847
void setup_attachments(std::vector<Graphics::AttachmentInfo>& attachments,
@@ -44,10 +53,12 @@ class EnviromentPass : public GraphicPass
4453

4554
void setup_shader_passes();
4655

47-
void render(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
48-
4956
void update_uniforms(uint32_t frameIndex, Scene* const scene);
5057

58+
void update();
59+
60+
void render(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
61+
5162
void cleanup();
5263
};
5364

include/engine/core/passes/geometry_pass.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ class GeometryPass : public GraphicPass
5353

5454
void render(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
5555

56+
void link_previous_images(std::vector<Graphics::Image> images);
57+
5658
void update_uniforms(uint32_t frameIndex, Scene* const scene);
5759

58-
void set_envmap_descriptor(Graphics::Image env, Graphics::Image irr);
5960
};
6061
} // namespace Core
6162
VULKAN_ENGINE_NAMESPACE_END

include/engine/core/passes/voxelization_pass.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ VULKAN_ENGINE_NAMESPACE_BEGIN
1717

1818
namespace Core {
1919

20+
/*
21+
Performs an voxelization of the direct irradiance of the scene. For setting the edges of the volume it takes into account the
22+
AABB of the scene.
23+
*/
2024
class VoxelizationPass : public GraphicPass
2125
{
2226
#ifdef USE_IMG_ATOMIC_OPERATION
@@ -48,13 +52,16 @@ class VoxelizationPass : public GraphicPass
4852

4953
void setup_shader_passes();
5054

51-
void render(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
55+
void link_previous_images(std::vector<Graphics::Image> images);
5256

5357
void update_uniforms(uint32_t frameIndex, Scene* const scene);
5458

5559
void update();
5660

61+
void render(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
62+
5763
void cleanup();
64+
5865
};
5966

6067
} // namespace Core

include/engine/core/resource_manager.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
#include <engine/common.h>
1414
#include <engine/core/materials/material.h>
15-
#include <engine/core/passes/irradiance_compute_pass.h>
16-
#include <engine/core/passes/panorama_conversion_pass.h>
1715
#include <engine/core/textures/texture.h>
1816
#include <engine/core/textures/textureLDR.h>
1917
#include <engine/core/windows/window.h>
@@ -35,11 +33,6 @@ Static utility class that handles resource creation, uploading to the GPU and cl
3533
class ResourceManager
3634
{
3735
public:
38-
/*
39-
Auxiliar passes
40-
*/
41-
static Core::PanoramaConverterPass* panoramaConverterPass;
42-
static Core::IrrandianceComputePass* irradianceComputePass;
4336
/*
4437
Texture Resources
4538
*/
@@ -50,6 +43,7 @@ class ResourceManager
5043
Vignette for RTT
5144
*/
5245
static Core::Mesh* VIGNETTE;
46+
5347
/*
5448
Creates and initiates basic rendering resources such as fallback textures and a vignette
5549
*/
@@ -83,10 +77,9 @@ class ResourceManager
8377
upload_geometry_data(Graphics::Device* const device, Core::Geometry* const g, bool createAccelStructure = true);
8478
static void destroy_geometry_data(Core::Geometry* const g);
8579
/*
86-
Setup skybox
80+
Uploads scene's skybox resources (cube mesh and panorama texture)
8781
*/
88-
static void setup_skybox(Graphics::Device* const device, Core::Scene* const scene);
89-
static void generate_skybox_maps(Graphics::Frame* const currentFrame, Core::Scene* const scene);
82+
static void upload_skybox_data(Graphics::Device* const device, Core::Skybox* const sky);
9083
/*
9184
Scene cleanup
9285
*/

include/engine/graphics/descriptors.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,32 @@ struct DescriptorPool {
5959
/*
6060
Set writes for Uniform Buffers
6161
*/
62-
void set_descriptor_write(Buffer* buffer,
62+
void update_descriptor(Buffer* buffer,
6363
size_t dataSize,
6464
size_t readOffset,
6565
DescriptorSet* descriptor,
6666
UniformDataType type,
6767
uint32_t binding);
68-
6968
/*
7069
Set writes for Images
7170
*/
72-
void set_descriptor_write(Image* image,
71+
void update_descriptor(Image* image,
7372
ImageLayout layout,
7473
DescriptorSet* descriptor,
7574
uint32_t binding,
7675
UniformDataType type = UNIFORM_COMBINED_IMAGE_SAMPLER);
7776
/*
7877
Set writes for Image Array
7978
*/
80-
void set_descriptor_write(std::vector<Image>& images,
79+
void update_descriptor(std::vector<Image>& images,
8180
ImageLayout layout,
8281
DescriptorSet* descriptor,
8382
uint32_t binding,
8483
UniformDataType type = UNIFORM_COMBINED_IMAGE_SAMPLER);
8584
/*
8685
Set writes for Acceleration Structures
8786
*/
88-
void set_descriptor_write(TLAS* accel, DescriptorSet* descriptor, uint32_t binding);
87+
void update_descriptor(TLAS* accel, DescriptorSet* descriptor, uint32_t binding);
8988

9089
void cleanup();
9190
};

include/engine/systems/renderers/deferred.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#ifndef DEFERRED_H
22
#define DEFERRED_H
33

4+
#include <engine/systems/renderers/renderer.h>
5+
46
#include <engine/core/passes/bloom_pass.h>
57
#include <engine/core/passes/composition_pass.h>
8+
#include <engine/core/passes/enviroment_pass.h>
69
#include <engine/core/passes/geometry_pass.h>
710
#include <engine/core/passes/postprocess_pass.h>
811
#include <engine/core/passes/precomposition_pass.h>
912
#include <engine/core/passes/variance_shadow_pass.h>
1013
#include <engine/core/passes/voxelization_pass.h>
1114

12-
#include <engine/systems/renderers/renderer.h>
13-
1415
VULKAN_ENGINE_NAMESPACE_BEGIN
1516

1617
namespace Systems {
@@ -22,14 +23,15 @@ class DeferredRenderer : public BaseRenderer
2223
{
2324
enum RendererPasses
2425
{
25-
SHADOW_PASS = 0,
26-
VOXELIZATION_PASS = 1,
27-
GEOMETRY_PASS = 2,
28-
PRECOMPOSITION_PASS = 3,
29-
COMPOSITION_PASS = 4,
30-
BLOOM_PASS = 5,
31-
TONEMAPPIN_PASS = 6,
32-
FXAA_PASS = 7,
26+
ENVIROMENT_PASS = 0,
27+
SHADOW_PASS = 1,
28+
VOXELIZATION_PASS = 2,
29+
GEOMETRY_PASS = 3,
30+
PRECOMPOSITION_PASS = 4,
31+
COMPOSITION_PASS = 5,
32+
BLOOM_PASS = 6,
33+
TONEMAPPIN_PASS = 7,
34+
FXAA_PASS = 8,
3335
};
3436

3537
// Graphic Settings
@@ -89,21 +91,21 @@ class DeferredRenderer : public BaseRenderer
8991
return m_AO;
9092
};
9193
inline void set_shading_output(Core::OutputBuffer output) {
92-
static_cast<Core::CompositionPass*>(m_passes[COMPOSITION_PASS])->set_output_buffer(output);
94+
get_pass<Core::CompositionPass*>(COMPOSITION_PASS)->set_output_buffer(output);
9395
}
9496
inline Core::OutputBuffer get_shading_output() const {
97+
// get_pass<Core::CompositionPass*>(COMPOSITION_PASS)->get_output_buffer();
9598
return static_cast<Core::CompositionPass*>(m_passes[COMPOSITION_PASS])->get_output_buffer();
9699
}
97-
inline void set_clearcolor(Vec4 c) {
98-
BaseRenderer::set_clearcolor(c);
99-
}
100100

101101
protected:
102102
virtual void on_before_render(Core::Scene* const scene);
103103

104104
virtual void on_after_render(RenderResult& renderResult, Core::Scene* const scene);
105105

106106
virtual void create_passes();
107+
108+
virtual void update_enviroment(Core::Skybox* const skybox);
107109
};
108110
} // namespace Systems
109111
VULKAN_ENGINE_NAMESPACE_END

include/engine/systems/renderers/forward.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define FORWARD_H
33

44
#include <engine/core/passes/bloom_pass.h>
5+
#include <engine/core/passes/enviroment_pass.h>
56
#include <engine/core/passes/forward_pass.h>
67
#include <engine/core/passes/postprocess_pass.h>
78
#include <engine/core/passes/variance_shadow_pass.h>
@@ -20,11 +21,12 @@ class ForwardRenderer : public BaseRenderer
2021

2122
enum RendererPasses
2223
{
23-
SHADOW_PASS = 0,
24-
FORWARD_PASS = 1,
25-
BLOOM_PASS = 2,
26-
TONEMAPPIN_PASS = 3,
27-
FXAA_PASS = 4,
24+
ENVIROMENT_PASS = 0,
25+
SHADOW_PASS = 1,
26+
FORWARD_PASS = 2,
27+
BLOOM_PASS = 3,
28+
TONEMAPPIN_PASS = 4,
29+
FXAA_PASS = 5,
2830
};
2931

3032
ShadowResolution m_shadowQuality = ShadowResolution::MEDIUM;
@@ -69,6 +71,8 @@ class ForwardRenderer : public BaseRenderer
6971
virtual void on_after_render(RenderResult& renderResult, Core::Scene* const scene);
7072

7173
virtual void create_passes();
74+
75+
virtual void update_enviroment(Core::Skybox* const skybox);
7276
};
7377
} // namespace Systems
7478
VULKAN_ENGINE_NAMESPACE_END

include/engine/systems/renderers/renderer.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define RENDERER_H
1414

1515
#include <engine/common.h>
16+
#include <engine/core/passes/pass.h>
1617
#include <engine/core/resource_manager.h>
1718

1819
VULKAN_ENGINE_NAMESPACE_BEGIN
@@ -55,7 +56,6 @@ class BaseRenderer
5556
/*Passes*/
5657
std::vector<Core::BasePass*> m_passes;
5758

58-
5959
/*Automatic deletion queue*/
6060
Graphics::Utils::DeletionQueue m_deletionQueue;
6161

@@ -116,6 +116,9 @@ class BaseRenderer
116116
virtual inline void set_clearcolor(Vec4 c) {
117117
m_settings.clearColor = c;
118118
}
119+
template <typename T> inline T get_pass(uint32_t id) {
120+
return id < m_passes.size() ? static_cast<T>(m_passes[id]) : nullptr;
121+
}
119122

120123
#pragma endregion
121124
#pragma region Public Functions

0 commit comments

Comments
 (0)