From 9e2e9fba4c11f675d5b7251a33e8ba33ccbb1e53 Mon Sep 17 00:00:00 2001 From: drewcassidy Date: Sun, 21 Feb 2021 03:26:40 -0800 Subject: [PATCH] add some notes on how the covariance model works --- src/BC1/BC1Encoder.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/BC1/BC1Encoder.cpp b/src/BC1/BC1Encoder.cpp index c9803a3..c1566a8 100644 --- a/src/BC1/BC1Encoder.cpp +++ b/src/BC1/BC1Encoder.cpp @@ -317,7 +317,7 @@ void BC1Encoder::FindEndpoints(Color4x4 pixels, BC1Encoder::Flags flags, const B std::array colors; - Vector4 axis = {306, 601, 117}; // I think this is luma? + Vector4 axis = {306, 601, 117}; // Luma vector Matrix4x4 covariance; const unsigned total_power_iters = (flags & Flags::Use6PowerIters) != Flags::None ? 6 : 4; @@ -341,8 +341,10 @@ void BC1Encoder::FindEndpoints(Color4x4 pixels, BC1Encoder::Flags flags, const B if (covariance[0][2] < 0) delta[0] = -delta[0]; // r vs b if (covariance[1][2] < 0) delta[1] = -delta[1]; // g vs b + // using the covariance matrix, iteratively stretch the delta vector towards the primary axis of the data for (unsigned power_iter = 0; power_iter < total_power_iters; power_iter++) { delta = covariance * delta; } + // if we found any correlation, then this is our new axis. otherwise we fallback to the luma vector float k = delta.MaxAbs(3); if (k > 2) { axis = delta * (2048.0f / k); } @@ -352,6 +354,8 @@ void BC1Encoder::FindEndpoints(Color4x4 pixels, BC1Encoder::Flags flags, const B unsigned min_index, max_index; for (unsigned i = 0; i < 16; i++) { + // since axis is constant here, I dont think its magnitude actually matters, + // since we only care about the min or max dot product float dot = colors[i].Dot(axis); if (dot > max_dot) { max_dot = dot;