1#version 430
2//4*4 ray bundle
3#define group_size 8
4#define buffer_size 64
5
6layout(local_size_x = group_size, local_size_y = group_size) in;
7layout(rgba32f, binding = 0) uniform image2D before;
8layout(rgba32f, binding = 1) uniform image2D after;
9layout(rgba32f, binding = 2) uniform image2D DE_input;
10
11//bilateral blur...
12//4 pixel radius
13#define blur_R 1
14
15vec3 getpos(vec2 p, vec2 rr)
16{
17	return imageLoad(DE_input, ivec2(p*rr)).xyz;
18}
19
20#include<utility/camera.glsl>
21
22void main() {
23	ivec2 global_pos = ivec2(gl_GlobalInvocationID.xy);
24	ivec2 local_indx = ivec2(gl_LocalInvocationID.xy);
25
26	vec2 img_size = vec2(imageSize(before));
27
28	vec2 res_ratio = vec2(imageSize(DE_input))/img_size;
29
30	vec4 sum = vec4(0);
31	float norm = 0.;
32
33	ray rr = get_ray(vec2(global_pos)/img_size);
34	vec4 pos = vec4(rr.pos,0);
35	vec4 dir = vec4(rr.dir,0);
36	vec4 var = vec4(0);
37
38	vec3 cpos = getpos(global_pos, res_ratio);
39	float td = dot(dir.xyz, cpos - pos.xyz);//traveled distance
40	float DX = fovray*td;
41
42	for(int i = -blur_R; i <= blur_R; i++)
43	{
44		for(int j = -blur_R; j <= blur_R; j++)
45		{
46			vec3 dpos = (getpos(global_pos + vec2(i,j),res_ratio) - cpos)/td;
47			float weight = exp(- 1200.*dot(dpos,dpos));
48			sum += weight*imageLoad(before, ivec2(global_pos) + ivec2(i,j));
49			norm += weight;
50		}
51	}
52	sum /= norm;
53
54	imageStore(after, global_pos,  sum);
55}