Commit: 4690281b17a9b302bd86484703b2389e371c8f07
Author: Sergey Sharybin
Date:   Tue Jul 28 14:36:08 2015 +0200
Branches: master
https://developer.blender.org/rB4690281b17a9b302bd86484703b2389e371c8f07

Cycles: Add implementation of clip extension mode

For now there's no OpenCL support, it'll come later.

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

M       intern/cycles/device/device_cuda.cpp
M       intern/cycles/kernel/kernel_compat_cpu.h
M       intern/cycles/render/nodes.cpp
M       intern/cycles/util/util_types.h

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

diff --git a/intern/cycles/device/device_cuda.cpp 
b/intern/cycles/device/device_cuda.cpp
index 9703b78..a47d4ed 100644
--- a/intern/cycles/device/device_cuda.cpp
+++ b/intern/cycles/device/device_cuda.cpp
@@ -513,13 +513,19 @@ public:
                                cuda_assert(cuTexRefSetFlags(texref, 
CU_TRSF_READ_AS_INTEGER));
                        }
 
-                       if(extension == EXTENSION_REPEAT) {
-                               cuda_assert(cuTexRefSetAddressMode(texref, 0, 
CU_TR_ADDRESS_MODE_WRAP));
-                               cuda_assert(cuTexRefSetAddressMode(texref, 1, 
CU_TR_ADDRESS_MODE_WRAP));
-                       }
-                       else {
-                               cuda_assert(cuTexRefSetAddressMode(texref, 0, 
CU_TR_ADDRESS_MODE_CLAMP));
-                               cuda_assert(cuTexRefSetAddressMode(texref, 1, 
CU_TR_ADDRESS_MODE_CLAMP));
+                       switch(extension) {
+                               case EXTENSION_REPEAT:
+                                       
cuda_assert(cuTexRefSetAddressMode(texref, 0, CU_TR_ADDRESS_MODE_WRAP));
+                                       
cuda_assert(cuTexRefSetAddressMode(texref, 1, CU_TR_ADDRESS_MODE_WRAP));
+                                       break;
+                               case EXTENSION_EXTEND:
+                                       
cuda_assert(cuTexRefSetAddressMode(texref, 0, CU_TR_ADDRESS_MODE_CLAMP));
+                                       
cuda_assert(cuTexRefSetAddressMode(texref, 1, CU_TR_ADDRESS_MODE_CLAMP));
+                                       break;
+                               case EXTENSION_CLIP:
+                                       
cuda_assert(cuTexRefSetAddressMode(texref, 0, CU_TR_ADDRESS_MODE_BORDER));
+                                       
cuda_assert(cuTexRefSetAddressMode(texref, 1, CU_TR_ADDRESS_MODE_BORDER));
+                                       break;
                        }
                        cuda_assert(cuTexRefSetFormat(texref, format, 
mem.data_elements));
 
diff --git a/intern/cycles/kernel/kernel_compat_cpu.h 
b/intern/cycles/kernel/kernel_compat_cpu.h
index be8e54b..37387d7 100644
--- a/intern/cycles/kernel/kernel_compat_cpu.h
+++ b/intern/cycles/kernel/kernel_compat_cpu.h
@@ -138,14 +138,20 @@ template<typename T> struct texture_image  {
                if(interpolation == INTERPOLATION_CLOSEST) {
                        frac(x*(float)width, &ix);
                        frac(y*(float)height, &iy);
-                       if(extension == EXTENSION_REPEAT) {
-                               ix = wrap_periodic(ix, width);
-                               iy = wrap_periodic(iy, height);
-
-                       }
-                       else {
-                               ix = wrap_clamp(ix, width);
-                               iy = wrap_clamp(iy, height);
+                       switch(extension) {
+                               case EXTENSION_REPEAT:
+                                       ix = wrap_periodic(ix, width);
+                                       iy = wrap_periodic(iy, height);
+                                       break;
+                               case EXTENSION_CLIP:
+                                       if (ix < 0 || iy < 0 || ix >= width || 
iy >= height) {
+                                               return make_float4(0.0f, 0.0f, 
0.0f, 0.0f);
+                                       }
+                                       /* Fall through. */
+                               case EXTENSION_EXTEND:
+                                       ix = wrap_clamp(ix, width);
+                                       iy = wrap_clamp(iy, height);
+                                       break;
                        }
                        return read(data[ix + iy*width]);
                }
@@ -153,19 +159,26 @@ template<typename T> struct texture_image  {
                        float tx = frac(x*(float)width - 0.5f, &ix);
                        float ty = frac(y*(float)height - 0.5f, &iy);
 
-                       if(extension == EXTENSION_REPEAT) {
-                               ix = wrap_periodic(ix, width);
-                               iy = wrap_periodic(iy, height);
-
-                               nix = wrap_periodic(ix+1, width);
-                               niy = wrap_periodic(iy+1, height);
-                       }
-                       else {
-                               ix = wrap_clamp(ix, width);
-                               iy = wrap_clamp(iy, height);
-
-                               nix = wrap_clamp(ix+1, width);
-                               niy = wrap_clamp(iy+1, height);
+                       switch(extension) {
+                               case EXTENSION_REPEAT:
+                                       ix = wrap_periodic(ix, width);
+                                       iy = wrap_periodic(iy, height);
+
+                                       nix = wrap_periodic(ix+1, width);
+                                       niy = wrap_periodic(iy+1, height);
+                                       break;
+                               case EXTENSION_CLIP:
+                                       if (ix < 0 || iy < 0 || ix >= width || 
iy >= height) {
+                                               return make_float4(0.0f, 0.0f, 
0.0f, 0.0f);
+                                       }
+                                       /* Fall through. */
+                               case EXTENSION_EXTEND:
+                                       ix = wrap_clamp(ix, width);
+                                       iy = wrap_clamp(iy, height);
+
+                                       nix = wrap_clamp(ix+1, width);
+                                       niy = wrap_clamp(iy+1, height);
+                                       break;
                        }
 
                        float4 r = (1.0f - ty)*(1.0f - tx)*read(data[ix + 
iy*width]);
@@ -176,36 +189,44 @@ template<typename T> struct texture_image  {
                        return r;
                }
                else {
-                       /* Tricubic b-spline interpolation. */
+                       /* Bicubic b-spline interpolation. */
                        const float tx = frac(x*(float)width - 0.5f, &ix);
                        const float ty = frac(y*(float)height - 0.5f, &iy);
                        int pix, piy, nnix, nniy;
-                       if(extension == EXTENSION_REPEAT) {
-                               ix = wrap_periodic(ix, width);
-                               iy = wrap_periodic(iy, height);
-
-                               pix = wrap_periodic(ix-1, width);
-                               piy = wrap_periodic(iy-1, height);
-
-                               nix = wrap_periodic(ix+1, width);
-                               niy = wrap_periodic(iy+1, height);
-
-                               nnix = wrap_periodic(ix+2, width);
-                               nniy = wrap_periodic(iy+2, height);
+                       switch(extension) {
+                               case EXTENSION_REPEAT:
+                                       ix = wrap_periodic(ix, width);
+                                       iy = wrap_periodic(iy, height);
+
+                                       pix = wrap_periodic(ix-1, width);
+                                       piy = wrap_periodic(iy-1, height);
+
+                                       nix = wrap_periodic(ix+1, width);
+                                       niy = wrap_periodic(iy+1, height);
+
+                                       nnix = wrap_periodic(ix+2, width);
+                                       nniy = wrap_periodic(iy+2, height);
+                                       break;
+                               case EXTENSION_CLIP:
+                                       if (ix < 0 || iy < 0 || ix >= width || 
iy >= height) {
+                                               return make_float4(0.0f, 0.0f, 
0.0f, 0.0f);
+                                       }
+                                       /* 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);
+
+                                       nix = wrap_clamp(ix+1, width);
+                                       niy = wrap_clamp(iy+1, height);
+
+                                       nnix = wrap_clamp(ix+2, width);
+                                       nniy = wrap_clamp(iy+2, height);
+                                       break;
                        }
-                       else {
-                               ix = wrap_clamp(ix, width);
-                               iy = wrap_clamp(iy, height);
-
-                               pix = wrap_clamp(ix-1, width);
-                               piy = 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);
-                       }
                        const int xc[4] = {pix, ix, nix, nnix};
                        const int yc[4] = {width * piy,
                                           width * iy,
@@ -251,15 +272,22 @@ template<typename T> struct texture_image  {
                        frac(y*(float)height, &iy);
                        frac(z*(float)depth, &iz);
 
-                       if(extension == EXTENSION_REPEAT) {
-                               ix = wrap_periodic(ix, width);
-                               iy = wrap_periodic(iy, height);
-                               iz = wrap_periodic(iz, depth);
-                       }
-                       else {
-                               ix = wrap_clamp(ix, width);
-                               iy = wrap_clamp(iy, height);
-                               iz = wrap_clamp(iz, depth);
+                       switch(extension) {
+                               case EXTENSION_REPEAT:
+                                       ix = wrap_periodic(ix, width);
+                                       iy = wrap_periodic(iy, height);
+                                       iz = wrap_periodic(iz, depth);
+                                       break;
+                               case EXTENSION_CLIP:
+                                       if (ix < 0 || iy < 0 || ix >= width || 
iy >= height) {
+                                               return make_float4(0.0f, 0.0f, 
0.0f, 0.0f);
+                                       }
+                                       /* Fall through. */
+                               case EXTENSION_EXTEND:
+                                       ix = wrap_clamp(ix, width);
+                                       iy = wrap_clamp(iy, height);
+                                       iz = wrap_clamp(iz, depth);
+                                       break;
                        }
 
                        return read(data[ix + iy*width + iz*width*height]);
@@ -269,23 +297,30 @@ template<typename T> struct texture_image  {
                        float ty = frac(y*(float)height - 0.5f, &iy);
                        float tz = frac(z*(float)depth - 0.5f, &iz);
 
-                       if(extension == EXTENSION_REPEAT) {
-                               ix = wrap_periodic(ix, width);
-                               iy = wrap_periodic(iy, height);
-                               iz = wrap_periodic(iz, depth);
-
-                               nix = wrap_periodic(ix+1, width);
-                               niy = wrap_periodic(iy+1, height);
-                               niz = wrap_periodic(iz+1, depth);
-                       }
-                       else {
-                               ix = wrap_clamp(ix, width);
-                               iy = wrap_clamp(iy, height);
-                               iz = wrap_clamp(iz, depth);
-
-                               nix = wrap_clamp(ix+1, width);
-                               niy = wrap_clamp(iy+1, height);
-                               niz = wrap_clamp(iz+1, depth);
+                       switch(extension) {
+                               case EXTENSION_REPEAT:
+                                       ix = wrap_periodic(ix, width);
+                                       iy = wrap_periodic(iy, height);
+                                       iz = wrap_periodic(iz, depth);
+
+                                       nix = wrap_periodic(ix+1, width);
+                                       niy = wrap_periodic(iy+1, height);
+                                       niz = wrap_periodic(iz+1, depth);
+                                       break;
+                               case EXTENSION_CLIP:
+                                       if (ix < 0 || iy < 0 || ix >= width || 
iy >= height) {
+                                               return make_float4(0.0f, 0.0f, 
0.0f, 0.0f);
+                                       }
+                                       /* Fall through. */
+                               case EXTENSION_EXTEND:
+                                       ix = wrap_clamp(ix, width);
+                                       iy = wrap_clamp(iy, height);
+                                       iz = wrap_clamp(iz, depth);
+
+                                       nix = wrap_clamp(ix+1, width);
+                                       niy = wrap_clamp(iy+1, height);
+                                       niz = wrap_clamp(iz+1, depth);
+                                       break;
                        }
 
                        float4 r;
@@ -309,39 +344,46 @@ template<typename T> struct texture_image  {
                        const float tz = frac(z*(float)depth - 0.5f, &iz);
                        int pix, piy, piz, nnix, nniy, nniz;
 
-                       if(extension == EXTENSION_REPEAT) {
-                               ix = wrap_periodic(ix, width);
-                               iy = wrap_periodic(iy, height);
-                               iz = wrap_periodic(iz, depth);
-
-                               pix = wrap_periodic(ix-1, width);
-                               piy = wrap_periodic(iy-1, height);
-                               piz = wrap_periodic(iz-1, depth);
-
-                               nix = wrap_periodic(ix+1, width);
-                               niy = wrap_periodic(iy+1, height);
-                               niz = wrap_periodic(iz+1, depth);
-
-                               nnix = wrap_periodic(ix+2, width);
-                               nniy = wrap_periodic(iy+2, height);
-                               nniz = wrap_periodic(iz+2, depth);
-                       }
-                       else {
-                               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);
-
-                               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);
+                       switch(extension) {
+                               case EXTENSION_REPEAT:
+                                       ix = wrap_periodic(ix, width);
+                                       iy = wrap_periodic(iy, height);
+                                       iz = wrap_periodic(iz, depth);
+
+                                       pix = wrap_periodic(ix-1, width);
+                                       piy = wrap_periodic(iy-1, height);
+                                       piz = wrap_periodic(iz-1, depth);
+
+                                       nix = wrap_periodic(ix+1, width);
+                                       niy = wrap_periodic(iy+1, height);
+                                       niz = wrap_periodic(iz+1, depth);
+
+                                       nnix = wrap_periodic(ix+2, width);
+                                       nniy = wrap_periodic(iy+2, height);
+                                       nniz = wrap_periodic(iz+2, depth);
+                                       break;
+                               case EXTENSION_CLIP:
+                                       if (ix < 0 || iy < 0 || ix >= width || 
iy >= height) {
+                                               return make_float4(0.0f, 0.0f, 
0.0f, 0.0f);
+                                       }
+                                       /* 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);
+
+                                       nix = wrap_clamp(ix+1, width);
+                                       niy = wrap_clamp(iy+1, height);
+                                       niz = wrap_clamp(iz+1, depth);
+
+                               

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to