Skip to content

Commit 537291a

Browse files
committed
-Dev: added line geometry support for deferred and fix of minor bugs
1 parent 6790a68 commit 537291a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2006
-2111
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ BinPackArguments: false
88
BinPackParameters: false
99

1010
# Column limit to trigger line wrapping
11-
ColumnLimit: 120 # Adjust as needed; lower value ensures more wrapping
11+
ColumnLimit: 160 # Adjust as needed; lower value ensures more wrapping
1212

1313
IndentWidth: 4
1414
TabWidth: 4

examples/sponza/application.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void Application::setup() {
5353
const std::string TEXTURE_PATH(EXAMPLES_RESOURCES_PATH "textures/");
5454

5555
m_scene = new Scene();
56-
Tools::Loaders::SceneLoader loader(true);
56+
Tools::SceneLoader loader(true);
5757
loader.load_scene(m_scene, SCENE_PATH + "sponza.xml");
5858

5959
m_scene->set_ambient_intensity(0.1f);

examples/sponza/application.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <engine/tools/controller.h>
1111
#include <engine/tools/gui.h>
1212
#include <engine/tools/loaders.h>
13+
#include <engine/tools/scene_loader.h>
1314

1415
/**
1516
* Example app

include/engine/core/geometries/geometry.h

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,22 @@ namespace Core {
2020

2121
class Geometry;
2222

23+
enum class Topology
24+
{
25+
TRIANGLES = 0,
26+
LINES = 1,
27+
LINES_TO_TRIANGLES = 2,
28+
OTHER = 3
29+
};
30+
2331
struct GeometricData {
2432
std::vector<uint32_t> vertexIndex;
2533
std::vector<Graphics::Vertex> vertexData;
2634
std::vector<Graphics::Voxel> voxelData;
2735

36+
// Topology
37+
Topology topology{Topology::TRIANGLES};
38+
2839
// Stats
2940
Vec3 maxCoords;
3041
Vec3 minCoords;
@@ -55,6 +66,9 @@ class Geometry
5566
Geometry() {
5667
}
5768

69+
~Geometry() {
70+
}
71+
5872
inline size_t get_material_ID() const {
5973
return m_materialID;
6074
}
@@ -69,8 +83,12 @@ class Geometry
6983
return !m_properties.vertexIndex.empty();
7084
}
7185

72-
inline const GeometricData* get_properties() const {
73-
return &m_properties;
86+
inline const GeometricData& get_properties() const {
87+
return m_properties;
88+
}
89+
/* Use it carefully, might break the mesh visualization */
90+
inline void set_topology(Topology topology) {
91+
m_properties.topology = topology;
7492
}
7593
/*
7694
Use Voxel Acceleration Structure
@@ -93,19 +111,21 @@ class Geometry
93111
inline void dynamic_AS(bool op) {
94112
m_BLAS.dynamic = op;
95113
}
96-
~Geometry() {
97-
}
98114

99-
void fill(std::vector<Graphics::Vertex> vertexInfo);
100-
void fill(std::vector<Graphics::Vertex> vertexInfo, std::vector<uint32_t> vertexIndex);
101-
void fill(Vec3* pos, Vec3* normal, Vec2* uv, Vec3* tangent, uint32_t vertNumber);
102-
void fill_voxel_array(std::vector<Graphics::Voxel> voxels);
115+
void fill(std::vector<Graphics::Vertex> vertexInfo, Topology topology = Topology::TRIANGLES);
116+
void fill(std::vector<Graphics::Vertex> vertexInfo, std::vector<uint32_t> vertexIndex, Topology topology = Topology::TRIANGLES);
117+
void fill(Vec3* pos, Vec3* normal, Vec2* uv, Vec3* tangent, uint32_t vertNumber, Topology topology = Topology::TRIANGLES);
118+
119+
void fill_voxel_array(std::vector<Graphics::Voxel> voxels);
120+
121+
/* Primitive creator helpers */
103122
static Geometry* create_quad();
104-
static Geometry* create_simple_cube(); //Not for shading geometry
105-
static Geometry* create_cube();
123+
static Geometry* create_simple_cube(); // Not for shading geometry
124+
static Geometry* create_cube();
106125
static Geometry* create_cylinder(int segments = 1, float radius = 0.5, float height = 2.0);
107-
static void compute_tangents_gram_smidt(std::vector<Graphics::Vertex>& vertices,
108-
const std::vector<uint32_t>& indices);
126+
127+
/* Other useful data */
128+
static void compute_tangents_gram_smidt(std::vector<Graphics::Vertex>& vertices, const std::vector<uint32_t>& indices);
109129
};
110130

