Skip to content

Commit 2f9f553

Browse files
committed
-Dev: starting changing the base pass (Compute pipelines only)
1 parent 604f4d1 commit 2f9f553

File tree

6 files changed

+237
-64
lines changed

6 files changed

+237
-64
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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 GRAPHIC_PASS_H
10+
#define GRAPHIC_PASS_H
11+
12+
#include <array>
13+
14+
#include <engine/common.h>
15+
16+
#include <engine/graphics/descriptors.h>
17+
#include <engine/graphics/device.h>
18+
#include <engine/graphics/frame.h>
19+
#include <engine/graphics/framebuffer.h>
20+
#include <engine/graphics/renderpass.h>
21+
#include <engine/graphics/swapchain.h>
22+
23+
#include <engine/core/scene/scene.h>
24+
25+
VULKAN_ENGINE_NAMESPACE_BEGIN
26+
27+
namespace Core {
28+
29+
/*
30+
Data containing a dependicy image's location belonging to a previows pass
31+
*/
32+
struct ImageDependency;
33+
34+
/*
35+
Core abstract GRAPHIC class needed for a renderer to work. It draws polygon primitives and rasterized them onto
36+
framebuffers. It controls the flow of the renderer state, what information and how it is being rendered. It also gives
37+
access to the framebuffers containing the rendered data. It can be inherited for full user control over the render
38+
pipeline.
39+
*/
40+
class GraphicPass : public BasePass
41+
{
42+
protected:
43+
Graphics::RenderPass m_renderpass = {};
44+
std::vector<Graphics::Framebuffer> m_framebuffers;
45+
uint32_t m_framebufferImageDepth; // In case if multilayered rendering.
46+
47+
virtual void
48+
setup_attachments(std::vector<Graphics::AttachmentInfo>& attachments,
49+
std::vector<Graphics::SubPassDependency>& dependencies) = 0;
50+
51+
public:
52+
GraphicPass(Graphics::Device* ctx,
53+
Extent2D extent,
54+
uint32_t framebufferCount = 1,
55+
uint32_t framebufferDepth = 1,
56+
bool isDefault = false,
57+
std::string name = "UNNAMED PASS")
58+
: m_device(ctx)
59+
, m_framebufferImageDepth(framebufferDepth)
60+
, m_isDefault(isDefault)
61+
, m_name(name) {
62+
!isDefault ? m_framebuffers.resize(framebufferCount)
63+
: m_framebuffers.resize(m_device->get_swapchain().get_present_images().size());
64+
m_imageExtent = extent;
65+
}
66+
virtual ~GraphicPass() {
67+
}
68+
69+
#pragma region Getters & Setters
70+
71+
72+
73+
inline Graphics::RenderPass get_renderpass() const {
74+
return m_renderpass;
75+
}
76+
inline std::vector<Graphics::Framebuffer> const get_framebuffers() const {
77+
return m_framebuffers;
78+
}
79+
inline std::vector<Graphics::Image> const get_resource_images() const {
80+
return m_resourceImages;
81+
}
82+
inline void set_attachment_clear_value(VkClearValue value, size_t attachmentLayout = 0) {
83+
m_renderpass.attachmentsInfo[attachmentLayout].clearValue = value;
84+
}
85+
86+
87+
88+
#pragma endregion
89+
#pragma region Core Functions
90+
/*
91+
Setups de renderpass. Init, create framebuffers, pipelines and resources ...
92+
*/
93+
void setup(std::vector<Graphics::Frame>& frames);
94+
95+
virtual void render(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0) = 0;
96+
97+
virtual void update_uniforms(uint32_t frameIndex, Scene* const scene) {
98+
}
99+
virtual void link_previous_images(std::vector<Graphics::Image> images) {
100+
}
101+
/**
102+
* Create framebuffers and images attached to them necessary for the
103+
* renderpass to work. It also sets the extent of the renderpass.
104+
*/
105+
virtual void create_framebuffer();
106+
/**
107+
* Destroy framebuffers and images attached to them necessary for the
108+
* renderpass to work. If images have a sampler attached to them, contol the
109+
* destruction of it too.
110+
*/
111+
virtual void clean_framebuffer();
112+
/**
113+
* Recreates the renderpass with new parameters. Useful for example, when
114+
* resizing the screen. It automatically manages framebuffer cleanup and
115+
* regeneration
116+
*
117+
*/
118+
virtual void update_framebuffer();
119+
/**
120+
* Destroy the renderpass and its shaderpasses. Framebuffers are managed in a
121+
* sepparate function for felxibilty matters
122+
*/
123+
virtual void cleanup();
124+
#pragma endregion
125+
126+
/*
127+
Public static member.
128+
Vignette for rendering textures onto screen.*/
129+
static Core::Geometry* vignette;
130+
};
131+
132+
#pragma region IMAGE DEP
133+
134+
struct ImageDependency {
135+
uint32_t passID = 0; // The pass that produces this image
136+
uint32_t fboID = 0; // The FBO within the pass that produces this image
137+
bool isFBO = true; // If set to false, It will take the attachments from the pass resourceImages (Useful if not a
138+
// graphical pass).
139+
std::vector<uint32_t> attachmentIDs; // The attachment indeces within the FBO
140+
141+
ImageDependency(uint32_t passId, u_int fboId, std::vector<uint32_t> attachmentIds)
142+
: passID(passId)
143+
, fboID(fboId)
144+
, attachmentIDs(attachmentIds) {
145+
}
146+
ImageDependency(uint32_t passId, std::vector<uint32_t> attachmentIds)
147+
: passID(passId)
148+
, attachmentIDs(attachmentIds)
149+
, isFBO(false) {
150+
}
151+
};
152+
153+
#pragma endregion
154+
} // namespace Core
155+
156+
VULKAN_ENGINE_NAMESPACE_END
157+
158+
#endif
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 SKINSSS_PASS_H
10+
// #define SKINSSS_PASS_H
11+
// #include <engine/core/passes/pass.h>
12+
13+
// VULKAN_ENGINE_NAMESPACE_BEGIN
14+
15+
// namespace Core {
16+
// /*
17+
// WIP
18+
// */
19+
// class SkinPass : public ComputePass
20+
// {
21+
// protected:
22+
// Graphics::DescriptorSet m_imageDescriptorSet;
23+
24+
// public:
25+
// PostProcessPass(Graphics::Device* ctx,
26+
// Extent2D extent)
27+
// : BasePass(ctx, extent, 0, 0, false, "SKIN PASS")
28+
// , m_colorFormat(colorFormat)
29+
// , m_shaderPath(shaderPath) {
30+
// }
31+
32+
// virtual void setup_attachments(std::vector<Graphics::AttachmentInfo>& attachments,
33+
// std::vector<Graphics::SubPassDependency>& dependencies);
34+
35+
// virtual void setup_uniforms(std::vector<Graphics::Frame>& frames);
36+
37+
// virtual void setup_shader_passes();
38+
39+
// virtual void render(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
40+
41+
// virtual void link_previous_images(std::vector<Graphics::Image> images);
42+
43+
// void clean_framebuffer() {
44+
// GraphicPass::clean_framebuffer();
45+
// }
46+
// };
47+
48+
// } // namespace Core
49+
// VULKAN_ENGINE_NAMESPACE_END
50+
51+
// #endif

