Skip to content

Commit

Permalink
debug gi
Browse files Browse the repository at this point in the history
  • Loading branch information
LifeKILLED committed Nov 3, 2023
1 parent 3f9928a commit 77dc69e
Show file tree
Hide file tree
Showing 12 changed files with 451 additions and 49 deletions.
20 changes: 11 additions & 9 deletions ref/vk/shaders/lk_dnsr_compose.comp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@ layout(set = 0, binding = 8, rgba16f) uniform readonly image2D gi_sh1_denoised;
layout(set = 0, binding = 9, rgba16f) uniform readonly image2D gi_sh2_denoised;
layout(set = 0, binding = 10, rgba32f) uniform readonly image2D refl_position_t;

layout(set = 0, binding = 12, rgba16f) uniform readonly image2D blue_noise;
layout(set = 0, binding = 11, rgba16f) uniform readonly image2D blue_noise;

//layout(set = 0, binding = 13, rgba16f) uniform writeonly image2D out_temporal_gi_sh1_denoised;
//layout(set = 0, binding = 14, rgba16f) uniform writeonly image2D out_temporal_gi_sh2_denoised;
layout(set = 0, binding = 12, rgba16f) uniform writeonly image2D out_temporal_gi_sh1_denoised;
layout(set = 0, binding = 13, rgba16f) uniform writeonly image2D out_temporal_gi_sh2_denoised;

//layout(set = 0, binding = 10, rgba16f) uniform readonly image2D gi_sh1_accum;
//layout(set = 0, binding = 11, rgba16f) uniform readonly image2D gi_sh2_accum;
layout(set = 0, binding = 14, rgba16f) uniform readonly image2D gi_sh1_accum;
layout(set = 0, binding = 15, rgba16f) uniform readonly image2D gi_sh2_accum;

layout(set = 0, binding = 16, rgba32f) uniform readonly image2D gi_position_t;

#define GLSL
#include "ray_interop.h"
#undef GLSL

layout(set = 0, binding = 11) uniform UBO { UniformBuffer ubo; } ubo;
layout(set = 0, binding = 17) uniform UBO { UniformBuffer ubo; } ubo;

// Blatantly copypasted from https://www.shadertoy.com/view/XsGfWV
vec3 aces_tonemap(vec3 color){
Expand Down Expand Up @@ -151,7 +153,7 @@ void main() {
// low_freq.CoCg = FIX_NAN(imageLoad(gi_sh2_accum, pix)).xy;
// colour = project_SH_irradiance(low_freq, shading_normal) / STORAGE_SCALE_LF;

//colour = diffuse_gi;
// colour = normalize(imageLoad(gi_position_t, pix).xyz);

//colour = FIX_NAN(imageLoad(diffuse_denoised, pix)).rgb;

Expand Down Expand Up @@ -194,8 +196,8 @@ void main() {

imageStore(out_composed, pix, vec4(colour, 0.));

//imageStore(out_temporal_gi_sh1_denoised, pix, low_freq.shY);
//imageStore(out_temporal_gi_sh2_denoised, pix, vec4(low_freq.CoCg, 0., 0.));
imageStore(out_temporal_gi_sh1_denoised, pix, low_freq.shY);
imageStore(out_temporal_gi_sh2_denoised, pix, vec4(low_freq.CoCg, 0., 0.));

//imageStore(dest, pix, FIX_NAN(imageLoad(light_direct_poly, pix)));
}
15 changes: 15 additions & 0 deletions ref/vk/shaders/lk_dnsr_light_gi_point_w23.comp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 460 core
#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_ray_query: require

#define RAY_QUERY

#define SECOND_POSITION gi_position_t

#define GI

#define LIGHT_POINT 1
#define OUTPUTS(X) \
X(20, light_point_diffuse_gi, rgba16f) \
X(21, light_point_specular_gi, rgba16f)
#include "lk_dnsr_lights_direct_w23.glsl"
49 changes: 26 additions & 23 deletions ref/vk/shaders/lk_dnsr_lighting_mix.comp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ layout(set = 0, binding = 10, rgba16f) uniform readonly image2D light_poly_refl;

layout(set = 0, binding = 11, rgba16f) uniform readonly image2D light_point_diffuse_refl;
layout(set = 0, binding = 12, rgba16f) uniform readonly image2D light_point_specular_refl;
/*

layout(set = 0, binding = 11, rgba16f) uniform readonly image2D light_poly_gi;
layout(set = 0, binding = 12, rgba16f) uniform readonly image2D light_point_gi;
*/
layout(set = 0, binding = 13, rgba16f) uniform readonly image2D refl_emissive;
/*layout(set = 0, binding = 14, rgba16f) uniform readonly image2D gi_emissive;
layout(set = 0, binding = 15, rgba8) uniform readonly image2D gi_base_color_a;
layout(set = 0, binding = 16, rgba16f) uniform readonly image2D gi_troughput;
layout(set = 0, binding = 17, rgba32f) uniform readonly image2D gi_position_t;
layout(set = 0, binding = 18, rgba32f) uniform readonly image2D gi_prev_bounce_pos;*/

layout(set = 0, binding = 12, rgba16f) uniform readonly image2D light_point_diffuse_gi;
layout(set = 0, binding = 13, rgba16f) uniform readonly image2D light_point_specular_gi;

layout(set = 0, binding = 14, rgba16f) uniform readonly image2D refl_emissive;
layout(set = 0, binding = 15, rgba16f) uniform readonly image2D gi_emissive;
layout(set = 0, binding = 16, rgba8) uniform readonly image2D gi_base_color_a;
layout(set = 0, binding = 17, rgba16f) uniform readonly image2D gi_troughput;
layout(set = 0, binding = 18, rgba32f) uniform readonly image2D gi_position_t;
layout(set = 0, binding = 19, rgba32f) uniform readonly image2D gi_prev_bounce_pos;



Expand Down Expand Up @@ -79,20 +81,20 @@ void main() {
return;
}

const vec3 diffuse = FIX_NAN(imageLoad(light_point_diffuse, pix)).rgb
+ FIX_NAN(imageLoad(light_poly_diffuse, pix)).rgb;
//const vec3 diffuse = FIX_NAN(imageLoad(light_point_diffuse, pix)).rgb
// + FIX_NAN(imageLoad(light_poly_diffuse, pix)).rgb;

const vec3 specular = FIX_NAN(imageLoad(light_poly_refl, pix)).rgb
+ FIX_NAN(imageLoad(light_point_diffuse_refl, pix)).rgb
+ FIX_NAN(imageLoad(light_point_specular_refl, pix)).rgb
+ FIX_NAN(imageLoad(light_poly_specular, pix)).rgb
//+ FIX_NAN(imageLoad(light_poly_specular, pix)).rgb
+ FIX_NAN(imageLoad(light_point_specular, pix)).rgb
+ FIX_NAN(imageLoad(refl_emissive, pix)).rgb;

imageStore(out_diffuse_accum, pix, vec4(diffuse, 0.));
//imageStore(out_diffuse_accum, pix, vec4(diffuse, 0.));
imageStore(out_specular_accum, pix, vec4(specular, 0.));
imageStore(out_gi_sh1_accum, pix, vec4(0.));
imageStore(out_gi_sh2_accum, pix, vec4(0.));
//imageStore(out_gi_sh1_accum, pix, vec4(0.));
//imageStore(out_gi_sh2_accum, pix, vec4(0.));


//vec3 irradiance1 =
Expand Down Expand Up @@ -136,7 +138,7 @@ void main() {

imageStore(out_diffuse_accum, pix, vec4(diffuse, 0.));
imageStore(out_specular_accum, pix, vec4(reflection, 0.));

*/
vec4 gi_sh1_sum = vec4(0.);
vec2 gi_sh2_sum = vec2(0.);

Expand All @@ -151,11 +153,12 @@ void main() {
continue;

// global illumination
vec3 global_illumination = FIX_NAN(imageLoad(light_poly_gi, pix_gi)).rgb +
FIX_NAN(imageLoad(light_point_gi, pix_gi)).rgb +
FIX_NAN(imageLoad(gi_emissive, pix_gi)).rgb * 100.0f;
vec3 global_illumination = (FIX_NAN(imageLoad(light_poly_gi, pix_gi)).rgb +
FIX_NAN(imageLoad(light_point_diffuse_gi, pix_gi)).rgb +
FIX_NAN(imageLoad(light_point_specular_gi, pix_gi)).rgb +
FIX_NAN(imageLoad(gi_emissive, pix_gi)).rgb) * 100.0f;

global_illumination = vec3(1.);
//global_illumination = vec3(1.);

//global_illumination *= gi_troughput;
//global_illumination *= float(GI_DOWNSAMPLE * GI_DOWNSAMPLE) * 10.;
Expand Down Expand Up @@ -194,7 +197,7 @@ void main() {
imageStore(out_gi_sh2_accum, pix_gi, vec4(gi_sh2_sum, 0., 0.));
}
}
// imageStore(out_gi_sh1_accum, pix * GI_DOWNSAMPLE, gi_sh1_sum);
// imageStore(out_gi_sh2_accum, pix * GI_DOWNSAMPLE, vec4(gi_sh2_sum, 0., 0.));
}*/
imageStore(out_gi_sh1_accum, pix * GI_DOWNSAMPLE, gi_sh1_sum);
imageStore(out_gi_sh2_accum, pix * GI_DOWNSAMPLE, vec4(gi_sh2_sum, 0., 0.));
}
}
54 changes: 54 additions & 0 deletions ref/vk/shaders/lk_dnsr_lighting_mix_diffuse.comp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#version 460

