From aac6ee6b870eb968d37c16039e6cdc579df17288 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 24 Aug 2015 10:37:59 +0200 Subject: Fix T45885: Cycles coordinate extension modes not working as expected Fix T45769: Image Texture Node clipping bug Simple mistakes in the normalized/pixel-space coordinates handling. Render tests for this feature are coming. --- intern/cycles/kernel/kernel_compat_cpu.h | 72 ++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 26 deletions(-) (limited to '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 d02670f630a..951de884494 100644 --- a/intern/cycles/kernel/kernel_compat_cpu.h +++ b/intern/cycles/kernel/kernel_compat_cpu.h @@ -144,7 +144,7 @@ template struct texture_image { iy = wrap_periodic(iy, height); break; case EXTENSION_CLIP: - if (x < 0.0f || y < 0.0f || x >= width || y >= height) { + if (x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f) { return make_float4(0.0f, 0.0f, 0.0f, 0.0f); } /* Fall through. */ @@ -168,7 +168,7 @@ template struct texture_image { niy = wrap_periodic(iy+1, height); break; case EXTENSION_CLIP: - if (x < 0.0f || y < 0.0f || x >= width || y >= height) { + if (x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f) { return make_float4(0.0f, 0.0f, 0.0f, 0.0f); } /* Fall through. */ @@ -176,8 +176,13 @@ template struct texture_image { ix = wrap_clamp(ix, width); iy = wrap_clamp(iy, height); - nix = wrap_clamp(ix+1, width); - niy = wrap_clamp(iy+1, 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; } @@ -208,7 +213,7 @@ template struct texture_image { nniy = wrap_periodic(iy+2, height); break; case EXTENSION_CLIP: - if (x < 0.0f || y < 0.0f || x >= width || y >= height) { + if (x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f) { return make_float4(0.0f, 0.0f, 0.0f, 0.0f); } /* Fall through. */ @@ -216,14 +221,19 @@ template struct texture_image { 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]); + } break; } @@ -279,7 +289,7 @@ template struct texture_image { iz = wrap_periodic(iz, depth); break; case EXTENSION_CLIP: - if (x < 0.0f || y < 0.0f || x >= width || y >= height) { + if (x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f) { return make_float4(0.0f, 0.0f, 0.0f, 0.0f); } /* Fall through. */ @@ -308,7 +318,7 @@ template struct texture_image { niz = wrap_periodic(iz+1, depth); break; case EXTENSION_CLIP: - if (x < 0.0f || y < 0.0f || x >= width || y >= height) { + if (x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f) { return make_float4(0.0f, 0.0f, 0.0f, 0.0f); } /* Fall through. */ @@ -317,9 +327,14 @@ template struct texture_image { 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); + 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; } @@ -363,7 +378,7 @@ template struct texture_image { nniz = wrap_periodic(iz+2, depth); break; case EXTENSION_CLIP: - if (x < 0.0f || y < 0.0f || x >= width || y >= height) { + if (x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f) { return make_float4(0.0f, 0.0f, 0.0f, 0.0f); } /* Fall through. */ @@ -372,17 +387,22 @@ template struct texture_image { 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]); + } break; } -- cgit v1.2.3 From 0bc4bc2e616bc860634bb3b4a637c3400dc5c68f Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 3 Sep 2015 17:14:35 +0500 Subject: Fix T45946: Cycles texture interpolation bug Coordinate clamping was done in the wrong order. --- intern/cycles/kernel/kernel_compat_cpu.h | 78 ++++++++++++-------------------- 1 file changed, 29 insertions(+), 49 deletions(-) (limited to '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 951de884494..ed145b4a967 100644 --- a/intern/cycles/kernel/kernel_compat_cpu.h +++ b/intern/cycles/kernel/kernel_compat_cpu.h @@ -173,16 +173,11 @@ template 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 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 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 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 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; } -- cgit v1.2.3 From d784568805732fd7929c93cf30b7df7c07a16e5e Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 5 Oct 2015 12:40:50 +0500 Subject: Cycles: Fix missing z-coordinate check in volume sampling --- intern/cycles/kernel/kernel_compat_cpu.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to '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 ed145b4a967..7908293589a 100644 --- a/intern/cycles/kernel/kernel_compat_cpu.h +++ b/intern/cycles/kernel/kernel_compat_cpu.h @@ -279,7 +279,9 @@ template struct texture_image { iz = wrap_periodic(iz, depth); break; case EXTENSION_CLIP: - if (x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f) { + if (x < 0.0f || y < 0.0f || z < 0.0f || + x > 1.0f || y > 1.0f || z > 1.0f) + { return make_float4(0.0f, 0.0f, 0.0f, 0.0f); } /* Fall through. */ @@ -308,7 +310,9 @@ template struct texture_image { niz = wrap_periodic(iz+1, depth); break; case EXTENSION_CLIP: - if (x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f) { + if (x < 0.0f || y < 0.0f || z < 0.0f || + x > 1.0f || y > 1.0f || z > 1.0f) + { return make_float4(0.0f, 0.0f, 0.0f, 0.0f); } /* Fall through. */ @@ -363,7 +367,9 @@ template struct texture_image { nniz = wrap_periodic(iz+2, depth); break; case EXTENSION_CLIP: - if (x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f) { + if (x < 0.0f || y < 0.0f || z < 0.0f || + x > 1.0f || y > 1.0f || z > 1.0f) + { return make_float4(0.0f, 0.0f, 0.0f, 0.0f); } /* Fall through. */ -- cgit v1.2.3 From 350cf8ea7fe1572e361e773ee4912707054035ff Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 8 Oct 2015 19:08:28 +0500 Subject: Cycles: Cleanup, whitespace around keywords --- intern/cycles/kernel/kernel_compat_cpu.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to '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 7908293589a..04c4cf35587 100644 --- a/intern/cycles/kernel/kernel_compat_cpu.h +++ b/intern/cycles/kernel/kernel_compat_cpu.h @@ -144,7 +144,7 @@ template struct texture_image { iy = wrap_periodic(iy, height); break; case EXTENSION_CLIP: - if (x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f) { + if(x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f) { return make_float4(0.0f, 0.0f, 0.0f, 0.0f); } /* Fall through. */ @@ -168,7 +168,7 @@ template struct texture_image { niy = wrap_periodic(iy+1, height); break; case EXTENSION_CLIP: - if (x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f) { + if(x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f) { return make_float4(0.0f, 0.0f, 0.0f, 0.0f); } /* Fall through. */ @@ -208,7 +208,7 @@ template struct texture_image { nniy = wrap_periodic(iy+2, height); break; case EXTENSION_CLIP: - if (x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f) { + if(x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f) { return make_float4(0.0f, 0.0f, 0.0f, 0.0f); } /* Fall through. */ @@ -279,8 +279,8 @@ template struct texture_image { iz = wrap_periodic(iz, depth); break; case EXTENSION_CLIP: - if (x < 0.0f || y < 0.0f || z < 0.0f || - x > 1.0f || y > 1.0f || z > 1.0f) + if(x < 0.0f || y < 0.0f || z < 0.0f || + x > 1.0f || y > 1.0f || z > 1.0f) { return make_float4(0.0f, 0.0f, 0.0f, 0.0f); } @@ -310,8 +310,8 @@ template struct texture_image { niz = wrap_periodic(iz+1, depth); break; case EXTENSION_CLIP: - if (x < 0.0f || y < 0.0f || z < 0.0f || - x > 1.0f || y > 1.0f || z > 1.0f) + if(x < 0.0f || y < 0.0f || z < 0.0f || + x > 1.0f || y > 1.0f || z > 1.0f) { return make_float4(0.0f, 0.0f, 0.0f, 0.0f); } @@ -367,8 +367,8 @@ template struct texture_image { nniz = wrap_periodic(iz+2, depth); break; case EXTENSION_CLIP: - if (x < 0.0f || y < 0.0f || z < 0.0f || - x > 1.0f || y > 1.0f || z > 1.0f) + if(x < 0.0f || y < 0.0f || z < 0.0f || + x > 1.0f || y > 1.0f || z > 1.0f) { return make_float4(0.0f, 0.0f, 0.0f, 0.0f); } -- cgit v1.2.3