| 1 |
#[compute] |
| 2 |
|
| 3 |
#version 450 |
| 4 |
|
| 5 |
#VERSION_DEFINES |
| 6 |
|
| 7 |
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; |
| 8 |
|
| 9 |
layout(set = 0, binding = 0) uniform sampler2D source_depth; |
| 10 |
layout(set = 0, binding = 1) uniform sampler2D source_normal_roughness; |
| 11 |
layout(r32f, set = 0, binding = 2) uniform restrict writeonly image2D dest_depth; |
| 12 |
layout(rgba8, set = 0, binding = 3) uniform restrict writeonly image2D dest_normal_roughness; |
| 13 |
|
| 14 |
layout(push_constant, std430) uniform Params { |
| 15 |
ivec2 screen_size; |
| 16 |
} |
| 17 |
params; |
| 18 |
|
| 19 |
void get_sample(ivec2 sample_pos, inout float depth, inout ivec2 winner_sample_pos) { |
| 20 |
float sample_depth = texelFetch(source_depth, sample_pos, 0).x; |
| 21 |
|
| 22 |
if (depth < sample_depth) { |
| 23 |
depth = sample_depth; |
| 24 |
winner_sample_pos = sample_pos; |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
void main() { |
| 29 |
ivec2 pixel_pos = ivec2(gl_GlobalInvocationID.xy); |
| 30 |
|
| 31 |
if (any(greaterThanEqual(pixel_pos, params.screen_size))) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
ivec2 sample_pos = pixel_pos * 2 + ivec2(0, 0); |
| 36 |
float depth = texelFetch(source_depth, sample_pos, 0).x; |
| 37 |
|
| 38 |
get_sample(pixel_pos * 2 + ivec2(1, 0), depth, sample_pos); |
| 39 |
get_sample(pixel_pos * 2 + ivec2(0, 1), depth, sample_pos); |
| 40 |
get_sample(pixel_pos * 2 + ivec2(1, 1), depth, sample_pos); |
| 41 |
|
| 42 |
#ifdef MODE_ODD_WIDTH |
| 43 |
get_sample(pixel_pos * 2 + ivec2(2, 0), depth, sample_pos); |
| 44 |
get_sample(pixel_pos * 2 + ivec2(2, 1), depth, sample_pos); |
| 45 |
#endif |
| 46 |
|
| 47 |
#ifdef MODE_ODD_HEIGHT |
| 48 |
get_sample(pixel_pos * 2 + ivec2(0, 2), depth, sample_pos); |
| 49 |
get_sample(pixel_pos * 2 + ivec2(1, 2), depth, sample_pos); |
| 50 |
#endif |
| 51 |
|
| 52 |
#if defined(MODE_ODD_WIDTH) && defined(MODE_ODD_HEIGHT) |
| 53 |
get_sample(pixel_pos * 2 + ivec2(2, 2), depth, sample_pos); |
| 54 |
#endif |
| 55 |
|
| 56 |
imageStore(dest_depth, pixel_pos, vec4(depth, 0.0, 0.0, 0.0)); |
| 57 |
imageStore(dest_normal_roughness, pixel_pos, texelFetch(source_normal_roughness, sample_pos, 0)); |
| 58 |
} |