forked from FWGS/xash3d-fwgs
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vk: rt: add experimental second Á-Trous pass for indirect diffuse
Now indirect diffuse channel gets blurred with 2 Á-Trous passes. It mostly follows the paper, except for Σd_i, which gives very bad viusal artifacts.
- Loading branch information
Showing
5 changed files
with
162 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#ifndef ATROUS_CONSTS_DECLARED | ||
#define ATROUS_CONSTS_DECLARED | ||
|
||
#include "utils.glsl" | ||
|
||
// https://jo.dreggn.org/home/2010_atrous.pdf | ||
// https://www.shadertoy.com/view/ldKBzG | ||
#define ATROUS_KERNEL_WIDTH 5 | ||
#define ATROUS_KERNEL_HALF 2 | ||
const float kATrousKernel[ATROUS_KERNEL_WIDTH] = { 1./16., 1./4., 3./8., 1./4., 1./16. }; | ||
|
||
|
||
// Depends on: | ||
// - image2D normals_gs | ||
// - image2D position_t | ||
float aTrousSampleWeigth(const ivec2 res, const ivec2 pix, vec3 pos, vec3 shading_normal, ivec2 offset, int step_width, int pix_scale, float phi_normal, float phi_pos, out ivec2 p) { | ||
const float x_kernel = kATrousKernel[offset.x]; | ||
const float y_kernel = kATrousKernel[offset.y]; | ||
|
||
const float inv_step_width_sq = 1. / float(step_width * step_width); | ||
p = pix + (offset - ivec2(ATROUS_KERNEL_HALF)) * step_width; | ||
const ivec2 p_scaled = p * pix_scale; | ||
|
||
if (any(greaterThanEqual(p_scaled, res)) || any(lessThan(p_scaled, ivec2(0)))) { | ||
return 0.; | ||
} | ||
|
||
// Weight normals | ||
const vec4 ngs = imageLoad(normals_gs, p_scaled); | ||
const vec3 sample_shading_normal = normalDecode(ngs.zw); | ||
|
||
// TODO should we go geometry_normal too? | ||
const vec3 sn_diff = sample_shading_normal - shading_normal; | ||
const float sn_dist2 = max(dot(sn_diff,sn_diff) * inv_step_width_sq, 0.); | ||
const float weight_sn = min(exp(-(sn_dist2)/phi_normal), 1.0); | ||
|
||
// Weight positions | ||
const vec3 sample_position = imageLoad(position_t, p_scaled).xyz; | ||
const vec3 p_diff = sample_position - pos; | ||
//Original paper: const float p_dist2 = dot(p_diff, p_diff); | ||
const float p_dist2 = max(dot(p_diff,p_diff) * inv_step_width_sq, 0.); | ||
const float weight_pos = min(exp(-(p_dist2)/phi_pos),1.0); | ||
|
||
const float weight = (weight_pos * weight_sn) * x_kernel * y_kernel; | ||
return weight; | ||
} | ||
|
||
#endif // ifndef ATROUS_CONSTS_DECLARED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#version 460 | ||
//#include "debug.glsl" | ||
//#include "utils.glsl" | ||
|
||
#define GLSL | ||
#include "ray_interop.h" | ||
#undef GLSL | ||
|
||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; | ||
|
||
layout(set = 0, binding = 0) uniform UBO { UniformBuffer ubo; } ubo; | ||
|
||
layout(set = 0, binding = 1, rgba16f) uniform image2D out_indirect_diffuse_atrous1; | ||
|
||
layout(set = 0, binding = 2, rgba32f) uniform readonly image2D position_t; | ||
layout(set = 0, binding = 3, rgba16f) uniform readonly image2D normals_gs; | ||
|
||
layout(set = 0, binding = 4, rgba16f) uniform readonly image2D indirect_diffuse; | ||
|
||
#include "atrous.glsl" | ||
|
||
const int INDIRECT_SCALE = 2; | ||
|
||
void main() { | ||
const ivec2 res = ubo.ubo.res; | ||
const ivec2 pix = ivec2(gl_GlobalInvocationID); | ||
|
||
const ivec2 res_scaled = res / INDIRECT_SCALE; | ||
if (any(greaterThanEqual(pix, res_scaled))) { | ||
return; | ||
} | ||
|
||
const vec3 pos = imageLoad(position_t, pix * INDIRECT_SCALE).xyz; | ||
const vec3 shading_normal = normalDecode(imageLoad(normals_gs, pix * INDIRECT_SCALE).zw); | ||
|
||
vec3 indiff = vec3(0.); | ||
float weight_total_indirect_diffuse = 0.; | ||
for (int x = 0; x <= ATROUS_KERNEL_WIDTH; ++x) { | ||
for (int y = 0; y <= ATROUS_KERNEL_WIDTH; ++y) { | ||
const ivec2 offset = ivec2(x, y); | ||
|
||
// 3. Indirect diffuse | ||
{ | ||
const float sn_phi = .5; | ||
const float p_phi = 3.; | ||
const int step_width = 1; | ||
ivec2 p; | ||
const float weight = aTrousSampleWeigth( | ||
res, pix, pos, shading_normal, offset, step_width, INDIRECT_SCALE, sn_phi, p_phi, p); | ||
|
||
if (weight > 0.) { | ||
const bool do_indirect = all(lessThan(p, res_scaled)); | ||
if (do_indirect) { | ||
weight_total_indirect_diffuse += weight; | ||
indiff += imageLoad(indirect_diffuse, p).rgb * weight; | ||
} | ||
} | ||
} | ||
} // for y | ||
} // for x | ||
|
||
const float one_over_weight_indirect_diffuse = weight_total_indirect_diffuse == 0. ? 0 : 1. / weight_total_indirect_diffuse; | ||
indiff *= one_over_weight_indirect_diffuse; | ||
|
||
//indiff = imageLoad(indirect_diffuse, pix).rgb; | ||
|
||
imageStore(out_indirect_diffuse_atrous1, pix, vec4(indiff, 0./*unused*/)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters