Accumulate filter sums using doubles to avoid unsymmetries. Fixes issue 167.

This commit is contained in:
castano 2011-09-14 17:51:09 +00:00
parent 02709e1699
commit b68d428492
3 changed files with 11 additions and 6 deletions

View File

@ -112,22 +112,25 @@ float Filter::sampleDelta(float x, float scale) const
float Filter::sampleBox(float x, float scale, int samples) const float Filter::sampleBox(float x, float scale, int samples) const
{ {
float sum = 0; double sum = 0;
float isamples = 1.0f / float(samples); float isamples = 1.0f / float(samples);
for(int s = 0; s < samples; s++) for(int s = 0; s < samples; s++)
{ {
float p = (x + (float(s) + 0.5f) * isamples) * scale; float p = (x + (float(s) + 0.5f) * isamples) * scale;
float value = evaluate(p); float value = evaluate(p);
//printf("%f: %.8f (%X)\n", p, value, *(uint32 *)&value);
sum += value; sum += value;
} }
return sum * isamples; return float(sum * isamples);
} }
float Filter::sampleTriangle(float x, float scale, int samples) const float Filter::sampleTriangle(float x, float scale, int samples) const
{ {
float sum = 0; double sum = 0;
float isamples = 1.0f / float(samples); float isamples = 1.0f / float(samples);
for(int s = 0; s < samples; s++) for(int s = 0; s < samples; s++)
@ -142,7 +145,7 @@ float Filter::sampleTriangle(float x, float scale, int samples) const
sum += value * weight; sum += value * weight;
} }
return 2 * sum * isamples; return float(2 * sum * isamples);
} }
@ -586,6 +589,8 @@ PolyphaseKernel::PolyphaseKernel(const Filter & f, uint srcLength, uint dstLengt
{ {
const float sample = f.sampleBox(left + j - center, scale, samples); const float sample = f.sampleBox(left + j - center, scale, samples);
//printf("%f %X\n", sample, *(uint32 *)&sample);
m_data[i * m_windowSize + j] = sample; m_data[i * m_windowSize + j] = sample;
total += sample; total += sample;
} }

View File

@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
#include "nvcore/Debug.h" #include "nvcore/Debug.h"
#include "nvcore/Library.h" //#include "nvcore/Library.h"
#include "CudaUtils.h" #include "CudaUtils.h"
#if defined HAVE_CUDA #if defined HAVE_CUDA

View File

@ -453,7 +453,7 @@ int main(int argc, char *argv[])
// Block compressed textures with mipmaps must be powers of two. // Block compressed textures with mipmaps must be powers of two.
if (!noMipmaps && format != nvtt::Format_RGB) if (!noMipmaps && format != nvtt::Format_RGB)
{ {
inputOptions.setRoundMode(nvtt::RoundMode_ToNearestPowerOfTwo); inputOptions.setRoundMode(nvtt::RoundMode_ToPreviousPowerOfTwo);
} }
if (normal) if (normal)