Commit: 3ec81b814c995b585f19c97cf87fee5b7195382b
Author: Sergey Sharybin
Date:   Thu Aug 27 18:50:40 2015 +0200
Branches: master
https://developer.blender.org/rB3ec81b814c995b585f19c97cf87fee5b7195382b

Fix T45617: Map UV node produces image artifacts

Basically filtering was happening twice, first time by applying weights of EWA
filter itself and then by applying subpixel offset while reading pixel values.

===================================================================

M       source/blender/compositor/intern/COM_MemoryBuffer.cpp
M       source/blender/compositor/intern/COM_MemoryBuffer.h
M       source/blender/compositor/intern/COM_SocketReader.h
M       source/blender/compositor/operations/COM_DisplaceOperation.cpp
M       source/blender/compositor/operations/COM_MapUVOperation.cpp
M       source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp
M       source/blender/compositor/operations/COM_ReadBufferOperation.cpp
M       source/blender/compositor/operations/COM_ReadBufferOperation.h

===================================================================

diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cpp 
b/source/blender/compositor/intern/COM_MemoryBuffer.cpp
index 2dbf0a6..162e08a 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.cpp
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.cpp
@@ -195,45 +195,15 @@ void MemoryBuffer::addPixel(int x, int y, const float 
color[4])
        }
 }
 
-typedef struct ReadEWAData {
-       MemoryBuffer *buffer;
-       PixelSampler sampler;
-       float ufac, vfac;
-} ReadEWAData;
-
 static void read_ewa_pixel_sampled(void *userdata, int x, int y, float 
result[4])
 {
-       ReadEWAData *data = (ReadEWAData *) userdata;
-       switch (data->sampler) {
-               case COM_PS_NEAREST:
-                       data->buffer->read(result, x, y);
-                       break;
-               case COM_PS_BILINEAR:
-                       data->buffer->readBilinear(result,
-                                                  (float)x + data->ufac,
-                                                  (float)y + data->vfac);
-                       break;
-               case COM_PS_BICUBIC:
-                       /* TOOD(sergey): no readBicubic method yet */
-                       data->buffer->readBilinear(result,
-                                                  (float)x + data->ufac,
-                                                  (float)y + data->vfac);
-                       break;
-               default:
-                       zero_v4(result);
-                       break;
-       }
+       MemoryBuffer *buffer = (MemoryBuffer *) userdata;
+       buffer->read(result, x, y);
 }
 
-void MemoryBuffer::readEWA(float *result, const float uv[2], const float 
derivatives[2][2], PixelSampler sampler)
+void MemoryBuffer::readEWA(float *result, const float uv[2], const float 
derivatives[2][2])
 {
        BLI_assert(this->m_datatype == COM_DT_COLOR);
-       ReadEWAData data;
-       data.buffer = this;
-       data.sampler = sampler;
-       data.ufac = uv[0] - floorf(uv[0]);
-       data.vfac = uv[1] - floorf(uv[1]);
-
        int width = this->getWidth(), height = this->getHeight();
        /* TODO(sergey): Render pipeline uses normalized coordinates and 
derivatives,
         * but compositor uses pixel space. For now let's just divide the 
values and
@@ -248,6 +218,6 @@ void MemoryBuffer::readEWA(float *result, const float 
uv[2], const float derivat
                       true,
                       uv_normal, du_normal, dv_normal,
                       read_ewa_pixel_sampled,
-                      &data,
+                      this,
                       result);
 }
diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.h 
b/source/blender/compositor/intern/COM_MemoryBuffer.h
index 0b5fc21..de8c14e 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.h
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.h
@@ -262,7 +262,7 @@ public:
                BLI_bilinear_interpolation_fl(this->m_buffer, result, 
this->m_width, this->m_height, this->m_num_channels, u, v);
        }
 
-       void readEWA(float *result, const float uv[2], const float 
derivatives[2][2], PixelSampler sampler);
+       void readEWA(float *result, const float uv[2], const float 
derivatives[2][2]);
        
        /**
         * @brief is this MemoryBuffer a temporarily buffer (based on an area, 
not on a chunk)
diff --git a/source/blender/compositor/intern/COM_SocketReader.h 
b/source/blender/compositor/intern/COM_SocketReader.h
index 7ba208e..ab8a3c0 100644
--- a/source/blender/compositor/intern/COM_SocketReader.h
+++ b/source/blender/compositor/intern/COM_SocketReader.h
@@ -93,8 +93,7 @@ protected:
         */
        virtual void executePixelFiltered(float /*output*/[4],
                                          float /*x*/, float /*y*/,
-                                         float /*dx*/[2], float /*dy*/[2],
-                                         PixelSampler /*sampler*/) {}
+                                         float /*dx*/[2], float /*dy*/[2]) {}
 
 public:
        inline void readSampled(float result[4], float x, float y, PixelSampler 
sampler) {
@@ -103,8 +102,8 @@ public:
        inline void read(float result[4], int x, int y, void *chunkData) {
                executePixel(result, x, y, chunkData);
        }
-       inline void readFiltered(float result[4], float x, float y, float 
dx[2], float dy[2], PixelSampler sampler) {
-               executePixelFiltered(result, x, y, dx, dy, sampler);
+       inline void readFiltered(float result[4], float x, float y, float 
dx[2], float dy[2]) {
+               executePixelFiltered(result, x, y, dx, dy);
        }
 
        virtual void *initializeTileData(rcti * /*rect*/) { return 0; }
diff --git a/source/blender/compositor/operations/COM_DisplaceOperation.cpp 
b/source/blender/compositor/operations/COM_DisplaceOperation.cpp
index 6dfef8a..9b3377e 100644
--- a/source/blender/compositor/operations/COM_DisplaceOperation.cpp
+++ b/source/blender/compositor/operations/COM_DisplaceOperation.cpp
@@ -60,7 +60,7 @@ void DisplaceOperation::executePixelSampled(float output[4], 
float x, float y, P
        }
        else {
                /* EWA filtering (without nearest it gets blurry with NO 
distortion) */
-               this->m_inputColorProgram->readFiltered(output, uv[0], uv[1], 
deriv[0], deriv[1], COM_PS_BILINEAR);
+               this->m_inputColorProgram->readFiltered(output, uv[0], uv[1], 
deriv[0], deriv[1]);
        }
 }
 
diff --git a/source/blender/compositor/operations/COM_MapUVOperation.cpp 
b/source/blender/compositor/operations/COM_MapUVOperation.cpp
index ffa48ce..d091675 100644
--- a/source/blender/compositor/operations/COM_MapUVOperation.cpp
+++ b/source/blender/compositor/operations/COM_MapUVOperation.cpp
@@ -53,7 +53,7 @@ void MapUVOperation::executePixelSampled(float output[4], 
float x, float y, Pixe
        }
 
        /* EWA filtering */
-       this->m_inputColorProgram->readFiltered(output, uv[0], uv[1], deriv[0], 
deriv[1], COM_PS_BILINEAR);
+       this->m_inputColorProgram->readFiltered(output, uv[0], uv[1], deriv[0], 
deriv[1]);
        
        /* UV to alpha threshold */
        const float threshold = this->m_alpha * 0.05f;
diff --git 
a/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp 
b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp
index d7d1c9c..1145abd 100644
--- a/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp
+++ b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp
@@ -108,8 +108,7 @@ void 
PlaneDistortWarpImageOperation::executePixelSampled(float output[4], float
                warpCoord(x, y, this->m_samples[0].perspectiveMatrix, uv, 
deriv);
                m_pixelReader->readFiltered(output,
                                            uv[0], uv[1],
-                                           deriv[0], deriv[1],
-                                           COM_PS_BILINEAR);
+                                           deriv[0], deriv[1]);
        }
        else {
                zero_v4(output);
@@ -118,8 +117,7 @@ void 
PlaneDistortWarpImageOperation::executePixelSampled(float output[4], float
                        warpCoord(x, y, 
this->m_samples[sample].perspectiveMatrix, uv, deriv);
                        m_pixelReader->readFiltered(color,
                                                    uv[0], uv[1],
-                                                   deriv[0], deriv[1],
-                                                   COM_PS_BILINEAR);
+                                                   deriv[0], deriv[1]);
                        add_v4_v4(output, color);
                }
                mul_v4_fl(output, 1.0f / (float)this->m_motion_blur_samples);
diff --git a/source/blender/compositor/operations/COM_ReadBufferOperation.cpp 
b/source/blender/compositor/operations/COM_ReadBufferOperation.cpp
index bf0f24e..6dbe132 100644
--- a/source/blender/compositor/operations/COM_ReadBufferOperation.cpp
+++ b/source/blender/compositor/operations/COM_ReadBufferOperation.cpp
@@ -89,7 +89,7 @@ void ReadBufferOperation::executePixelExtend(float output[4], 
float x, float y,
        }
 }
 
-void ReadBufferOperation::executePixelFiltered(float output[4], float x, float 
y, float dx[2], float dy[2], PixelSampler sampler)
+void ReadBufferOperation::executePixelFiltered(float output[4], float x, float 
y, float dx[2], float dy[2])
 {
        if (m_single_value) {
                /* write buffer has a single value stored at (0,0) */
@@ -98,7 +98,7 @@ void ReadBufferOperation::executePixelFiltered(float 
output[4], float x, float y
        else {
                const float uv[2] = { x, y };
                const float deriv[2][2] = { {dx[0], dx[1]}, {dy[0], dy[1]} };
-               m_buffer->readEWA(output, uv, deriv, sampler);
+               m_buffer->readEWA(output, uv, deriv);
        }
 }
 
diff --git a/source/blender/compositor/operations/COM_ReadBufferOperation.h 
b/source/blender/compositor/operations/COM_ReadBufferOperation.h
index 7e5bc55..cd706ed 100644
--- a/source/blender/compositor/operations/COM_ReadBufferOperation.h
+++ b/source/blender/compositor/operations/COM_ReadBufferOperation.h
@@ -43,7 +43,7 @@ public:
        void executePixelSampled(float output[4], float x, float y, 
PixelSampler sampler);
        void executePixelExtend(float output[4], float x, float y, PixelSampler 
sampler,
                                MemoryBufferExtend extend_x, MemoryBufferExtend 
extend_y);
-       void executePixelFiltered(float output[4], float x, float y, float 
dx[2], float dy[2], PixelSampler sampler);
+       void executePixelFiltered(float output[4], float x, float y, float 
dx[2], float dy[2]);
        const bool isReadBufferOperation() const { return true; }
        void setOffset(unsigned int offset) { this->m_offset = offset; }
        unsigned int getOffset() const { return this->m_offset; }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to