-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFastBilateral.glsl
96 lines (78 loc) · 3.2 KB
/
FastBilateral.glsl
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
// MIT License
// Copyright (c) 2023 João Chrisóstomo
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//!HOOK CHROMA
//!BIND LUMA
//!BIND HOOKED
//!SAVE LUMA_LOWRES
//!WIDTH CHROMA.w
//!HEIGHT CHROMA.h
//!WHEN CHROMA.w LUMA.w <
//!DESC Fast Bilateral (Downscaling Luma)
vec4 hook() {
return LUMA_texOff(0.0);
}
//!PARAM distance_coeff
//!TYPE float
//!MINIMUM 0.0
2.0
//!PARAM intensity_coeff
//!TYPE float
//!MINIMUM 0.0
128.0
//!HOOK CHROMA
//!BIND LUMA
//!BIND LUMA_LOWRES
//!BIND HOOKED
//!WIDTH LUMA.w
//!HEIGHT LUMA.h
//!WHEN CHROMA.w LUMA.w <
//!OFFSET ALIGN
//!DESC Fast Bilateral (Upscaling Chroma)
float comp_w(vec2 spatial_distance, float intensity_distance) {
return max(100.0 * exp(-distance_coeff * pow(length(spatial_distance), 2.0) - intensity_coeff * pow(intensity_distance, 2.0)), 1e-32);
}
vec4 hook() {
float luma_zero = LUMA_texOff(0.0).x;
vec4 output_pix = vec4(0.0, 0.0, 0.0, 1.0);
vec2 pp = HOOKED_pos * HOOKED_size - vec2(0.5);
vec2 fp = floor(pp);
pp -= fp;
vec2 chroma_pixels[4];
chroma_pixels[0] = HOOKED_tex(vec2((fp + vec2( 0.5, 0.5)) * HOOKED_pt)).xy;
chroma_pixels[1] = HOOKED_tex(vec2((fp + vec2( 1.5, 0.5)) * HOOKED_pt)).xy;
chroma_pixels[2] = HOOKED_tex(vec2((fp + vec2( 0.5, 1.5)) * HOOKED_pt)).xy;
chroma_pixels[3] = HOOKED_tex(vec2((fp + vec2( 1.5, 1.5)) * HOOKED_pt)).xy;
float luma_pixels[4];
luma_pixels[0] = LUMA_LOWRES_tex(vec2((fp + vec2( 0.5, 0.5)) * HOOKED_pt)).x;
luma_pixels[1] = LUMA_LOWRES_tex(vec2((fp + vec2( 1.5, 0.5)) * HOOKED_pt)).x;
luma_pixels[2] = LUMA_LOWRES_tex(vec2((fp + vec2( 0.5, 1.5)) * HOOKED_pt)).x;
luma_pixels[3] = LUMA_LOWRES_tex(vec2((fp + vec2( 1.5, 1.5)) * HOOKED_pt)).x;
float w[4];
w[0] = comp_w(vec2( 0.0, 0.0) - pp, luma_zero - luma_pixels[0] );
w[1] = comp_w(vec2( 1.0, 0.0) - pp, luma_zero - luma_pixels[1] );
w[2] = comp_w(vec2( 0.0, 1.0) - pp, luma_zero - luma_pixels[2] );
w[3] = comp_w(vec2( 1.0, 1.0) - pp, luma_zero - luma_pixels[3] );
float wt = 0.0;
vec2 ct = vec2(0.0);
for (int i = 0; i < 4; i++) {
wt += w[i];
ct += w[i] * chroma_pixels[i];
}
output_pix.xy = clamp(ct / wt, 0.0, 1.0);
return output_pix;
}