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
|
/**
* Accumulate input texture into the film accumulation buffer.
*
* All samples inside the filter radius are projected to the input texture.
* The nearest input sample is then projected back to the destination texture space
* to get an accurate filter weight.
*
* If using nearest filtering (for non-color data) only the closest sample is considered
* and the weight is use as a distance metric.
**/
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_film_lib.glsl)
/* clang-format off */
const vec2 sample_offsets_plus[5] = vec2[5](vec2(0, 1), vec2(-1, 0), vec2(0, 0), vec2(1, 0), vec2(0, -1));
const vec2 sample_offsets_3x3[9] = vec2[9](vec2(-1, 1), vec2(0, 1), vec2(1, 1), vec2(-1, 0), vec2(0, 0), vec2(1, 0), vec2(-1, -1), vec2(0, -1), vec2(1, -1));
/* clang-format on */
void main(void)
{
out_data = vec4(0.0);
out_weight = 0.0;
/* TODO(fclem) Split into multiple shaders? Measure benefits. */
if (camera.filter_size < 1.0 || !film_is_color_data(film)) {
film_process_sample(camera,
film,
ProjectionMatrix,
ProjectionMatrixInverse,
input_tx,
vec2(0.0),
out_data,
out_weight);
}
else if (camera.filter_size < M_SQRT2) {
for (int i = 0; i < 5; i++) {
film_process_sample(camera,
film,
ProjectionMatrix,
ProjectionMatrixInverse,
input_tx,
sample_offsets_plus[i],
out_data,
out_weight);
}
}
else if (camera.filter_size < 2.0) {
for (int i = 0; i < 9; i++) {
film_process_sample(camera,
film,
ProjectionMatrix,
ProjectionMatrixInverse,
input_tx,
sample_offsets_3x3[i],
out_data,
out_weight);
}
}
else {
/* This is slow but using large filter is not very common. */
float extent = floor(camera.filter_size);
for (float x = -extent; x < extent; x++) {
for (float y = -extent; y < extent; y++) {
film_process_sample(camera,
film,
ProjectionMatrix,
ProjectionMatrixInverse,
input_tx,
vec2(x, y),
out_data,
out_weight);
}
}
}
if (film.use_history) {
vec2 uv_history = film_uv_history_get(camera, camera, uvcoordsvar.xy);
vec4 history_data = textureLod(data_tx, uv_history, 0.0);
float history_weight = textureLod(weight_tx, uv_history, 0.0).r;
if (film_is_color_data(film)) {
out_data += history_data;
out_weight += history_weight;
}
else {
/* Non-color data do not accumulates. It is replaced by nearest value. */
if (history_weight > out_weight) {
out_weight = history_weight;
out_data = history_data;
}
}
}
}
|