Skip to content

Commit

Permalink
New Deferred almost set up
Browse files Browse the repository at this point in the history
  • Loading branch information
AEspinosaDev committed Nov 27, 2024
1 parent 1b63270 commit 6d8599a
Show file tree
Hide file tree
Showing 29 changed files with 644 additions and 706 deletions.
2 changes: 1 addition & 1 deletion examples/lighting-test/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void Application::init(Systems::RendererSettings settings) {
std::placeholders::_3,
std::placeholders::_4));

m_renderer = new Systems::ForwardRenderer(m_window, settings, {ShadowResolution::LOW, true});
m_renderer = new Systems::ForwardRenderer(m_window, true, ShadowResolution::VERY_LOW, settings);

setup();

Expand Down
11 changes: 4 additions & 7 deletions examples/raytracing/application.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "application.h"
#include <filesystem>

void Application::init(Systems::RendererSettings settings, Systems::ForwardRendererSettings settings2) {
void Application::init(Systems::RendererSettings settings) {
m_window = new WindowGLFW("Raytracing Example", 1280, 1024);

m_window->init();
Expand All @@ -17,7 +17,7 @@ void Application::init(Systems::RendererSettings settings, Systems::ForwardRende
std::placeholders::_3,
std::placeholders::_4));

m_renderer = new Systems::ForwardRenderer(m_window, settings, settings2);
m_renderer = new Systems::ForwardRenderer(m_window, true, ShadowResolution::LOW, settings);

setup();
setup_gui();
Expand All @@ -30,11 +30,8 @@ void Application::run(int argc, char* argv[]) {
settings.clearColor = Vec4(0.02, 0.02, 0.02, 1.0);
settings.enableUI = true;
settings.enableRaytracing = true;
Systems::ForwardRendererSettings settings2{};
settings2.shadowQuality = ShadowResolution::MEDIUM;
settings2.fxaa = true;

init(settings, settings2);
init(settings);
while (!m_window->get_window_should_close())
{

Expand Down Expand Up @@ -73,7 +70,7 @@ void Application::setup() {
light->set_shadow_fov(115.0f);
light->set_shadow_type(ShadowType::RAYTRACED_SHADOW);
light->set_area(0.5f);
light->add_child(lightDummy);
// light->add_child(lightDummy);
light->set_name("Light");

m_scene->add(light);
Expand Down
3 changes: 2 additions & 1 deletion examples/raytracing/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <engine/core.h>
#include <engine/systems/renderers/forward.h>
#include <engine/systems/renderers/deferred.h>

#include <engine/tools/controller.h>
#include <engine/tools/gui.h>
Expand Down Expand Up @@ -48,7 +49,7 @@ class Application
Time m_time{};

public:
void init(Systems::RendererSettings settings, Systems::ForwardRendererSettings settings2);
void init(Systems::RendererSettings settings);

void run(int argc, char *argv[]);

Expand Down
11 changes: 4 additions & 7 deletions examples/renderer-app/application.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "application.h"
#include <filesystem>

void Application::init(Systems::RendererSettings settings, Systems::ForwardRendererSettings settings2) {
void Application::init(Systems::RendererSettings settings) {
m_window = new WindowGLFW("VK Engine", 1280, 1024);

m_window->init();
Expand All @@ -17,7 +17,7 @@ void Application::init(Systems::RendererSettings settings, Systems::ForwardRende
std::placeholders::_3,
std::placeholders::_4));

m_renderer = new Systems::ForwardRenderer(m_window, settings, settings2);
m_renderer = new Systems::ForwardRenderer(m_window, false, ShadowResolution::MEDIUM, settings);

setup();

Expand All @@ -31,9 +31,6 @@ void Application::run(int argc, char* argv[]) {
settings.clearColor = Vec4(0.02, 0.02, 0.02, 1.0);
settings.enableUI = true;
settings.enableRaytracing = true;
Systems::ForwardRendererSettings settings2{};
settings2.shadowQuality = ShadowResolution::MEDIUM;
settings2.fxaa = true;

if (argc == 1)
std::cout << "No arguments submitted, initializing with default parameters..." << std::endl;
Expand Down Expand Up @@ -89,7 +86,7 @@ void Application::run(int argc, char* argv[]) {
settings.samplesMSAA = MSAASamples::x8;
if (aaType == "fxaa")
{
settings2.fxaa = true;
// settings2.fxaa = true;
settings.samplesMSAA = MSAASamples::x1;
}

Expand All @@ -115,7 +112,7 @@ void Application::run(int argc, char* argv[]) {
continue;
}

init(settings, settings2);
init(settings);
while (!m_window->get_window_should_close())
{

Expand Down
2 changes: 1 addition & 1 deletion examples/renderer-app/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Application
Time m_time{};

public:
void init(Systems::RendererSettings settings, Systems::ForwardRendererSettings settings2);
void init(Systems::RendererSettings settings);

void run(int argc, char *argv[]);

Expand Down
3 changes: 2 additions & 1 deletion examples/rotating-kabuto/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ int main() {
settings.samplesMSAA = MSAASamples::x4;
settings.clearColor = Vec4(0.0, 0.0, 0.0, 1.0);

Systems::BaseRenderer* renderer = new Systems::ForwardRenderer(window, settings, {});
Systems::BaseRenderer* renderer =
new Systems::ForwardRenderer(window, false, ShadowResolution::VERY_LOW, settings);

Core::Camera* camera = new Core::Camera();
camera->set_position(Vec3(0.0f, 0.15f, -1.0f));
Expand Down
5 changes: 3 additions & 2 deletions include/engine/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@
#define VULKAN_ENGINE_NAMESPACE_END }
#define USING_VULKAN_ENGINE_NAMESPACE using namespace VKFW;

#define VK_MAX_OBJECTS 100
#define VK_MAX_LIGHTS 50
//Max object ocurrence
#define ENGINE_MAX_OBJECTS 100
#define ENGINE_MAX_LIGHTS 50

// File terminations
#define PLY "ply"
Expand Down
120 changes: 62 additions & 58 deletions include/engine/core/renderpasses/composition_pass.h
Original file line number Diff line number Diff line change
@@ -1,58 +1,62 @@
// /*
// This file is part of Vulkan-Engine, a simple to use Vulkan based 3D library

// MIT License

// Copyright (c) 2023 Antonio Espinosa Garcia

// */
// #ifndef COMPOSITION_PASS_H
// #define COMPOSITION_PASS_H
// #include <engine/graphics/renderpass.h>

// VULKAN_ENGINE_NAMESPACE_BEGIN

// class CompositionPass : public RenderPass
// {

// ColorFormatType m_colorFormat;

// Mesh *m_vignette;

// bool m_fxaa;

// DescriptorSet m_GBufferDescriptor{};

// std::vector<Image> m_Gbuffer;
// Buffer m_uniformBuffer;

// unsigned int m_outputType{0};

// public:
// CompositionPass(Context* ctx,VkExtent2D extent,
// uint32_t framebufferCount,
// ColorFormatType colorFormat, Mesh *vignette, bool fxaa) : RenderPass(ctx, extent, framebufferCount, 1, fxaa ? false : true),
// m_colorFormat(colorFormat), m_vignette(vignette), m_fxaa(fxaa) {}

// void init();

// void create_pipelines( DescriptorManager &descriptorManager);

// void init_resources();

// void render(uint32_t frameIndex, Scene *const scene, uint32_t presentImageIndex = 0);

// inline void set_output_type(int op) { m_outputType = op; }
// inline int get_output_type() const { return m_outputType; }

// void set_g_buffer(Image position, Image normals, Image albedo, Image material, DescriptorManager &descriptorManager);

// void update_uniforms();

// void cleanup();

// void update();
// };
// VULKAN_ENGINE_NAMESPACE_END

// #endif
/*
This file is part of Vulkan-Engine, a simple to use Vulkan based 3D library
MIT License
Copyright (c) 2023 Antonio Espinosa Garcia
*/
#ifndef COMPOSITION_PASS_H
#define COMPOSITION_PASS_H
#include <engine/core/renderpasses/renderpass.h>
#include <engine/core/resource_manager.h>

VULKAN_ENGINE_NAMESPACE_BEGIN
namespace Core {

/*
DEFERRED RENDERING LIGHTING PASS
*/
class CompositionPass : public RenderPass
{
/*Setup*/
ColorFormatType m_colorFormat;
Mesh* m_vignette;

/*Descriptors*/
struct FrameDescriptors {
Graphics::DescriptorSet globalDescritor;
Graphics::DescriptorSet gBufferDescritor;
};
std::vector<FrameDescriptors> m_descriptors;

public:
CompositionPass(Graphics::Device* ctx,
VkExtent2D extent,
uint32_t framebufferCount,
ColorFormatType colorFormat,
Mesh* vignette,
bool isDefault = true)
: RenderPass(ctx, extent, framebufferCount, 1, isDefault)
, m_colorFormat(colorFormat)
, m_vignette(vignette) {
}

void setup_attachments(std::vector<Graphics::Attachment>& attachments,
std::vector<Graphics::SubPassDependency>& dependencies);

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

void setup_shader_passes();

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

void connect_to_previous_images(std::vector<Graphics::Image> images);

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

};
} // namespace Core
VULKAN_ENGINE_NAMESPACE_END

#endif
3 changes: 3 additions & 0 deletions include/engine/core/renderpasses/forward_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ VULKAN_ENGINE_NAMESPACE_BEGIN

namespace Core {

/*
STANDARD FORWARD LIGHTING PASS
*/
class ForwardPass : public RenderPass
{
/*Setup*/
Expand Down
5 changes: 4 additions & 1 deletion include/engine/core/renderpasses/geometry_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ VULKAN_ENGINE_NAMESPACE_BEGIN

namespace Core {

/*
DEFERRED RENDERING GEOMETRY PASS
*/
class GeometryPass : public RenderPass
{
/*Setup*/
Expand All @@ -36,7 +39,7 @@ class GeometryPass : public RenderPass
uint32_t framebufferCount,
ColorFormatType colorFormat,
ColorFormatType depthFormat,
bool isDefault = true)
bool isDefault = false)
: RenderPass(ctx, extent, framebufferCount, 1, isDefault)
, m_colorFormat(colorFormat)
, m_depthFormat(depthFormat) {
Expand Down
2 changes: 1 addition & 1 deletion include/engine/graphics/uniforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct SceneUniforms {
Vec4 fogColorAndSSAO; // w is for enabling SSAO
Vec4 fogParams; // x for near, y for far, z for intensity, w enable.
Vec4 ambientColor; // w intensity
LightUniforms lightUniforms[VK_MAX_LIGHTS];
LightUniforms lightUniforms[ENGINE_MAX_LIGHTS];
int numLights;
int SSAOtype;
int emphasizeAO;
Expand Down
2 changes: 1 addition & 1 deletion include/engine/systems.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include <engine/systems/renderers/renderer.h>
#include <engine/systems/renderers/forward.h>
// #include <engine/systems/renderers/deferred.h>
#include <engine/systems/renderers/deferred.h>



Expand Down
62 changes: 62 additions & 0 deletions include/engine/systems/renderers/deferred.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#ifndef DEFERRED_H
#define DEFERRED_H

#include <engine/core/renderpasses/composition_pass.h>
#include <engine/core/renderpasses/fxaa_pass.h>
#include <engine/core/renderpasses/geometry_pass.h>
#include <engine/core/renderpasses/variance_shadow_pass.h>
#include <engine/systems/renderers/renderer.h>

VULKAN_ENGINE_NAMESPACE_BEGIN

namespace Systems {

/*
Renders a given scene data to a given window using forward rendering. Fully parametrizable.
*/
class DeferredRenderer : public BaseRenderer
{
enum RenderPasses
{
SHADOW_PASS = 0,
GEOMETRY_PASS = 1,
COMPOSITION_PASS = 2,
FXAA_PASS = 3
};

bool m_softwareAA = true; //FXAA for now
ShadowResolution m_shadowQuality = ShadowResolution::MEDIUM;

//Query
bool m_updateShadows = false;

public:
DeferredRenderer(Core::IWindow* window)
: BaseRenderer(window) {
}
DeferredRenderer(Core::IWindow* window,
bool softwareAA = true,
ShadowResolution shadowQuality = ShadowResolution::MEDIUM,
RendererSettings settings = {})
: BaseRenderer(window, settings)
, m_softwareAA(softwareAA)
, m_shadowQuality(shadowQuality) {
}

inline void set_shadow_quality(ShadowResolution quality) {
m_shadowQuality = quality;
if (m_initialized)
m_updateShadows = true;
}

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

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

virtual void create_renderpasses();
};
} // namespace Systems
VULKAN_ENGINE_NAMESPACE_END

#endif
Loading

0 comments on commit 6d8599a

Please sign in to comment.