Commit: 0bc4bc2e616bc860634bb3b4a637c3400dc5c68f
Author: Sergey Sharybin
Date:   Thu Sep 3 17:14:35 2015 +0500
Branches: master
https://developer.blender.org/rB0bc4bc2e616bc860634bb3b4a637c3400dc5c68f

Fix T45946: Cycles texture interpolation bug

Coordinate clamping was done in the wrong order.

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

M       intern/cycles/kernel/kernel_compat_cpu.h

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

diff --git a/intern/cycles/kernel/kernel_compat_cpu.h 
b/intern/cycles/kernel/kernel_compat_cpu.h
index 951de88..ed145b4 100644
--- a/intern/cycles/kernel/kernel_compat_cpu.h
+++ b/intern/cycles/kernel/kernel_compat_cpu.h
@@ -173,16 +173,11 @@ template<typename T> struct texture_image  {
                                        }
                                        /* Fall through. */
                                case EXTENSION_EXTEND:
+                                       nix = wrap_clamp(ix+1, width);
+                                       niy = wrap_clamp(iy+1, height);
+
                                        ix = wrap_clamp(ix, width);
                                        iy = wrap_clamp(iy, height);
-
-                                       if (x >= 0.0f && y >= 0.0f && x <= 1.0f 
&& y <= 1.0f) {
-                                               nix = wrap_clamp(ix+1, width);
-                                               niy = wrap_clamp(iy+1, height);
-                                       }
-                                       else {
-                                               return read(data[ix + 
iy*width]);
-                                       }
                                        break;
                        }
 
@@ -195,8 +190,8 @@ template<typename T> struct texture_image  {
                }
                else {
                        /* Bicubic b-spline interpolation. */
-                       const float tx = frac(x*(float)width - 0.5f, &ix);
-                       const float ty = frac(y*(float)height - 0.5f, &iy);
+                       float tx = frac(x*(float)width - 0.5f, &ix);
+                       float ty = frac(y*(float)height - 0.5f, &iy);
                        int pix, piy, nnix, nniy;
                        switch(extension) {
                                case EXTENSION_REPEAT:
@@ -218,22 +213,17 @@ template<typename T> struct texture_image  {
                                        }
                                        /* Fall through. */
                                case EXTENSION_EXTEND:
-                                       ix = wrap_clamp(ix, width);
-                                       iy = wrap_clamp(iy, height);
+                                       pix = wrap_clamp(ix-1, width);
+                                       piy = wrap_clamp(iy-1, height);
 
-                                       if (x >= 0.0f && y >= 0.0f && x <= 1.0f 
&& y <= 1.0f) {
-                                               pix = wrap_clamp(ix-1, width);
-                                               piy = wrap_clamp(iy-1, height);
+                                       nix = wrap_clamp(ix+1, width);
+                                       niy = wrap_clamp(iy+1, height);
 
-                                               nix = wrap_clamp(ix+1, width);
-                                               niy = wrap_clamp(iy+1, height);
+                                       nnix = wrap_clamp(ix+2, width);
+                                       nniy = wrap_clamp(iy+2, height);
 
-                                               nnix = wrap_clamp(ix+2, width);
-                                               nniy = wrap_clamp(iy+2, height);
-                                       }
-                                       else {
-                                               return read(data[ix + 
iy*width]);
-                                       }
+                                       ix = wrap_clamp(ix, width);
+                                       iy = wrap_clamp(iy, height);
                                        break;
                        }
 
@@ -323,18 +313,13 @@ template<typename T> struct texture_image  {
                                        }
                                        /* Fall through. */
                                case EXTENSION_EXTEND:
+                                       nix = wrap_clamp(ix+1, width);
+                                       niy = wrap_clamp(iy+1, height);
+                                       niz = wrap_clamp(iz+1, depth);
+
                                        ix = wrap_clamp(ix, width);
                                        iy = wrap_clamp(iy, height);
                                        iz = wrap_clamp(iz, depth);
-
-                                       if (x >= 0.0f && y >= 0.0f && x <= 1.0f 
&& y <= 1.0f) {
-                                               nix = wrap_clamp(ix+1, width);
-                                               niy = wrap_clamp(iy+1, height);
-                                               niz = wrap_clamp(iz+1, depth);
-                                       }
-                                       else {
-                                               return read(data[ix + iy*width 
+ iz*width*height]);
-                                       }
                                        break;
                        }
 
@@ -383,26 +368,21 @@ template<typename T> struct texture_image  {
                                        }
                                        /* Fall through. */
                                case EXTENSION_EXTEND:
-                                       ix = wrap_clamp(ix, width);
-                                       iy = wrap_clamp(iy, height);
-                                       iz = wrap_clamp(iz, depth);
+                                       pix = wrap_clamp(ix-1, width);
+                                       piy = wrap_clamp(iy-1, height);
+                                       piz = wrap_clamp(iz-1, depth);
 
-                                       if (x >= 0.0f && y >= 0.0f && x <= 1.0f 
&& y <= 1.0f) {
-                                               pix = wrap_clamp(ix-1, width);
-                                               piy = wrap_clamp(iy-1, height);
-                                               piz = wrap_clamp(iz-1, depth);
+                                       nix = wrap_clamp(ix+1, width);
+                                       niy = wrap_clamp(iy+1, height);
+                                       niz = wrap_clamp(iz+1, depth);
 
-                                               nix = wrap_clamp(ix+1, width);
-                                               niy = wrap_clamp(iy+1, height);
-                                               niz = wrap_clamp(iz+1, depth);
+                                       nnix = wrap_clamp(ix+2, width);
+                                       nniy = wrap_clamp(iy+2, height);
+                                       nniz = wrap_clamp(iz+2, depth);
 
-                                               nnix = wrap_clamp(ix+2, width);
-                                               nniy = wrap_clamp(iy+2, height);
-                                               nniz = wrap_clamp(iz+2, depth);
-                                       }
-                                       else {
-                                               return read(data[ix + iy*width 
+ iz*width*height]);
-                                       }
+                                       ix = wrap_clamp(ix, width);
+                                       iy = wrap_clamp(iy, height);
+                                       iz = wrap_clamp(iz, depth);
                                        break;
                        }

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

Reply via email to