Differential D17094 Diff 60012 source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||
| #include "workbench_private.hh" | #include "workbench_private.hh" | ||||
| #include "BLI_jitter_2d.h" | #include "BLI_jitter_2d.h" | ||||
| #include "smaa_textures.h" | #include "smaa_textures.h" | ||||
| namespace blender::workbench { | namespace blender::workbench { | ||||
| class TaaSamples { | class TaaSamples { | ||||
| void init_samples(Array<float2> &samples, const int size) | void init_samples(MutableSpan<float2> samples) | ||||
| { | { | ||||
| samples = Array<float2>(size); | BLI_jitter_init(reinterpret_cast<float(*)[2]>(samples.data()), samples.size()); | ||||
| BLI_jitter_init((float(*)[2])samples.begin(), size); | |||||
| /* Find closest element to center */ | /* Find closest element to center */ | ||||
| int closest_index = 0; | int closest_index = 0; | ||||
| float closest_squared_distance = 1.0f; | float closest_squared_distance = 1.0f; | ||||
| for (int i : samples.index_range()) { | for (int i : samples.index_range()) { | ||||
| float2 sample = samples[i]; | const float2 sample = samples[i]; | ||||
| const float squared_dist = len_squared_v2(sample); | const float squared_dist = math::length_squared(sample); | ||||
| if (squared_dist < closest_squared_distance) { | if (squared_dist < closest_squared_distance) { | ||||
| closest_squared_distance = squared_dist; | closest_squared_distance = squared_dist; | ||||
| closest_index = i; | closest_index = i; | ||||
| } | } | ||||
| } | } | ||||
| float2 closest_sample = samples[closest_index]; | const float2 closest_sample = samples[closest_index]; | ||||
| for (float2 &sample : samples) { | for (float2 &sample : samples) { | ||||
| /* Move jitter samples so that closest sample is in center */ | /* Move jitter samples so that closest sample is in center */ | ||||
| sample -= closest_sample; | sample -= closest_sample; | ||||
| /* Avoid samples outside range (wrap around). */ | /* Avoid samples outside range (wrap around). */ | ||||
| sample = {fmodf(sample.x + 0.5f, 1.0f), fmodf(sample.y + 0.5f, 1.0f)}; | sample = {fmodf(sample.x + 0.5f, 1.0f), fmodf(sample.y + 0.5f, 1.0f)}; | ||||
| /* Recenter the distribution[-1..1]. */ | /* Recenter the distribution[-1..1]. */ | ||||
| sample = (sample * 2.0f) - 1.0f; | sample = (sample * 2.0f) - 1.0f; | ||||
| } | } | ||||
| /* Swap center sample to the start of the array */ | /* Swap center sample to the start of the array */ | ||||
| if (closest_index != 0) { | if (closest_index != 0) { | ||||
| std::swap(samples[0], samples[closest_index]); | std::swap(samples[0], samples[closest_index]); | ||||
| } | } | ||||
| /* Sort list based on farthest distance with previous. */ | /* Sort list based on farthest distance with previous. */ | ||||
| for (int i = 0; i < size - 2; i++) { | for (int i = 0; i < samples.size() - 2; i++) { | ||||
| float squared_dist = 0.0; | float squared_dist = 0.0; | ||||
| int index = i; | int index = i; | ||||
| for (int j = i + 1; j < size; j++) { | for (int j = i + 1; j < samples.size(); j++) { | ||||
| const float _squared_dist = len_squared_v2(samples[i] - samples[j]); | const float _squared_dist = math::length_squared(samples[i] - samples[j]); | ||||
JacquesLucke: This looks wrong. | |||||
Not Done Inline ActionsYes, this should be drop_front(i + 1). Personally, I find this option less readable. If anything I would change it for: The same for the outer loop. pragma37: Yes, this should be `drop_front(i + 1)`.
Personally, I find this option less readable. If… | |||||
| if (_squared_dist > squared_dist) { | if (_squared_dist > squared_dist) { | ||||
| squared_dist = _squared_dist; | squared_dist = _squared_dist; | ||||
| index = j; | index = j; | ||||
| } | } | ||||
| } | } | ||||
| std::swap(samples[i + 1], samples[index]); | std::swap(samples[i + 1], samples[index]); | ||||
| } | } | ||||
| } | } | ||||
| public: | public: | ||||
| Array<float2> x5; | std::array<float2, 5> x5; | ||||
| Array<float2> x8; | std::array<float2, 8> x8; | ||||
| Array<float2> x11; | std::array<float2, 11> x11; | ||||
| Array<float2> x16; | std::array<float2, 16> x16; | ||||
| Array<float2> x32; | std::array<float2, 32> x32; | ||||
| TaaSamples() | TaaSamples() | ||||
| { | { | ||||
| init_samples(x5, 5); | init_samples(x5); | ||||
| init_samples(x8, 8); | init_samples(x8); | ||||
| init_samples(x11, 11); | init_samples(x11); | ||||
| init_samples(x16, 16); | init_samples(x16); | ||||
| init_samples(x32, 32); | init_samples(x32); | ||||
| } | } | ||||
| }; | }; | ||||
| static const TaaSamples &get_taa_samples() | static const TaaSamples &get_taa_samples() | ||||
| { | { | ||||
| static const TaaSamples taa_samples; | static const TaaSamples taa_samples; | ||||
| return taa_samples; | return taa_samples; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 236 Lines • Show Last 20 Lines | |||||
This looks wrong.