Skip to content

Commit 663071b

Browse files
committed
-Dev: working on VXGI
1 parent e7d4de4 commit 663071b

File tree

12 files changed

+636
-80
lines changed

12 files changed

+636
-80
lines changed

examples/sponza/application.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ void Application::setup() {
5858
m_scene->set_ambient_intensity(0.1f);
5959
m_scene->use_IBL(false);
6060

61-
62-
6361
m_camera = m_scene->get_active_camera();
6462
m_controller = new Tools::Controller(m_camera, m_window, ControllerMovementType::WASD);
6563
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
This file is part of Vulkan-Engine, a simple to use Vulkan based 3D library
3+
4+
MIT License
5+
6+
Copyright (c) 2023 Antonio Espinosa Garcia
7+
8+
*/
9+
#ifndef VOXELIZATION_PASS_H
10+
#define VOXELIZATION_PASS_H
11+
#include <engine/core/passes/pass.h>
12+
#include <engine/core/resource_manager.h>
13+
14+
VULKAN_ENGINE_NAMESPACE_BEGIN
15+
16+
namespace Core {
17+
18+
class VoxelizationPass : public GraphicPass
19+
{
20+
Graphics::Image m_voxelization = {};
21+
22+
/*Descriptors*/
23+
struct FrameDescriptors {
24+
Graphics::DescriptorSet globalDescritor;
25+
Graphics::DescriptorSet objectDescritor;
26+
};
27+
std::vector<FrameDescriptors> m_descriptors;
28+
29+
void create_voxelization_image();
30+
void setup_material_descriptor(IMaterial* mat);
31+
32+
public:
33+
VoxelizationPass(Graphics::Device* ctx, uint32_t resolution)
34+
: BasePass(ctx, {resolution, resolution}, 1, 1, false, "VOXELIZATION") {
35+
}
36+
37+
void setup_attachments(std::vector<Graphics::AttachmentInfo>& attachments,
38+
std::vector<Graphics::SubPassDependency>& dependencies);
39+
40+
void setup_uniforms(std::vector<Graphics::Frame>& frames);
41+
42+
void setup_shader_passes();
43+
44+
void render(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
45+
46+
void update_uniforms(uint32_t frameIndex, Scene* const scene);
47+
48+
void cleanup();
49+
};
50+
51+
} // namespace Core
52+
VULKAN_ENGINE_NAMESPACE_END
53+
54+
#endif

include/engine/core/scene/mesh.h

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,58 @@ class Mesh;
2424
/*
2525
Bounding volume base struct
2626
*/
27-
struct Volume {
28-
Mesh* mesh;
29-
Vec3 center{0.0f, 0.0f, 0.0f};
27+
struct BoundingVolume {
28+
const VolumeType TYPE;
29+
Object3D* obj = nullptr;
30+
Vec3 center = {0.0f, 0.0f, 0.0f};
31+
Vec3 maxCoords = {0.0f, 0.0f, 0.0f};
32+
Vec3 minCoords = {INFINITY, INFINITY, INFINITY};
33+
34+
BoundingVolume(VolumeType t, Object3D* o)
35+
: TYPE(t)
36+
, obj(o) {
37+
}
3038

3139
virtual void setup(Mesh* const mesh) = 0;
3240

3341
virtual bool is_on_frustrum(const Frustum& frustum) const = 0;
3442
};
35-
struct Sphere : public Volume {
43+
typedef BoundingVolume BVolume;
44+
typedef BoundingVolume BV;
45+
46+
struct BoundingSphere : public BVolume {
3647
float radius{0.0f};
3748

38-
Sphere() = default;
49+
BoundingSphere(Object3D* o)
50+
: BVolume(VolumeType::SPHERE_VOLUME, o) {
51+
}
3952

40-
Sphere(const Vec3 c, const float r)
41-
: radius(r) {
53+
BoundingSphere(const Vec3 c, const float r, Object3D* o)
54+
: radius(r)
55+
, BVolume(VolumeType::SPHERE_VOLUME, o) {
4256
center = c;
4357
}
4458

4559
virtual void setup(Mesh* const mesh);
4660

4761
virtual bool is_on_frustrum(const Frustum& frustum) const;
4862
};
49-
struct AABB : public Volume {
50-
// TO DO
63+
struct AABB : public BVolume {
64+
65+
AABB(Object3D* o)
66+
: BVolume(VolumeType::AABB_VOLUME, o) {
67+
}
68+
69+
AABB(const Vec3 min, const Vec3 max, Object3D* o)
70+
: BoundingVolume(VolumeType::AABB_VOLUME, o) {
71+
minCoords = min;
72+
maxCoords = max;
73+
center = (maxCoords + minCoords) * 0.5f;
74+
}
75+
76+
virtual void setup(Mesh* const mesh);
77+
78+
virtual bool is_on_frustrum(const Frustum& frustum) const;
5179
};
5280

5381
/*
@@ -59,8 +87,7 @@ class Mesh : public Object3D
5987
std::vector<Geometry*> m_geometry;
6088
std::vector<IMaterial*> m_material;
6189

62-
VolumeType m_volumeType = SPHERE_VOLUME;
63-
Volume* m_volume = nullptr;
90+
BV* m_volume = nullptr;
6491
bool m_affectedByFog = true;
6592
bool m_castShadows = true;
6693
bool m_receiveShadows = true;
@@ -77,12 +104,12 @@ class Mesh : public Object3D
77104
public:
78105
Mesh()
79106
: Object3D("Mesh #" + std::to_string(Mesh::m_instanceCount), ObjectType::MESH)
80-
, m_volume(new Sphere()) {
107+
, m_volume(nullptr) {
81108
Mesh::m_instanceCount++;
82109
}
83110
Mesh(Geometry* geom, IMaterial* mat)
84111
: Object3D("Mesh #" + std::to_string(Mesh::m_instanceCount), ObjectType::MESH)
85-
, m_volume(new Sphere()) {
112+
, m_volume(nullptr) {
86113
Mesh::m_instanceCount++;
87114
m_geometry.push_back(geom);
88115
m_material.push_back(mat);
@@ -173,17 +200,8 @@ class Mesh : public Object3D
173200
inline bool ray_hittable() const {
174201
return m_rayHittable;
175202
}
176-
inline VolumeType get_volume_type() const {
177-
return m_volumeType;
178-
}
179-
void set_volume_type(VolumeType t);
180-
181-
inline void setup_volume() {
182-
if (m_volume)
183-
m_volume->setup(this);
184-
}
185203

186-
inline const Volume* const get_bounding_volume() const {
204+
inline const BV* const get_bounding_volume() const {
187205
return m_volume;
188206
}
189207

@@ -202,6 +220,7 @@ class Mesh : public Object3D
202220
m_geometry[geometrySlot]->set_material_ID(materialSlot);
203221
}
204222

223+
void setup_volume(VolumeType type = VolumeType::SPHERE_VOLUME);
205224
Mesh* clone() const;
206225
};
207226
} // namespace Core

include/engine/core/scene/scene.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class Scene : public Object3D
3939
Vec3 m_fogColor = {0.2f, 0.2f, 0.2f};
4040
float m_fogIntensity = 20.0f;
4141
float m_fogExponent = 1.0f;
42+
// BVOL
43+
AABB m_volume = (this);
4244

4345
inline void classify_object(Object3D* obj) {
4446
switch (obj->get_type())
@@ -69,7 +71,6 @@ class Scene : public Object3D
6971
Scene()
7072
: m_activeCamera(nullptr) {};
7173
~Scene() {
72-
7374
delete m_activeCamera;
7475
delete m_skybox;
7576

@@ -176,7 +177,9 @@ class Scene : public Object3D
176177
inline void update_AS(bool op) {
177178
m_updateAccel = op;
178179
}
180+
void compute_limits();
179181
};
182+
180183
void set_meshes(Scene* const scene, std::vector<Mesh*> meshes);
181184

182185
Graphics::TLAS* get_TLAS(Scene* const scene);

include/engine/systems/renderers/deferred.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <engine/core/passes/geometry_pass.h>
77
#include <engine/core/passes/postprocess_pass.h>
88
#include <engine/core/passes/precomposition_pass.h>
9+
#include <engine/core/passes/voxelization_pass.h>
910
#include <engine/core/passes/variance_shadow_pass.h>
1011

1112
#include <engine/systems/renderers/renderer.h>
@@ -21,13 +22,14 @@ class DeferredRenderer : public BaseRenderer
2122
{
2223
enum RendererPasses
2324
{
24-
SHADOW_PASS = 0,
25-
GEOMETRY_PASS = 1,
26-
PRECOMPOSITION_PASS = 2,
27-
COMPOSITION_PASS = 3,
28-
BLOOM_PASS = 4,
29-
TONEMAPPIN_PASS = 5,
30-
FXAA_PASS = 6,
25+
VOXELIZATION_PASS = 0,
26+
SHADOW_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,
3133
};
3234

3335
ShadowResolution m_shadowQuality = ShadowResolution::MEDIUM;

include/engine/systems/renderers/renderer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ class BaseRenderer
4848
protected:
4949
Graphics::Device* m_device;
5050
std::vector<Graphics::Frame> m_frames;
51-
52-
Core::IWindow* m_window;
53-
51+
Core::IWindow* m_window;
5452
RendererSettings m_settings{};
53+
54+
/*Passes*/
5555
std::vector<Core::BasePass*> m_passes;
5656

5757
Graphics::Utils::DeletionQueue m_deletionQueue;

0 commit comments

Comments
 (0)