@@ -26,15 +26,15 @@ void main() {
2626#include utils.glsl
2727#include shadow_mapping.glsl
2828#include fresnel.glsl
29- #include ssao.glsl
3029#include IBL.glsl
31- #include reindhart.glsl
3230#include BRDFs/ schlick_smith_BRDF.glsl
3331#include BRDFs/ marschner_BSDF.glsl
32+ #include warp.glsl
3433#include raytracing.glsl
3534#include hashing.glsl
3635#include SSR.glsl
3736
37+
3838// INPUT
3939layout (location = 0 ) in vec2 v_uv;
4040
@@ -53,13 +53,25 @@ layout(set = 1, binding = 1) uniform sampler2D normalBuffer;
5353layout (set = 1 , binding = 2 ) uniform sampler2D colorBuffer;
5454layout (set = 1 , binding = 3 ) uniform sampler2D materialBuffer;
5555layout (set = 1 , binding = 4 ) uniform sampler2D emissionBuffer;
56- layout (set = 1 , binding = 5 ) uniform sampler2D prevBuffer;
56+ layout (set = 1 , binding = 5 ) uniform sampler2D preCompositionBuffer;
57+
58+ layout (set = 1 , binding = 6 ) uniform sampler2D prevBuffer;
59+
5760// SETTINGS
5861layout (push_constant) uniform Settings {
5962 uint bufferOutput;
63+ uint enableAO;
6064 SSR ssr;
6165} settings;
6266
67+ // DEBUGGING QUERIES
68+ #define LIGHTING_MODE settings.bufferOutput == 0
69+ #define ALBEDO_OUTPUT settings.bufferOutput == 1
70+ #define NORMALS_OUTPUT settings.bufferOutput == 2
71+ #define POSITION_OUTPUT settings.bufferOutput == 3
72+ #define MATERIAL_OUTPUT settings.bufferOutput == 4
73+ #define SSAO_OUTPUT settings.bufferOutput == 5
74+
6375// SURFACE PROPERTIES
6476vec3 g_pos;
6577float g_depth;
@@ -71,6 +83,7 @@ vec3 g_emission;
7183int g_isReflective;
7284vec4 g_temp;
7385
86+
7487void main()
7588{
7689
@@ -89,10 +102,18 @@ void main()
89102 g_emission = emissionFresnelThreshold.rgb;
90103 g_isReflective = int (emissionFresnelThreshold.w);
91104 g_temp = vec4 (0.0 );
105+ // /////////////////////////////////
106+ // PRE-COMPUTED DATA
107+ // /////////////////////////////////
108+ vec2 preComputedData = texture(preCompositionBuffer,v_uv).rg;
109+ float SSAO = preComputedData.r;
110+ float rtShadow = preComputedData.g;
111+
92112
93113 vec3 color = vec3 (0.0 );
94114 vec3 reflectedColor = vec3 (0.0 );
95- if (settings.bufferOutput == 0 ){
115+
116+ if (LIGHTING_MODE){
96117 // ////////////////////////////////////
97118 // IF LIT MATERIAL
98119 // ////////////////////////////////////
@@ -137,6 +158,9 @@ void main()
137158 lighting *= computeShadow(shadowMap, scene.lights[i], i, modelPos);
138159 if (scene.lights[i].shadowType == 1 ) // VSM
139160 lighting *= computeVarianceShadow(shadowMap, scene.lights[i], i, modelPos);
161+ // if(scene.lights[i].shadowType == 2) //Raytraced
162+ // lighting *= texture(preCompositionBuffer,v_uv).g;
163+
140164 if (scene.lights[i].shadowType == 2 ) // Raytraced
141165 lighting *= computeRaytracedShadow(
142166 TLAS,
@@ -167,7 +191,7 @@ void main()
167191 }else {
168192 ambient = (scene.ambientIntensity * scene.ambientColor) * brdf.albedo;
169193 }
170- ambient *= brdf.ao;
194+ ambient *= settings.enableAO == 1 ? (brdf.ao * SSAO) : brdf.ao;
171195 // SSR ________________________________
172196 vec3 fresnel = fresnelSchlick(max (dot (g_normal, normalize (g_pos)), 0.0 ), brdf.F0);
173197 if (settings.ssr.enabled == 1 && g_isReflective == 1 ){
@@ -226,7 +250,7 @@ void main()
226250 color = g_albedo;
227251 }
228252
229-
253+ // Fog ________________________________
230254 if (scene.enableFog){
231255 float f = computeFog(g_depth);
232256 color = f * color + (1 - f) * scene.fogColor.rgb;
@@ -236,21 +260,21 @@ void main()
236260
237261 }
238262 else { // DEBUG MODE
239- if (settings.bufferOutput == 1 ) // Albedo
263+ if (ALBEDO_OUTPUT)
240264 outColor = vec4 (g_albedo,1.0 );
241- if (settings.bufferOutput == 2 ) // Normals
242- outColor = vec4 (g_normal,1.0 );
243- if (settings.bufferOutput == 3 ) // Position
244- outColor = vec4 (g_pos,1.0 );
245- if (settings.bufferOutput == 4 ) // Material
265+ if (NORMALS_OUTPUT)
266+ outColor = vec4 ((camera.invView * vec4 ( g_normal.xyz, 0.0 )).xyz ,1.0 );
267+ if (POSITION_OUTPUT)
268+ outColor = vec4 ((camera.invView * vec4 ( g_pos.xyz, 1.0 )).xyz ,1.0 );
269+ if (MATERIAL_OUTPUT)
246270 outColor = g_material;
247- if (settings.bufferOutput == 5 ) // SSR
248- outColor = vec4 (reflectedColor ,1.0 );
249- }
271+ if (SSAO_OUTPUT)
272+ outColor = vec4 (SSAO,SSAO,SSAO ,1.0 );
273+ }
250274
251275 // check whether result is higher than some threshold, if so, output as bloom threshold color
252276 float brightness = dot (color, vec3 (0.2126 , 0.7152 , 0.0722 ));
253- if (brightness > 1.0 && settings.bufferOutput == 0 )
277+ if (brightness > 1.0 && LIGHTING_MODE )
254278 outBrightColor = vec4 (color, 1.0 );
255279 else
256280 outBrightColor = vec4 (0.0 , 0.0 , 0.0 , 1.0 );
0 commit comments