111131
Graphics::VertexArrays* const get_VAO(Geometry* g);

include/engine/core/materials/material.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class IMaterial
3939
friend class Renderer;
4040

4141
public:
42-
static IMaterial* DEBUG_MATERIAL;
42+
static IMaterial* debugMaterial;
4343

4444
IMaterial(std::string shaderPassID)
4545
: m_shaderPassID(shaderPassID) {

include/engine/core/passes/TAA_pass.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Core {
1717
/*
1818
Tempopral Filtering Pass.
1919
*/
20-
class TAAPass final : public PostProcessPass<2, 0>
20+
class TAAPass final : public PostProcessPass<2, 1>
2121
{
2222
public:
2323
/*
@@ -34,7 +34,7 @@ class TAAPass final : public PostProcessPass<2, 0>
3434
3535
*/
3636
TAAPass(Graphics::Device* device,
37-
const PassLinkage<2, 0>& linkage,
37+
const PassLinkage<2, 1>& linkage,
3838
Extent2D extent,
3939
ColorFormatType colorFormat,
4040
bool isDefault = true)

include/engine/core/passes/postprocess_pass.h

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ template <std::size_t numberIN, std::size_t numberOUT> class PostProcessPass : p
3838
BasePass::store_attachments<numberIN, numberOUT>(config);
3939
}
4040

41-
virtual void setup_out_attachments(std::vector<Graphics::AttachmentConfig>& attachments,
42-
std::vector<Graphics::SubPassDependency>& dependencies);
41+
virtual void setup_out_attachments(std::vector<Graphics::AttachmentConfig>& attachments, std::vector<Graphics::SubPassDependency>& dependencies);
4342

4443
virtual void setup_uniforms(std::vector<Graphics::Frame>& frames);
4544

@@ -53,9 +52,8 @@ template <std::size_t numberIN, std::size_t numberOUT> class PostProcessPass : p
5352
#pragma region Implementation
5453

5554
template <std::size_t numberIN, std::size_t numberOUT>
56-
void PostProcessPass<numberIN, numberOUT>::setup_out_attachments(
57-
std::vector<Graphics::AttachmentConfig>& attachments,
58-
std::vector<Graphics::SubPassDependency>& dependencies) {
55+
void PostProcessPass<numberIN, numberOUT>::setup_out_attachments(std::vector<Graphics::AttachmentConfig>& attachments,
56+
std::vector<Graphics::SubPassDependency>& dependencies) {
5957

6058
attachments.resize(1);
6159

@@ -64,27 +62,27 @@ void PostProcessPass<numberIN, numberOUT>::setup_out_attachments(
6462
1,
6563
this->m_isDefault ? LAYOUT_PRESENT : LAYOUT_SHADER_READ_ONLY_OPTIMAL,
6664
LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
67-
this->m_isDefault ? IMAGE_USAGE_TRANSIENT_ATTACHMENT | IMAGE_USAGE_COLOR_ATTACHMENT
68-
: IMAGE_USAGE_COLOR_ATTACHMENT | IMAGE_USAGE_SAMPLED,
65+
this->m_isDefault ? IMAGE_USAGE_TRANSIENT_ATTACHMENT | IMAGE_USAGE_COLOR_ATTACHMENT
66+
: IMAGE_USAGE_COLOR_ATTACHMENT | IMAGE_USAGE_SAMPLED | IMAGE_USAGE_TRANSFER_SRC | IMAGE_USAGE_TRANSFER_DST,
6967
COLOR_ATTACHMENT,
7068
ASPECT_COLOR,
7169
TEXTURE_2D,
7270
FILTER_LINEAR,
7371
ADDRESS_MODE_CLAMP_TO_EDGE);
7472

75-
attachments[0].isDefault = this->m_isDefault ? true : false;
73+
attachments[0].isDefault = this->m_isDefault ? true : false;
74+
// attachments[0].imageConfig.mipLevels = static_cast<uint32_t>(std::floor(std::log2(std::max(this->m_imageExtent.width, this->m_imageExtent.height)))) + 1;
75+
// attachments[0].imageConfig.useMipmaps = true;
7676

7777
// Depdencies
7878
if (!this->m_isDefault)
7979
{
8080
dependencies.resize(2);
8181

82-
dependencies[0] = Graphics::SubPassDependency(
83-
STAGE_FRAGMENT_SHADER, STAGE_COLOR_ATTACHMENT_OUTPUT, ACCESS_COLOR_ATTACHMENT_WRITE);
82+
dependencies[0] = Graphics::SubPassDependency(STAGE_FRAGMENT_SHADER, STAGE_COLOR_ATTACHMENT_OUTPUT, ACCESS_COLOR_ATTACHMENT_WRITE);
8483
dependencies[0].srcAccessMask = ACCESS_SHADER_READ;
8584
dependencies[0].dependencyFlags = SUBPASS_DEPENDENCY_NONE;
86-
dependencies[1] =
87-
Graphics::SubPassDependency(STAGE_COLOR_ATTACHMENT_OUTPUT, STAGE_FRAGMENT_SHADER, ACCESS_SHADER_READ);
85+
dependencies[1] = Graphics::SubPassDependency(STAGE_COLOR_ATTACHMENT_OUTPUT, STAGE_FRAGMENT_SHADER, ACCESS_SHADER_READ);
8886
dependencies[1].srcAccessMask = ACCESS_COLOR_ATTACHMENT_WRITE;
8987
dependencies[1].srcSubpass = 0;
9088
dependencies[1].dstSubpass = VK_SUBPASS_EXTERNAL;
@@ -94,13 +92,11 @@ void PostProcessPass<numberIN, numberOUT>::setup_out_attachments(
9492
dependencies.resize(1);
9593

9694
// dependencies[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT;
97-
dependencies[0] = Graphics::SubPassDependency(
98-
STAGE_COLOR_ATTACHMENT_OUTPUT, STAGE_COLOR_ATTACHMENT_OUTPUT, ACCESS_COLOR_ATTACHMENT_WRITE);
95+
dependencies[0] = Graphics::SubPassDependency(STAGE_COLOR_ATTACHMENT_OUTPUT, STAGE_COLOR_ATTACHMENT_OUTPUT, ACCESS_COLOR_ATTACHMENT_WRITE);
9996
dependencies[0].dependencyFlags = SUBPASS_DEPENDENCY_NONE;
10097
}
10198
}
102-
template <std::size_t numberIN, std::size_t numberOUT>
103-
void PostProcessPass<numberIN, numberOUT>::setup_uniforms(std::vector<Graphics::Frame>& frames) {
99+
template <std::size_t numberIN, std::size_t numberOUT> void PostProcessPass<numberIN, numberOUT>::setup_uniforms(std::vector<Graphics::Frame>& frames) {
104100
// Init and configure local descriptors
105101
this->m_descriptorPool = this->m_device->create_descriptor_pool(1, numberIN, 1, 1, 1);
106102

@@ -114,27 +110,21 @@ void PostProcessPass<numberIN, numberOUT>::setup_uniforms(std::vector<Graphics::
114110

115111
this->m_descriptorPool.allocate_descriptor_set(GLOBAL_LAYOUT, &this->m_imageDescriptorSet);
116112
}
117-
template <std::size_t numberIN, std::size_t numberOUT>
118-
void PostProcessPass<numberIN, numberOUT>::setup_shader_passes() {
113+
template <std::size_t numberIN, std::size_t numberOUT> void PostProcessPass<numberIN, numberOUT>::setup_shader_passes() {
119114

120-
Graphics::GraphicShaderPass* ppPass = new Graphics::GraphicShaderPass(
121-
this->m_device->get_handle(), this->m_renderpass, this->m_imageExtent, this->m_shaderPath);
115+
Graphics::GraphicShaderPass* ppPass =
116+
new Graphics::GraphicShaderPass(this->m_device->get_handle(), this->m_renderpass, this->m_imageExtent, this->m_shaderPath);
122117
ppPass->settings.descriptorSetLayoutIDs = {{GLOBAL_LAYOUT, true}};
123-
ppPass->graphicSettings.attributes = {{POSITION_ATTRIBUTE, true},
124-
{NORMAL_ATTRIBUTE, false},
125-
{UV_ATTRIBUTE, true},
126-
{TANGENT_ATTRIBUTE, false},
127-
{COLOR_ATTRIBUTE, false}};
118+
ppPass->graphicSettings.attributes = {
119+
{POSITION_ATTRIBUTE, true}, {NORMAL_ATTRIBUTE, false}, {UV_ATTRIBUTE, true}, {TANGENT_ATTRIBUTE, false}, {COLOR_ATTRIBUTE, false}};
128120

129121
ppPass->build_shader_stages();
130122
ppPass->build(this->m_descriptorPool);
131123

132124
this->m_shaderPasses["pp"] = ppPass;
133125
}
134126
template <std::size_t numberIN, std::size_t numberOUT>
135-
void PostProcessPass<numberIN, numberOUT>::execute(Graphics::Frame& currentFrame,
136-
Scene* const scene,
137-
uint32_t presentImageIndex) {
127+
void PostProcessPass<numberIN, numberOUT>::execute(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex) {
138128
PROFILING_EVENT()
139129

140130
Graphics::CommandBuffer cmd = currentFrame.commandBuffer;
@@ -154,8 +144,7 @@ void PostProcessPass<numberIN, numberOUT>::execute(Graphics::Frame& currentFrame
154144

155145
cmd.end_renderpass(this->m_renderpass, this->m_framebuffers[this->m_isDefault ? presentImageIndex : 0]);
156146
}
157-
template <std::size_t numberIN, std::size_t numberOUT>
158-
void PostProcessPass<numberIN, numberOUT>::link_input_attachments() {
147+
template <std::size_t numberIN, std::size_t numberOUT> void PostProcessPass<numberIN, numberOUT>::link_input_attachments() {
159148
for (size_t i = 0; i < numberIN; i++)
160149
{
161150
this->m_descriptorPool.update_descriptor(this->m_inAttachments[i], LAYOUT_SHADER_READ_ONLY_OPTIMAL, &m_imageDescriptorSet, i);

include/engine/core/passes/tonemapping_pass.h

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ enum TonemappingType
2525
/*
2626
Tonemapping Pass.
2727
*/
28-
class TonemappingPass final : public PostProcessPass<1, 1>
28+
class TonemappingPass final : public PostProcessPass<1, 0>
2929
{
3030
protected:
3131
float m_exposure = 1.0f;
3232
TonemappingType m_tonemap = FILMIC_TONEMAP;
3333

34+
void setup_input_image_mipmaps();
35+
3436
public:
3537
/*
3638
@@ -43,18 +45,9 @@ class TonemappingPass final : public PostProcessPass<1, 1>
4345
- Tonemapped Color
4446
4547
*/
46-
TonemappingPass(Graphics::Device* device,
47-
const PassLinkage<1, 1>& config,
48-
Extent2D extent,
49-
ColorFormatType colorFormat,
50-
bool isDefault = true)
51-
: PostProcessPass(device,
52-
config,
53-
extent,
54-
colorFormat,
55-
ENGINE_RESOURCES_PATH "shaders/misc/tonemapping.glsl",
56-
"TONEMAPPING",
57-
isDefault) {
48+
TonemappingPass(Graphics::Device* device, const PassLinkage<1, 0>& config, Extent2D extent, ColorFormatType colorFormat, bool isDefault = true)
49+
: PostProcessPass(device, config, extent, colorFormat, ENGINE_RESOURCES_PATH "shaders/misc/tonemapping.glsl", "TONEMAPPING", isDefault) {
50+
m_interAttachments.resize(1);
5851
}
5952

6053
inline float get_exposure() const {

include/engine/graphics/device.h

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,7 @@ class Device
9595
uint32_t framesPerFlight,
9696
ColorFormatType presentFormat,
9797
SyncType presentMode);
98-
void update_swapchain(Extent2D surfaceExtent,
99-
uint32_t framesPerFlight,
100-
ColorFormatType presentFormat,
101-
SyncType presentMode);
98+
void update_swapchain(Extent2D surfaceExtent, uint32_t framesPerFlight, ColorFormatType presentFormat, SyncType presentMode);
10299
void cleanup();
103100

104101
/*
@@ -107,33 +104,21 @@ class Device
107104
*/
108105

109106
/*Create Buffer using Vulkan Memory Allocator (VMA)*/
110-
Buffer
111-
create_buffer_VMA(size_t allocSize, BufferUsageFlags usage, VmaMemoryUsage memoryUsage, uint32_t strideSize = 0);
107+
Buffer create_buffer_VMA(size_t allocSize, BufferUsageFlags usage, VmaMemoryUsage memoryUsage, uint32_t strideSize = 0);
112108
/*Create Buffer*/
113-
Buffer create_buffer(size_t allocSize,
114-
BufferUsageFlags usage,
115-
MemoryPropertyFlags memoryProperties,
116-
uint32_t strideSize = 0);
109+
Buffer create_buffer(size_t allocSize, BufferUsageFlags usage, MemoryPropertyFlags memoryProperties, uint32_t strideSize = 0);
117110
/*Create Image*/
118-
Image create_image(Extent3D extent,
119-
ImageConfig config,
120-
bool useMipmaps,
121-
VmaMemoryUsage memoryUsage = VMA_MEMORY_USAGE_GPU_ONLY);
111+
Image create_image(Extent3D extent, ImageConfig config, VmaMemoryUsage memoryUsage = VMA_MEMORY_USAGE_GPU_ONLY);
122112
/*Create Framebuffer Object*/
123-
Framebuffer create_framebuffer(RenderPass& renderpass,
124-
std::vector<Image*>& attachments,
125-
Extent2D extent,
126-
uint32_t layers = 1,
127-
uint32_t id = 0);
113+
Framebuffer create_framebuffer(RenderPass& renderpass, std::vector<Image*>& attachments, Extent2D extent, uint32_t layers = 1, uint32_t id = 0);
128114
Framebuffer create_framebuffer(RenderPass& renderpass, Image& attachment);
129115
Semaphore create_semaphore();
130116
Fence create_fence(bool signaled = true);
131117
/*Create Frame. A frame is a data structure that contains the objects needed for synchronize each frame rendered and
132118
* buffers to contain data needed for the GPU to render*/
133119
Frame create_frame(uint16_t id);
134120
/*Create RenderPass*/
135-
RenderPass create_render_pass(std::vector<AttachmentConfig>& attachments,
136-
std::vector<SubPassDependency>& dependencies);
121+
RenderPass create_render_pass(std::vector<AttachmentConfig>& attachments, std::vector<SubPassDependency>& dependencies);
137122
/*Create Descriptor Pool*/
138123
DescriptorPool create_descriptor_pool(uint32_t maxSets,
139124
uint32_t numUBO,
@@ -149,11 +134,9 @@ class Device
149134
uint32_t numIAttachment = 0,
150135
VkDescriptorPoolCreateFlagBits flag = {});
151136
/*Create Command Pool*/
152-
CommandPool create_command_pool(QueueType QueueType,
153-
CommandPoolCreateFlags flags = COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER);
137+
CommandPool create_command_pool(QueueType QueueType, CommandPoolCreateFlags flags = COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER);
154138
/*Create command buffer*/
155-
CommandBuffer create_command_buffer(CommandPool commandPool,
156-
CommandBufferLevel level = COMMAND_BUFFER_LEVEL_PRIMARY);
139+
CommandBuffer create_command_buffer(CommandPool commandPool, CommandBufferLevel level = COMMAND_BUFFER_LEVEL_PRIMARY);
157140
/*Create shader pass*/
158141
// ShaderPass build_shader_pass(const std::string shaderFile, PipelineSettings sett = {});
159142

@@ -181,12 +164,7 @@ class Device
181164
const void* iboData,
182165
size_t voxelSize = 0,
183166
const void* voxelData = nullptr);
184-
void upload_texture_image(Image& img,
185-
ImageConfig config,
186-
SamplerConfig samplerConfig,
187-
const void* imgCache,
188-
size_t bytesPerPixel,
189-
bool mipmapping);
167+
void upload_texture_image(Image& img, ImageConfig config, SamplerConfig samplerConfig, const void* imgCache, size_t bytesPerPixel);
190168
void upload_BLAS(BLAS& accel, VAO& vao);
191169
void upload_TLAS(TLAS& accel, std::vector<BLASInstance>& BLASinstances);
192170
/*

include/engine/graphics/image.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct ImageConfig {
2525
uint16_t samples = 1U;
2626
uint32_t mipLevels = 1U;
2727
uint32_t baseMipLevel = 0;
28+
bool useMipmaps = false;
2829
uint32_t layers = 1U;
2930
ImageLayout layout = LAYOUT_UNDEFINED;
3031
ClearValue clearValue = {{{0.0, 0.0, 0.0, 1.0}}};

0 commit comments

Comments
 (0)