#include "noise.glsl"
#include "utils.glsl"
#include "brdf.h"
#include "lk_dnsr_config.glsl"
#include "lk_dnsr_spherical_harmonics.glsl"
#include "lk_dnsr_utils.glsl"
#include "color_spaces.glsl"

#define GI_LIMIT_LUMINANCE 0.2

layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;

layout(set = 0, binding = 0, rgba16f) uniform image2D out_specular_accum;
layout(set = 0, binding = 1, rgba16f) uniform image2D out_diffuse_accum;
layout(set = 0, binding = 2, rgba16f) uniform image2D out_gi_sh1_accum;
layout(set = 0, binding = 3, rgba16f) uniform image2D out_gi_sh2_accum;

layout(set = 0, binding = 4, rgba8) uniform readonly image2D base_color_a;
layout(set = 0, binding = 5, rgba8) uniform readonly image2D refl_base_color_a;

layout(set = 0, binding = 6, rgba16f) uniform readonly image2D light_poly_diffuse;

layout(set = 0, binding = 7, rgba16f) uniform readonly image2D light_point_diffuse;



vec3 samplePolyDirect(ivec2 pix, ivec2 res) {
if (any(lessThan(pix, ivec2(0))) && any(greaterThanEqual(pix, res))) return vec3(-100.);
return FIX_NAN(imageLoad(light_poly_diffuse, pix)).rgb;
}

vec3 samplePolyDirectOpposite(ivec2 pix1, ivec2 pix2, ivec2 res) {
const vec3 first = samplePolyDirect(pix1, res);
const vec3 second = samplePolyDirect(pix2, res);
if (first.x < 0.99) return second;
else if (first.x < 0.99) return first;
return (first + second) / 2.;
}

