-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.glsl
More file actions
149 lines (131 loc) · 3.71 KB
/
image.glsl
File metadata and controls
149 lines (131 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "common.glsl"
#iChannel0 "file://buffer_c_path_tracing.glsl"
#iChannel0::MinFilter "Nearest"
#iChannel0::MagFilter "Nearest"
#iChannel0::WrapMode "Repeat"
#iChannel1 "file://blue_noise.png"
#iChannel1::MinFilter "Nearest"
#iChannel1::MagFilter "Nearest"
#iChannel1::WrapMode "Repeat"
// ASC CDL color grading
// https://en.wikipedia.org/wiki/ASC_CDL
vec3 asc_cdl(vec3 col, vec3 slope, vec3 offset, vec3 power)
{
return pow(max(col, 0.) * slope + offset, power);
}
vec3 view_transform(vec3 col)
{
// avoid any negative values before using power functions
col = max(col, 0.);
if (IMAGE_APPLY_CDL)
{
col = asc_cdl(
col,
1.1 * vec3(1, .903, .94),
vec3(0, 0, .007),
1.05 * vec3(1, .95, 1)
);
}
if (IMAGE_USE_FLIM)
{
col = flim_transform(col, 0., true);
}
else
{
// OETF (Linear BT.709 I-D65 to sRGB 2.2)
col = pow(col, vec3(1. / 2.2));
col = clamp(col, 0., 1.);
}
return col;
}
void mainImage(out vec4 frag_col, in vec2 frag_coord)
{
ivec2 icoord = ivec2(frag_coord);
vec2 render_res = ceil(RES_FAC * iResolution.xy);
vec2 real_res_fac = render_res / iResolution.xy;
vec2 buf_coord = clamp(
real_res_fac * frag_coord,
vec2(.501),
render_res - .501
);
ivec2 buf_icoord = ivec2(buf_coord);
vec3 col;
if (IMAGE_DEBUG_DEPTH)
{
float depth = unpack_from_path_tracing_buffer_depth(texelFetch(
iChannel0,
buf_icoord,
0
));
col = vec3(1. / (depth + .0001));
}
else if (IMAGE_DEBUG_MOTION_VEC)
{
vec2 motion_vec = unpack_from_path_tracing_buffer_motion_vec(texelFetch(
iChannel0,
buf_icoord,
0
));
col = flim_rgb_sweep(get_angle(motion_vec) / TAU);
col *= .1 * length(motion_vec);
}
else if (IMAGE_DEBUG_BLEND_ITER)
{
vec4 data = texelFetch(iChannel0, buf_icoord, 0);
vec3 buf_col = unpack_from_path_tracing_buffer_col(data);
int blend_iter = unpack_from_path_tracing_buffer_blend_iter(data);
col = mix(
buf_col,
vec3(0, 0, 1),
remap_clamp(float(blend_iter), 1., 50., 0., .5)
);
}
else
{
// sample col with bilinear interpolation
ivec2 buf_icoord_bl = ivec2(floor(buf_coord - .499));
ivec2 buf_icoord_tr = buf_icoord_bl + 1;
ivec2 buf_icoord_br = buf_icoord_bl + ivec2(1, 0);
ivec2 buf_icoord_tl = buf_icoord_bl + ivec2(0, 1);
vec3 buf_col_bl = unpack_from_path_tracing_buffer_col(texelFetch(
iChannel0,
buf_icoord_bl,
0
));
vec3 buf_col_tr = unpack_from_path_tracing_buffer_col(texelFetch(
iChannel0,
buf_icoord_tr,
0
));
vec3 buf_col_br = unpack_from_path_tracing_buffer_col(texelFetch(
iChannel0,
buf_icoord_br,
0
));
vec3 buf_col_tl = unpack_from_path_tracing_buffer_col(texelFetch(
iChannel0,
buf_icoord_tl,
0
));
vec2 offs = clamp(buf_coord - (vec2(buf_icoord_bl) + .5), 0., 1.);
col = mix(
mix(buf_col_bl, buf_col_br, offs.x),
mix(buf_col_tl, buf_col_tr, offs.x),
offs.y
);
}
// view transform
col = view_transform(col);
// dither
if (IMAGE_DITHER)
{
float bn = texelFetch(
iChannel1,
icoord % textureSize(iChannel1, 0),
0
).x;
col = clamp(col + (2. * bn - .5) / 254., 0., 1.);
}
// output
frag_col = vec4(col, 1.);
}