Skip to content

Commit 7fb7484

Browse files
committed
-Fix: bloom pass compute in GFX queue & VXGI AO
1 parent 6c202b0 commit 7fb7484

File tree

23 files changed

+302
-177
lines changed

23 files changed

+302
-177
lines changed

examples/resources/scenes/sponza.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
<albedo r="0.5" g="0.5" b="0.5" />
177177
</Material>
178178
</Mesh>
179-
<!-- <Mesh type="file" name="Leaves" alphaTest="true">
179+
<Mesh type="file" name="Leaves" alphaTest="true">
180180
<Filename value="meshes/leaves.obj" />
181181
<Material type="physical">
182182
<Textures>
@@ -185,7 +185,7 @@
185185
</Textures>
186186
<albedo r="0.5" g="0.5" b="0.5" />
187187
</Material>
188-
</Mesh> -->
188+
</Mesh>
189189
<Mesh type="file" name="Vase Leaves" alphaTest="true">
190190
<Filename value="meshes/leaves2.obj" />
191191
<Material type="physical">

include/engine/core/passes/composition_pass.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct VXGI { // Settings for Voxel Based GI
4040
float strength = 1.0f;
4141
float diffuseConeSpread = 0.577f;
4242
float offset = 1.0f;
43-
float maxDistance = 75.0f;
43+
float maxDistance = 35.0f;
4444
uint32_t resolution = 256;
4545
uint32_t samples = 8;
4646
uint32_t enabled = 1;
@@ -65,6 +65,7 @@ class CompositionPass : public GraphicPass
6565
struct Settings {
6666
OutputBuffer outputBuffer = OutputBuffer::LIGHTING;
6767
int enableAO = 1;
68+
int AOtype = 0;
6869
VXGI vxgi = {};
6970
SSR ssr = {};
7071
};
@@ -107,6 +108,12 @@ class CompositionPass : public GraphicPass
107108
inline void enable_AO(bool op) {
108109
m_settings.enableAO = op;
109110
}
111+
inline int get_AO_type() const {
112+
return m_settings.AOtype;
113+
}
114+
inline void set_AO_type(int op) {
115+
m_settings.AOtype = op;
116+
}
110117

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

include/engine/core/passes/precomposition_pass.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ typedef enum class AmbientOcclusionType
1919
{
2020
SSAO = 0,
2121
RTAO = 1, // Raytraced AO
22+
VXAO = 2, // Voxel Cone Traced
2223
} AOType;
23-
struct SSAOSettings {
24+
struct AO {
2425
float radius = 0.2;
2526
float bias = 0.0;
2627
uint32_t samples = 4;
@@ -49,7 +50,7 @@ class PreCompositionPass : public GraphicPass
4950
Graphics::Buffer m_kernelBuffer;
5051
bool m_updateSamplesKernel = true;
5152
/*Settings*/
52-
SSAOSettings m_AO = {};
53+
AO m_AO = {};
5354

5455
void create_samples_kernel();
5556

@@ -59,12 +60,12 @@ class PreCompositionPass : public GraphicPass
5960
, m_vignette(vignette) {
6061
}
6162

62-
inline void set_SSAO_settings(SSAOSettings settings) {
63+
inline void set_SSAO_settings(AO settings) {
6364
if (settings.samples != m_AO.samples)
6465
m_updateSamplesKernel = true;
6566
m_AO = settings;
6667
};
67-
inline SSAOSettings get_SSAO_settings() const {
68+
inline AO get_SSAO_settings() const {
6869
return m_AO;
6970
};
7071

include/engine/core/passes/voxelization_pass.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class VoxelizationPass : public GraphicPass
5252

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

55+
void update();
56+
5557
void cleanup();
5658
};
5759

include/engine/systems/renderers/deferred.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ class DeferredRenderer : public BaseRenderer
3333
};
3434

3535
// Graphic Settings
36-
ShadowResolution m_shadowQuality = ShadowResolution::MEDIUM;
37-
Core::SSR m_SSR = {};
38-
Core::VXGI m_VXGI = {};
39-
Core::SSAOSettings m_SSAO = {};
40-
float m_bloomStrength = 0.05f;
36+
ShadowResolution m_shadowQuality = ShadowResolution::MEDIUM;
37+
Core::SSR m_SSR = {};
38+
Core::VXGI m_VXGI = {};
39+
Core::AO m_AO = {};
40+
float m_bloomStrength = 0.05f;
4141

4242
// Query
4343
bool m_updateShadows = false;
44+
bool m_updateGI = false;
4445

4546
public:
4647
DeferredRenderer(Core::IWindow* window)
@@ -74,16 +75,18 @@ class DeferredRenderer : public BaseRenderer
7475
return m_SSR;
7576
};
7677
inline void set_VXGI_settings(Core::VXGI settings) {
78+
if (m_VXGI.resolution != settings.resolution)
79+
m_updateGI = true;
7780
m_VXGI = settings;
7881
};
7982
inline Core::VXGI get_VXGI_settings() const {
8083
return m_VXGI;
8184
};
82-
inline void set_SSAO_settings(Core::SSAOSettings settings) {
83-
m_SSAO = settings;
85+
inline void set_SSAO_settings(Core::AO settings) {
86+
m_AO = settings;
8487
};
85-
inline Core::SSAOSettings get_SSAO_settings() const {
86-
return m_SSAO;
88+
inline Core::AO get_SSAO_settings() const {
89+
return m_AO;
8790
};
8891
inline void set_shading_output(Core::OutputBuffer output) {
8992
static_cast<Core::CompositionPass*>(m_passes[COMPOSITION_PASS])->set_output_buffer(output);
@@ -93,7 +96,6 @@ class DeferredRenderer : public BaseRenderer
9396
}
9497
inline void set_clearcolor(Vec4 c) {
9598
BaseRenderer::set_clearcolor(c);
96-
9799
}
98100

99101
protected:

resources/shaders/VXGI/merge_intermediates.glsl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
layout(local_size_x = 4, local_size_y = 4, local_size_z = 4) in;
88

9-
layout(set = 0, binding = 6, r32f) uniform image3D finalVoxelImage;
10-
// layout(set = 0, binding = 7, r32ui) uniform uimage3D interVoxelImages[3];
11-
layout(set = 0, binding = 8) uniform usampler3D interVoxelImages[3];
9+
layout(set = 0, binding = 6, r32f) uniform image3D finalVoxelImage;
10+
layout(set = 0, binding = 8) uniform usampler3D interVoxelImages[3];
1211

1312
void main()
1413
{
@@ -20,9 +19,6 @@ void main()
2019
uint r = texelFetch(interVoxelImages[0], imgCoord, 0).r;
2120
uint g = texelFetch(interVoxelImages[1], imgCoord, 0).r;
2221
uint b = texelFetch(interVoxelImages[2], imgCoord, 0).r;
23-
// float r = imageLoad(interVoxelImages[0], imgCoord).r;
24-
// float g = imageLoad(interVoxelImages[1], imgCoord).r;
25-
// float b = imageLoad(interVoxelImages[2], imgCoord).r;
2622
imageStore(finalVoxelImage, imgCoord, vec4(uintBitsToFloat(r), uintBitsToFloat(g), uintBitsToFloat(b), a));
2723
}
2824
}

resources/shaders/VXGI/voxelization.glsl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ void main(){
9797
#include material_defines.glsl
9898

9999

100-
101-
102100
layout(location = 0) in vec3 _pos;
103101
layout(location = 1) in vec3 _normal;
104102
layout(location = 2) in vec2 _uv;

resources/shaders/deferred/composition.glsl

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ void main() {
2626
#include utils.glsl
2727
#include shadow_mapping.glsl
2828
#include fresnel.glsl
29-
#include IBL.glsl
30-
#include BRDFs/schlick_smith_BRDF.glsl
29+
#include BRDFs/cook_torrance_BRDF.glsl
3130
#include BRDFs/marschner_BSDF.glsl
3231
#include warp.glsl
3332
#include raytracing.glsl
@@ -63,6 +62,7 @@ layout(set = 1, binding = 6) uniform sampler2D prevBuffer;
6362
layout(push_constant) uniform Settings {
6463
uint bufferOutput;
6564
uint enableAO;
65+
uint AOtype;
6666
VXGI vxgi; //Voxel Based GI
6767
SSR ssr; //Screen Space Reflections
6868
} settings;
@@ -134,7 +134,7 @@ void main()
134134
//////////////////////////////////////
135135
if(g_material.w == PHYSICAL_MATERIAL){
136136
//Populate BRDF ________________________
137-
SchlickSmithBRDF brdf;
137+
CookTorranceBRDF brdf;
138138
brdf.albedo = g_albedo;
139139
brdf.opacity = g_opacity;
140140
brdf.normal = g_normal;
@@ -151,17 +151,23 @@ void main()
151151
if(settings.vxgi.enabled == 1){
152152

153153
// Diffuse
154-
indirect = diffuseVoxelGI2(voxelMap, modelPos, modelNormal, settings.vxgi, scene.maxCoord.x-scene.minCoord.x);
154+
indirect = diffuseVoxelGI2(voxelMap , modelPos, modelNormal, settings.vxgi, scene.maxCoord.x-scene.minCoord.x);
155155
indirect.rgb *= g_albedo;
156-
indirect.rgb *= settings.enableAO == 1 ? (brdf.ao * SSAO) : brdf.ao; //Add ambient occlusion
156+
indirect.rgb *= (1.0 - indirect.a);
157+
// indirect.rgb = evalDiffuseCookTorranceBRDF(
158+
// modelNormal,
159+
// normalize(camera.position.xyz-modelPos),
160+
// indirect.rgb,
161+
// brdf);
162+
//indirect = diffuseVoxelGI_CookTorrance(voxelMap, irradianceMap, modelPos, modelNormal,normalize(camera.position.xyz-modelPos), settings.vxgi, brdf, scene.maxCoord.x-scene.minCoord.x);
157163

158164
// Specular
159-
vec3 specularConeDirection = reflect(-normalize(camera.position.xyz-modelPos), modelNormal);
160-
float voxelWorldSize = (scene.maxCoord.x-scene.minCoord.x) / float(settings.vxgi.resolution);
161-
vec3 startPos = modelPos + modelNormal * voxelWorldSize * settings.vxgi.offset;
165+
// vec3 specularConeDirection = reflect(-normalize(camera.position.xyz-modelPos), modelNormal);
166+
// float voxelWorldSize = (scene.maxCoord.x-scene.minCoord.x) / float(settings.vxgi.resolution);
167+
// vec3 startPos = modelPos + modelNormal * voxelWorldSize * settings.vxgi.offset;
162168

163-
const float CONE_SPREAD = mix(0.005, settings.vxgi.diffuseConeSpread, brdf.roughness);
164-
indirectSpecular = traceCone(voxelMap, startPos, specularConeDirection, settings.vxgi.maxDistance, CONE_SPREAD, voxelWorldSize ).rgb;
169+
// const float CONE_SPREAD = mix(0.005, settings.vxgi.diffuseConeSpread, brdf.roughness);
170+
// indirectSpecular = traceCone(voxelMap, startPos, specularConeDirection, settings.vxgi.maxDistance, CONE_SPREAD, voxelWorldSize ).rgb;
165171

166172
// indirect+=specularIndirect.rgb;
167173
}
@@ -172,7 +178,7 @@ void main()
172178

173179
//Direct Component ________________________
174180
vec3 lighting = vec3(0.0);
175-
lighting = evalSchlickSmithBRDF(
181+
lighting = evalCookTorranceBRDF(
176182
scene.lights[i].type != DIRECTIONAL_LIGHT ? normalize(scene.lights[i].position - g_pos) : normalize(scene.lights[i].position.xyz), //wi
177183
normalize(-g_pos), //wo
178184
scene.lights[i].color * computeAttenuation(scene.lights[i].position, g_pos,scene.lights[i].areaEffect,int(scene.lights[i].type)) * scene.lights[i].intensity, //radiance
@@ -202,20 +208,18 @@ void main()
202208
direct += brdf.emission;
203209
//Ambient Component ________________________
204210
if(scene.useIBL){
205-
ambient = computeAmbient(
206-
irradianceMap,
207-
scene.envRotation,
208-
modelNormal,
209-
normalize(camera.position.xyz-modelPos),
210-
brdf.albedo,
211-
brdf.F0,
212-
brdf.metalness,
213-
brdf.roughness,
214-
scene.ambientIntensity);
211+
mat3 rotY = rotationY(radians(scene.envRotation));
212+
vec3 rotatedNormal = normalize(rotY * modelNormal);
213+
vec3 irradiance = texture(irradianceMap, rotatedNormal).rgb*scene.ambientIntensity;
214+
ambient = evalDiffuseCookTorranceBRDF(
215+
rotatedNormal,
216+
normalize(camera.position.xyz-modelPos),
217+
irradiance,
218+
brdf);
215219
}else{
216220
ambient = (scene.ambientIntensity * scene.ambientColor) * brdf.albedo;
217221
}
218-
ambient *= settings.enableAO == 1 ? (brdf.ao * SSAO) : brdf.ao;
222+
ambient *= settings.enableAO == 1 ? settings.AOtype != 2 ? (brdf.ao * SSAO) : 1.0 - indirect.a : brdf.ao;
219223

220224
//SSR ________________________________
221225
vec3 fresnel = fresnelSchlick(max(dot(g_normal, normalize(g_pos)), 0.0), brdf.F0);

resources/shaders/forward/physically_based.glsl

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,8 @@ void main() {
8484
#include utils.glsl
8585
#include shadow_mapping.glsl
8686
#include fresnel.glsl
87-
#include ssao.glsl
88-
#include IBL.glsl
8987
#include reindhart.glsl
90-
#include BRDFs/schlick_smith_BRDF.glsl
88+
#include BRDFs/cook_torrance_BRDF.glsl
9189
#include warp.glsl
9290
#include raytracing.glsl
9391

@@ -145,7 +143,7 @@ layout(set = 2, binding = 5) uniform sampler2D emissiveTex;
145143

146144

147145
//BRDF Definiiton
148-
SchlickSmithBRDF brdf;
146+
CookTorranceBRDF brdf;
149147

150148

151149
void setupBRDFProperties(){
@@ -197,7 +195,7 @@ void main() {
197195
//If inside liught area influence
198196
if(isInAreaOfInfluence(scene.lights[i].position, v_pos,scene.lights[i].areaEffect,int(scene.lights[i].type))){
199197

200-
vec3 lighting =evalSchlickSmithBRDF(
198+
vec3 lighting =evalCookTorranceBRDF(
201199
scene.lights[i].type != DIRECTIONAL_LIGHT ? normalize(scene.lights[i].position - v_pos) : normalize(scene.lights[i].position.xyz), //wi
202200
normalize(-v_pos), //wo
203201
scene.lights[i].color * computeAttenuation(scene.lights[i].position, v_pos,scene.lights[i].areaEffect,int(scene.lights[i].type)) * scene.lights[i].intensity, //radiance
@@ -228,16 +226,14 @@ void main() {
228226
//Ambient component ___________________________________________________________________
229227
vec3 ambient;
230228
if(scene.useIBL){
231-
ambient = computeAmbient(
232-
irradianceMap,
233-
scene.envRotation,
234-
v_modelNormal,
235-
normalize(camera.position.xyz-v_modelPos),
236-
brdf.albedo,
237-
brdf.F0,
238-
brdf.metalness,
239-
brdf.roughness,
240-
scene.ambientIntensity);
229+
mat3 rotY = rotationY(radians(scene.envRotation));
230+
vec3 rotatedNormal = normalize(rotY * v_modelNormal);
231+
vec3 irradiance = texture(irradianceMap, rotatedNormal).rgb*scene.ambientIntensity;
232+
ambient = evalDiffuseCookTorranceBRDF(
233+
rotatedNormal,
234+
normalize(camera.position.xyz-modelPos),
235+
irradiance,
236+
brdf);
241237
}else{
242238
ambient = (scene.ambientIntensity * scene.ambientColor) * brdf.albedo;
243239
}

resources/shaders/include/BRDFs/schlick_smith_BRDF.glsl renamed to resources/shaders/include/BRDFs/cook_torrance_BRDF.glsl

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
//////////////////////////////////////////////
2+
// ATTENTTION
3+
// This script needs: fresnel.glsl
4+
//////////////////////////////////////////////
5+
16
#ifndef PI
27
#define PI 3.1415926535897932384626433832795
38
#endif
49
#ifndef EPSILON
510
#define EPSILON 0.001
611
#endif
712

8-
struct SchlickSmithBRDF{
13+
struct CookTorranceBRDF{
914
vec3 albedo;
1015
float opacity;
1116
vec3 normal;
@@ -52,11 +57,11 @@ float geometrySmith(vec3 N, vec3 V, vec3 L, float roughness) {
5257
return ggx1 * ggx2;
5358
}
5459

55-
vec3 evalSchlickSmithBRDF(
60+
vec3 evalCookTorranceBRDF(
5661
vec3 wi,
5762
vec3 wo,
5863
vec3 radiance,
59-
SchlickSmithBRDF brdf)
64+
CookTorranceBRDF brdf)
6065
{
6166

6267
//Vector setup
@@ -88,3 +93,17 @@ vec3 evalSchlickSmithBRDF(
8893
return (kD * brdf.albedo / PI + specular) * radiance * lambertian;
8994

9095
}
96+
// For IBL
97+
vec3 evalDiffuseCookTorranceBRDF(
98+
vec3 wi,
99+
vec3 wo,
100+
vec3 irradiance,
101+
CookTorranceBRDF brdf){
102+
103+
vec3 specularity = fresnelSchlickRoughness(max(dot(wi, wo), 0.0), brdf.F0, brdf.roughness);
104+
vec3 aDiffuse = vec3(1.0) - specularity;
105+
aDiffuse *= 1.0 - brdf.metalness;
106+
107+
vec3 diffuse = irradiance * brdf.albedo;
108+
return aDiffuse * diffuse;
109+
}

0 commit comments

Comments
 (0)