From a76e89d0d7290ca955cf337330b6489ec798b701 Mon Sep 17 00:00:00 2001 From: castano Date: Thu, 13 Dec 2007 06:36:23 +0000 Subject: [PATCH] Fix more errors in the use of the color metric. Remove debug code from compress.cpp --- src/nvtt/squish/clusterfit.cpp | 5 +++-- src/nvtt/squish/clusterfit.h | 2 ++ src/nvtt/squish/fastclusterfit.cpp | 13 +++++++------ src/nvtt/squish/fastclusterfit.h | 2 ++ src/nvtt/squish/weightedclusterfit.cpp | 13 +++++++------ src/nvtt/squish/weightedclusterfit.h | 2 ++ src/nvtt/tools/compress.cpp | 10 +--------- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/nvtt/squish/clusterfit.cpp b/src/nvtt/squish/clusterfit.cpp index 3f4fad1..b77dac2 100644 --- a/src/nvtt/squish/clusterfit.cpp +++ b/src/nvtt/squish/clusterfit.cpp @@ -98,6 +98,7 @@ void ClusterFit::setMetric(float r, float g, float b) #else m_metric = Vec3(r, g, b); #endif + m_metricSqr = m_metric * m_metric; } float ClusterFit::bestError() const @@ -401,7 +402,7 @@ Vec4 ClusterFit::SolveLeastSquares( Vec4& start, Vec4& end ) const Vec4 e4 = MultiplyAdd( a*b*alphabeta_sum - e2, two, e3 ); // apply the metric to the error term - Vec4 e5 = e4*m_metric; + Vec4 e5 = e4*m_metricSqr; Vec4 error = e5.SplatX() + e5.SplatY() + e5.SplatZ(); // save the start and end @@ -473,7 +474,7 @@ float ClusterFit::SolveLeastSquares( Vec3& start, Vec3& end ) const + 2.0f*( a*b*alphabeta_sum - a*alphax_sum - b*betax_sum ); // apply the metric to the error term - float error = Dot( e1, m_metric ); + float error = Dot( e1, m_metricSqr ); //if (debug) printf(" - %f\n", error); diff --git a/src/nvtt/squish/clusterfit.h b/src/nvtt/squish/clusterfit.h index 8e8931b..e5da174 100644 --- a/src/nvtt/squish/clusterfit.h +++ b/src/nvtt/squish/clusterfit.h @@ -55,6 +55,7 @@ private: Vec4 m_unweighted[16]; Vec4 m_weights[16]; Vec4 m_metric; + Vec4 m_metricSqr; Vec4 m_alpha[16]; Vec4 m_beta[16]; Vec4 m_xxsum; @@ -66,6 +67,7 @@ private: Vec3 m_unweighted[16]; float m_weights[16]; Vec3 m_metric; + Vec3 m_metricSqr; float m_alpha[16]; float m_beta[16]; Vec3 m_xxsum; diff --git a/src/nvtt/squish/fastclusterfit.cpp b/src/nvtt/squish/fastclusterfit.cpp index c2e3103..f063ca8 100644 --- a/src/nvtt/squish/fastclusterfit.cpp +++ b/src/nvtt/squish/fastclusterfit.cpp @@ -184,16 +184,17 @@ void FastClusterFit::setMetric(float r, float g, float b) #else m_metric = Vec3(r, g, b); #endif + m_metricSqr = m_metric * m_metric; } float FastClusterFit::bestError() const { #if SQUISH_USE_SIMD - Vec4 x = m_xxsum * m_metric; + Vec4 x = m_xxsum * m_metricSqr; Vec4 error = m_besterror + x.SplatX() + x.SplatY() + x.SplatZ(); return error.GetVec3().X(); #else - return m_besterror + Dot(m_xxsum, m_metric); + return m_besterror + Dot(m_xxsum, m_metricSqr); #endif } @@ -252,7 +253,7 @@ void FastClusterFit::Compress3( void* block ) Vec4 e3 = MultiplyAdd( a*b*alphabeta_sum - e1, two, e2 ); // apply the metric to the error term - Vec4 e4 = e3 * m_metric; + Vec4 e4 = e3 * m_metricSqr; Vec4 error = e4.SplatX() + e4.SplatY() + e4.SplatZ(); // keep the solution if it wins @@ -369,7 +370,7 @@ void FastClusterFit::Compress4( void* block ) Vec4 e3 = MultiplyAdd( a*b*alphabeta_sum - e1, two, e2 ); // apply the metric to the error term - Vec4 e4 = e3 * m_metric; + Vec4 e4 = e3 * m_metricSqr; Vec4 error = e4.SplatX() + e4.SplatY() + e4.SplatZ(); // keep the solution if it wins @@ -489,7 +490,7 @@ void FastClusterFit::Compress3( void* block ) Vec3 e1 = a*a*alpha2_sum + b*b*beta2_sum + 2.0f*( a*b*alphabeta_sum - a*alphax_sum - b*betax_sum ); // apply the metric to the error term - float error = Dot( e1, m_metric ); + float error = Dot( e1, m_metricSqr ); // keep the solution if it wins if( error < besterror ) @@ -601,7 +602,7 @@ void FastClusterFit::Compress4( void* block ) Vec3 e1 = a*a*alpha2_sum + b*b*beta2_sum + 2.0f*( a*b*alphabeta_sum - a*alphax_sum - b*betax_sum ); // apply the metric to the error term - float error = Dot( e1, m_metric ); + float error = Dot( e1, m_metricSqr ); // keep the solution if it wins if( error < besterror ) diff --git a/src/nvtt/squish/fastclusterfit.h b/src/nvtt/squish/fastclusterfit.h index 19bf335..7c8c435 100644 --- a/src/nvtt/squish/fastclusterfit.h +++ b/src/nvtt/squish/fastclusterfit.h @@ -55,12 +55,14 @@ private: #if SQUISH_USE_SIMD Vec4 m_unweighted[16]; Vec4 m_metric; + Vec4 m_metricSqr; Vec4 m_xxsum; Vec4 m_xsum; Vec4 m_besterror; #else Vec3 m_unweighted[16]; Vec3 m_metric; + Vec3 m_metricSqr; Vec3 m_xxsum; Vec3 m_xsum; float m_besterror; diff --git a/src/nvtt/squish/weightedclusterfit.cpp b/src/nvtt/squish/weightedclusterfit.cpp index 3ad504e..563e329 100644 --- a/src/nvtt/squish/weightedclusterfit.cpp +++ b/src/nvtt/squish/weightedclusterfit.cpp @@ -107,16 +107,17 @@ void WeightedClusterFit::setMetric(float r, float g, float b) #else m_metric = Vec3(r, g, b); #endif + m_metricSqr = m_metric * m_metric; } float WeightedClusterFit::bestError() const { #if SQUISH_USE_SIMD - Vec4 x = m_xxsum * m_metric; + Vec4 x = m_xxsum * m_metricSqr; Vec4 error = m_besterror + x.SplatX() + x.SplatY() + x.SplatZ(); return error.GetVec3().X(); #else - return m_besterror + Dot(m_xxsum, m_metric); + return m_besterror + Dot(m_xxsum, m_metricSqr); #endif } @@ -183,7 +184,7 @@ void WeightedClusterFit::Compress3( void* block ) Vec4 e3 = MultiplyAdd( a*b*alphabeta_sum - e1, two, e2 ); // apply the metric to the error term - Vec4 e4 = e3 * m_metric; + Vec4 e4 = e3 * m_metricSqr; Vec4 error = e4.SplatX() + e4.SplatY() + e4.SplatZ(); // keep the solution if it wins @@ -298,7 +299,7 @@ void WeightedClusterFit::Compress4( void* block ) Vec4 e3 = MultiplyAdd( a*b*alphabeta_sum - e1, two, e2 ); // apply the metric to the error term - Vec4 e4 = e3 * m_metric; + Vec4 e4 = e3 * m_metricSqr; Vec4 error = e4.SplatX() + e4.SplatY() + e4.SplatZ(); // keep the solution if it wins @@ -408,7 +409,7 @@ void WeightedClusterFit::Compress3( void* block ) Vec3 e1 = a*a*alpha2_sum + b*b*beta2_sum + 2.0f*( a*b*alphabeta_sum - a*alphax_sum - b*betax_sum ); // apply the metric to the error term - float error = Dot( e1, m_metric ); + float error = Dot( e1, m_metricSqr ); // keep the solution if it wins if( error < besterror ) @@ -513,7 +514,7 @@ void WeightedClusterFit::Compress4( void* block ) Vec3 e1 = a*a*alpha2_sum + b*b*beta2_sum + 2.0f*( a*b*alphabeta_sum - a*alphax_sum - b*betax_sum ); // apply the metric to the error term - float error = Dot( e1, m_metric ); + float error = Dot( e1, m_metricSqr ); // keep the solution if it wins if( error < besterror ) diff --git a/src/nvtt/squish/weightedclusterfit.h b/src/nvtt/squish/weightedclusterfit.h index 32e6828..9aba189 100644 --- a/src/nvtt/squish/weightedclusterfit.h +++ b/src/nvtt/squish/weightedclusterfit.h @@ -55,6 +55,7 @@ private: #if SQUISH_USE_SIMD Vec4 m_weighted[16]; Vec4 m_metric; + Vec4 m_metricSqr; Vec4 m_xxsum; Vec4 m_xsum; Vec4 m_besterror; @@ -62,6 +63,7 @@ private: Vec3 m_weighted[16]; float m_weights[16]; Vec3 m_metric; + Vec3 m_metricSqr; Vec3 m_xxsum; Vec3 m_xsum; float m_wsum; diff --git a/src/nvtt/tools/compress.cpp b/src/nvtt/tools/compress.cpp index 597049b..e5659c8 100644 --- a/src/nvtt/tools/compress.cpp +++ b/src/nvtt/tools/compress.cpp @@ -386,15 +386,7 @@ int main(int argc, char *argv[]) //compressionOptions.setQuality(nvtt::Quality_Highest); } compressionOptions.enableHardwareCompression(!nocuda); - - if (normal) - { - compressionOptions.setColorWeights(4, 4, 2); - } - else - { - compressionOptions.setColorWeights(1, 1, 1); - } + compressionOptions.setColorWeights(1, 1, 1); if (externalCompressor != NULL) {