resources/shaders/deferred/composition.glsl

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ vec3 g_emission;
8888
int g_isReflective;
8989
vec4 g_temp;
9090

91+
float evalVisibility(int i, vec3 modelPos) {
92+
if(scene.lights[i].shadowCast == 1) {
93+
if(scene.lights[i].shadowType == 0) //Classic
94+
return computeShadow(shadowMap, scene.lights[i], i, modelPos);
95+
if(scene.lights[i].shadowType == 1) //VSM
96+
return computeVarianceShadow(shadowMap, scene.lights[i], i, modelPos);
97+
if(scene.lights[i].shadowType == 2) //Raytraced
98+
return computeRaytracedShadow(TLAS, samplerMap, modelPos, scene.lights[i].type != DIRECTIONAL_LIGHT ? scene.lights[i].worldPosition.xyz - modelPos : -scene.lights[i].shadowData.xyz, int(scene.lights[i].shadowData.w), scene.lights[i].area, scene.lights[i].type != DIRECTIONAL_LIGHT ? length(scene.lights[i].worldPosition.xyz - modelPos) : 30.0, 0);
99+
}
100+
}
101+
91102
void main() {
92103

93104
//////////////////////////////////////
@@ -177,14 +188,7 @@ void main() {
177188
brdf);
178189

179190
//Visibility Component ________________________
180-
if(scene.lights[i].shadowCast == 1) {
181-
if(scene.lights[i].shadowType == 0) //Classic
182-
lighting *= computeShadow(shadowMap, scene.lights[i], i, modelPos);
183-
if(scene.lights[i].shadowType == 1) //VSM
184-
lighting *= computeVarianceShadow(shadowMap, scene.lights[i], i, modelPos);
185-
if(scene.lights[i].shadowType == 2) //Raytraced
186-
lighting *= computeRaytracedShadow(TLAS, samplerMap, modelPos, scene.lights[i].type != DIRECTIONAL_LIGHT ? scene.lights[i].worldPosition.xyz - modelPos : -scene.lights[i].shadowData.xyz, int(scene.lights[i].shadowData.w), scene.lights[i].area, scene.lights[i].type != DIRECTIONAL_LIGHT ? length(scene.lights[i].worldPosition.xyz - modelPos) : 30.0, 0);
187-
}
191+
lighting *= evalVisibility(i, modelPos);
188192
direct += lighting;
189193
}
190194
}
@@ -250,14 +254,8 @@ void main() {
250254
// // v_uv, camDist, positionBuffer, materialBuffer, materialBuffer, bsdf);
251255

252256
// //Visibility Component ________________________
253-
// if(scene.lights[i].shadowCast == 1) {
254-
// if(scene.lights[i].shadowType == 0) //Classic
255-
// lighting *= computeShadow(shadowMap, scene.lights[i], i, modelPos);
256-
// if(scene.lights[i].shadowType == 1) //VSM
257-
// lighting *= computeVarianceShadow(shadowMap, scene.lights[i], i, modelPos);
258-
// if(scene.lights[i].shadowType == 2) //Raytraced
259-
// lighting *= computeRaytracedShadow(TLAS, samplerMap, modelPos, scene.lights[i].type != DIRECTIONAL_LIGHT ? scene.lights[i].worldPosition.xyz - modelPos : -scene.lights[i].shadowData.xyz, int(scene.lights[i].shadowData.w), scene.lights[i].area, scene.lights[i].type != DIRECTIONAL_LIGHT ? length(scene.lights[i].worldPosition.xyz - modelPos) : 30.0, 0);
260-
// }
257+
// lighting *= evalVisibility(i,modelPos);
258+
//
261259
// direct += lighting;
262260
// }
263261
// }

resources/shaders/deferred/geometry.glsl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ layout(location = 0) out vec4 outPos;
8080
layout(location = 1) out vec4 outNormal;
8181
layout(location = 2) out vec4 outAlbedo;
8282
layout(location = 3) out vec4 outMaterial; //U8
83-
layout(location = 4) out vec4 outMaterial2; //F32
83+
layout(location = 4) out vec4 outEmissive; //F32
8484
// layout(location = 5) out vec4 outTemporal;
8585

8686
#define EPSILON 0.1
@@ -92,7 +92,7 @@ vec3 g_albedo = vec3(0.0);
9292
float g_opacity = 1.0;
9393
vec3 g_normal = vec3(0.0);
9494
vec4 g_material = vec4(0.0);
95-
vec3 g_material2 = vec3(0.0);
95+
vec3 g_emissive = vec3(0.0);
9696
float g_fresnelThreshold = 0.0;
9797

9898
void setupSurfaceProperties(){
@@ -125,8 +125,8 @@ void setupSurfaceProperties(){
125125
g_material.b = material.slot5.w== 1 ? mix(material.slot4.y, texture(materialText3, v_uv).r, material.slot4.z) : material.slot4.y; //AO
126126
}
127127

128-
g_material2 = material.slot6.w == 1 ? mix(material.slot7.rgb, texture(materialText4, v_uv).rgb, material.slot7.w) : material.slot7.rgb;
129-
g_material2 *= material.slot8.x;
128+
g_emissive = material.slot6.w == 1 ? mix(material.slot7.rgb, texture(materialText4, v_uv).rgb, material.slot7.w) : material.slot7.rgb;
129+
g_emissive *= material.slot8.x;
130130

131131
g_fresnelThreshold = material.slot8.y;
132132

@@ -176,7 +176,7 @@ void main() {
176176
outNormal = vec4( g_normal , 1.0f );
177177
outAlbedo = vec4(g_albedo,g_opacity);
178178
outMaterial = g_material; //w material ID
179-
outMaterial2 = vec4(g_material2,g_fresnelThreshold); //w Fresnel Threshold
179+
outEmissive = vec4(g_emissive,g_fresnelThreshold); //w Fresnel Threshold
180180
// outTemporal = vec4(0.0); //TBD
181181

182182
}

resources/shaders/include/BRDFs/cook_torrance_BRDF.glsl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ vec3 evalCookTorranceBRDF(
8080
vec3 specular = numerator / denominator;
8181

8282
//Clamp specular value
83-
float roughnessThreshold = 0.1;
84-
float smoothness = 1.0 - smoothstep(0.0, roughnessThreshold, brdf.roughness);
85-
float specularScale = 1.0 - smoothness * 0.1; // Scaling factor reduces specular at low roughness
86-
specular *= specularScale;
83+
float roughnessThreshold = 0.1;
84+
float smoothness = 1.0 - smoothstep(0.0, roughnessThreshold, brdf.roughness);
85+
float specularScale = 1.0 - smoothness * 0.1; // Scaling factor reduces specular at low roughness
86+
specular *= specularScale;
8787

8888
// Add to outgoing radiance result
8989
float lambertian = max(dot(brdf.normal, wi), 0.0);

src/core/passes/geometry_pass.cpp

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void GeometryPass::setup_attachments(std::vector<Graphics::AttachmentInfo>& a
1111
/////////////////////
1212
attachments.resize(6);
1313

14-
// Positions
14+
// Positions + Depth
1515
attachments[0] = Graphics::AttachmentInfo(SRGBA_32F,
1616
1,
1717
LAYOUT_SHADER_READ_ONLY_OPTIMAL,
@@ -24,7 +24,7 @@ void GeometryPass::setup_attachments(std::vector<Graphics::AttachmentInfo>& a
2424
LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2525
IMAGE_USAGE_COLOR_ATTACHMENT | IMAGE_USAGE_SAMPLED);
2626
// Albedo
27-
attachments[2] = Graphics::AttachmentInfo(SRGBA_32F,
27+
attachments[2] = Graphics::AttachmentInfo(RGBA_8U,
2828
1,
2929
LAYOUT_SHADER_READ_ONLY_OPTIMAL,
3030
LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
@@ -35,7 +35,7 @@ void GeometryPass::setup_attachments(std::vector<Graphics::AttachmentInfo>& a
3535
LAYOUT_SHADER_READ_ONLY_OPTIMAL,
3636
LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3737
IMAGE_USAGE_COLOR_ATTACHMENT | IMAGE_USAGE_SAMPLED);
38-
// Material 2 (Emissive most of the time)
38+
// Emissive
3939
attachments[4] = Graphics::AttachmentInfo(SRGBA_32F,
4040
1,
4141
LAYOUT_SHADER_READ_ONLY_OPTIMAL,
@@ -217,22 +217,7 @@ void GeometryPass::setup_shader_passes() {
217217

218218
m_shaderPasses["skybox"] = skyboxPass;
219219

220-
// GraphicShaderPass* skyplanePass = new GraphicShaderPass(
221-
// m_device->get_handle(), m_renderpass, m_imageExtent, ENGINE_RESOURCES_PATH "shaders/env/sky_projection.glsl");
222-
// skyplanePass->settings.descriptorSetLayoutIDs = {{0, true}};
223-
// skyplanePass->graphicSettings.attributes = {{POSITION_ATTRIBUTE, true},
224-
// {NORMAL_ATTRIBUTE, false},
225-
// {UV_ATTRIBUTE, true},
226-
// {TANGENT_ATTRIBUTE, false},
227-
// {COLOR_ATTRIBUTE, false}};
228-
// skyplanePass->graphicSettings.dynamicStates = geomPass->graphicSettings.dynamicStates;
229-
// skyplanePass->graphicSettings.blendAttachments = geomPass->graphicSettings.blendAttachments;
230-
// // skyplanePass->graphicSettings.depthOp = VK_COMPARE_OP_LESS_OR_EQUAL;
231-
232-
// skyplanePass->build_shader_stages();
233-
// skyplanePass->build(m_descriptorPool);
234-
235-
// m_shaderPasses["skyplane"] = skyplanePass;
220+
236221
}
237222
void GeometryPass::render(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex) {
238223
PROFILING_EVENT()
@@ -243,26 +228,7 @@ void GeometryPass::render(Graphics::Frame& currentFrame, Scene* const scene, uin
243228

244229
if (scene->get_active_camera() && scene->get_active_camera()->is_active())
245230
{
246-
// if (scene->get_skybox())
247-
// {
248-
// if (scene->get_skybox()->is_active())
249-
// {
250-
251-
// cmd.set_depth_test_enable(false);
252-
// cmd.set_depth_write_enable(false);
253-
// cmd.set_cull_mode(CullingMode::NO_CULLING);
254-
255-
// ShaderPass* shaderPass = m_shaderPasses["skyplane"];
256-
257-
// // Bind pipeline
258-
// cmd.bind_shaderpass(*shaderPass);
259-
260-
// // GLOBAL LAYOUT BINDING
261-
// cmd.bind_descriptor_set(m_descriptors[currentFrame.index].globalDescritor, 0, *shaderPass, {0, 0});
262-
263-
// cmd.draw_geometry(*get_VAO(BasePass::vignette));
264-
// }
265-
// }
231+
266232

267233
ShaderPass* shaderPass = m_shaderPasses["geometry"];
268234

0 commit comments

Comments
 (0)