[Bf-blender-cvs] [2a1ad72d207] tmp-workbench-rewrite2: TaaSamples
Miguel Pozo
noreply at git.blender.org
Fri Oct 28 15:11:17 CEST 2022
Commit: 2a1ad72d207873215dfdf158497c111effd4ccc5
Author: Miguel Pozo
Date: Wed Oct 26 16:23:03 2022 +0200
Branches: tmp-workbench-rewrite2
https://developer.blender.org/rB2a1ad72d207873215dfdf158497c111effd4ccc5
TaaSamples
===================================================================
M source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc
===================================================================
diff --git a/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc b/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc
index d2ee8483c54..6a471765241 100644
--- a/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc
+++ b/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc
@@ -2,10 +2,81 @@
#include "workbench_private.hh"
+#include "BLI_jitter_2d.h"
#include "smaa_textures.h"
namespace blender::workbench {
+class TaaSamples {
+ void init_samples(blender::Array<float2> &samples, const int size)
+ {
+ samples = blender::Array<float2>(size);
+ BLI_jitter_init((float(*)[2])samples.begin(), size);
+
+ /* find closest element to center */
+ int closest_index = 0;
+ float closest_squared_distance = 1.0f;
+
+ for (int i : samples.index_range()) {
+ float2 sample = samples[i];
+ printf("%f : %f", sample.x, sample.y);
+ const float squared_dist = len_squared_v2(sample);
+ if (squared_dist < closest_squared_distance) {
+ closest_squared_distance = squared_dist;
+ closest_index = i;
+ }
+ }
+
+ float2 closest_sample = samples[closest_index];
+
+ for (float2 &sample : samples) {
+ /* move jitter samples so that closest sample is in center */
+ sample -= closest_sample;
+ /* Avoid samples outside range (wrap around). */
+ sample = {fmodf(sample.x + 0.5f, 1.0f), fmodf(sample.y + 0.5f, 1.0f)};
+ /* Recenter the distribution[-1..1]. */
+ sample = (sample * 2.0f) - 1.0f;
+ }
+
+ /* swap center sample to the start of the array */
+ if (closest_index != 0) {
+ swap_v2_v2(samples[0], samples[closest_index]);
+ }
+
+ /* Sort list based on farthest distance with previous. */
+ for (int i = 0; i < size - 2; i++) {
+ float squared_dist = 0.0;
+ int index = i;
+ for (int j = i + 1; j < size; j++) {
+ const float _squared_dist = len_squared_v2(samples[i] - samples[j]);
+ if (_squared_dist > squared_dist) {
+ squared_dist = _squared_dist;
+ index = j;
+ }
+ }
+ swap_v2_v2(samples[i + 1], samples[index]);
+ }
+ }
+
+ public:
+ blender::Array<float2> x5;
+ blender::Array<float2> x8;
+ blender::Array<float2> x11;
+ blender::Array<float2> x16;
+ blender::Array<float2> x32;
+
+ TaaSamples()
+ {
+ init_samples(x5, 5);
+ init_samples(x8, 8);
+ init_samples(x11, 11);
+ init_samples(x16, 16);
+ init_samples(x32, 32);
+ }
+};
+
+static TaaSamples TAA_SAMPLES = TaaSamples();
+
AntiAliasingPass::AntiAliasingPass()
{
smaa_edge_detect_sh = GPU_shader_create_from_info_name("workbench_smaa_stage_0");
More information about the Bf-blender-cvs
mailing list