void main() {
ivec2 res = ivec2(imageSize(base_color_a));
ivec2 pix = ivec2(gl_GlobalInvocationID);

if (any(greaterThanEqual(pix, res))) {
return;
}

const vec3 diffuse = FIX_NAN(imageLoad(light_point_diffuse, pix)).rgb
+ FIX_NAN(imageLoad(light_poly_diffuse, pix)).rgb;

imageStore(out_diffuse_accum, pix, vec4(diffuse, 0.));
}
7 changes: 6 additions & 1 deletion ref/vk/shaders/lk_dnsr_lights_direct_w23.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,22 @@ void main() {

const vec3 throughput = vec3(1.);
vec3 diffuse = vec3(0.), specular = vec3(0.);
computeLighting(pos + geometry_normal * .001, shading_normal, throughput, -direction, material, diffuse, specular);
//computeLighting(pos + geometry_normal * .001, shading_normal, throughput, -direction, material, diffuse, specular);

#if LIGHT_POINT
#ifdef PRIMARY_VIEW
imageStore(out_light_point_diffuse, pix, vec4(diffuse, 0.f));
imageStore(out_light_point_specular, pix, vec4(specular, 0.f));
#else
#ifdef GI
imageStore(out_light_point_diffuse_gi, pix, vec4(diffuse, 0.f));
imageStore(out_light_point_specular_gi, pix, vec4(specular, 0.f));
#else
imageStore(out_light_point_diffuse_refl, pix, vec4(diffuse, 0.f));
imageStore(out_light_point_specular_refl, pix, vec4(specular, 0.f));
#endif
#endif
#endif

#if LIGHT_POLYGON
imageStore(out_light_poly_diffuse, pix, vec4(diffuse, 0.f));
Expand Down
16 changes: 8 additions & 8 deletions ref/vk/shaders/lk_dnsr_ray_gi_bounces.comp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ bool bool getHit(vec3 origin, vec3 direction, int mask, inout RayPayloadPrimary

bool getHit(vec3 origin, vec3 direction, int mask, inout RayPayloadPrimary payload) {

float L = 1000.;
float L = 100000.;

rayQueryEXT rq;
const uint flags = 0
Expand Down Expand Up @@ -238,7 +238,7 @@ void main() {
}
vec3 gi_direction = vec3(1.);
float adapt_weight = 1.;

/*
const float random_choose_pos = rand01();
if (dir_weights_sum > 0. && GI_DIR_ADAPTIVE_CANDIDATES > 1) {
float sample_rnd_start = 0.;
Expand All @@ -252,10 +252,10 @@ void main() {
adapt_weight = curr_weight;
}
}
} else {
} else {*/
gi_direction = dir_candidates[0];
adapt_weight = 1.0;
}
/*}*/

adapt_weight = 1.0f; // rag for remove fireflyes?

Expand All @@ -264,15 +264,15 @@ void main() {
const ivec2 out_pix = pix + (res / GI_DOWNSAMPLE) * ivec2(bounce / GI_DOWNSAMPLE, bounce % GI_DOWNSAMPLE);
if (any(greaterThanEqual(out_pix, res)))
continue;
/*

RayPayloadPrimary payload;
payload.hit_t = vec4(0.);
payload.base_color_a = vec4(0.);
payload.normals_gs = vec4(0.);
payload.material_rmxx = vec4(0.);
payload.emissive = vec4(0.);

bool isSky = getHit(gi_origin, normalize(gi_direction), GEOMETRY_BIT_OPAQUE, payload);
bool isSky = getHit(gi_origin, normalize(-gi_direction), GEOMETRY_BIT_OPAQUE, payload);

if (any(lessThan(gi_troughput, vec3(0.001)))) {
break;
Expand Down Expand Up @@ -308,9 +308,9 @@ void main() {
imageStore(out_gi_emissive, out_pix, vec4((payload.emissive.xyz * gi_troughput) / adapt_weight, 0.));
break;
}
}*/
}
imageStore(out_gi_troughput,out_pix, vec4(1., 1., 1., 0.));
imageStore(out_gi_emissive, out_pix, vec4(10., 0., 0., 1.));
//imageStore(out_gi_emissive, out_pix, vec4(10., 0., 0., 1.));
imageStore(out_gi_emissive, out_pix, vec4(10., 0., 0., 1.));

}
Expand Down
2 changes: 1 addition & 1 deletion ref/vk/shaders/lk_dnsr_ray_primary.comp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ vec3 PowRand( vec3 rand, vec3 axis, float fpow )

bool getHit(vec3 origin, vec3 direction, int mask, inout RayPayloadPrimary payload) {

float L = 1000.;
float L = 100000.;

rayQueryEXT rq;
const uint flags = 0
Expand Down
8 changes: 4 additions & 4 deletions ref/vk/shaders/lk_dnsr_skip_denoising.comp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ layout(set = 0, binding = 1, rgba16f) uniform writeonly image2D out_diffuse_deno
layout(set = 0, binding = 2, rgba16f) uniform writeonly image2D out_gi_sh1_denoised;
layout(set = 0, binding = 3, rgba16f) uniform writeonly image2D out_gi_sh2_denoised;

layout(set = 0, binding = 4, rgba16f) uniform readonly image2D specular_accum;
layout(set = 0, binding = 5, rgba16f) uniform readonly image2D diffuse_accum;
layout(set = 0, binding = 4, rgba16f) uniform readonly image2D specular_pre_blured;
layout(set = 0, binding = 5, rgba16f) uniform readonly image2D diffuse_pre_blured;
layout(set = 0, binding = 6, rgba16f) uniform readonly image2D gi_sh1_accum;
layout(set = 0, binding = 7, rgba16f) uniform readonly image2D gi_sh2_accum;

Expand All @@ -35,8 +35,8 @@ void main() {
// imageStore(out_gi_sh2_denoised, pix, vec4(0.));


imageStore(out_specular_denoised, pix, imageLoad(specular_accum, pix));
imageStore(out_diffuse_denoised, pix, imageLoad(diffuse_accum, pix));
imageStore(out_specular_denoised, pix, imageLoad(specular_pre_blured, pix));
imageStore(out_diffuse_denoised, pix, imageLoad(diffuse_pre_blured, pix));
imageStore(out_gi_sh1_denoised, pix, imageLoad(gi_sh1_accum, pix));
imageStore(out_gi_sh2_denoised, pix, imageLoad(gi_sh2_accum, pix));
}
2 changes: 1 addition & 1 deletion ref/vk/shaders/lk_dnsr_specular_pre_blur_2.comp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define SVGF_STEP_SIZE 2
#define INPUT_IMAGE specular_pre_blur_1
#define OUTPUT_IMAGE out_specular_pre_blured
#define OUTPUT_IMAGE out_specular_pre_blur_2
//#define VARIANCE_IMAGE specular_variance

#define MAXIMAL_VARIANCE 1
Expand Down
11 changes: 11 additions & 0 deletions ref/vk/shaders/lk_dnsr_specular_pre_blur_3.comp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#version 460
#extension GL_GOOGLE_include_directive : require

#define SVGF_STEP_SIZE 4
#define INPUT_IMAGE specular_pre_blur_2
#define OUTPUT_IMAGE out_specular_pre_blured
//#define VARIANCE_IMAGE specular_variance

#define MAXIMAL_VARIANCE 1

#include "lk_dnsr_svgf_kernel.glsl"
Loading

0 comments on commit 77dc69e

Please sign in to comment.