Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2014-03-29 16:03:48 +0400
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2014-03-29 16:03:48 +0400
commita2e4ebd36a319dc18f362b1f75863b8ee93eed7d (patch)
treebcf041e53375766661de3d0a199930369b3d1466 /intern/cycles/kernel/kernel_compat_cpu.h
parent07d1fba3676c950b0cc3ab1dfb1f2de614c62697 (diff)
Cycles code internals: add CPU kernel support for 3D image textures.
Diffstat (limited to 'intern/cycles/kernel/kernel_compat_cpu.h')
-rw-r--r--intern/cycles/kernel/kernel_compat_cpu.h74
1 files changed, 72 insertions, 2 deletions
diff --git a/intern/cycles/kernel/kernel_compat_cpu.h b/intern/cycles/kernel/kernel_compat_cpu.h
index 850ef0abed1..feaff503212 100644
--- a/intern/cycles/kernel/kernel_compat_cpu.h
+++ b/intern/cycles/kernel/kernel_compat_cpu.h
@@ -99,6 +99,7 @@ template<typename T> struct texture_image {
return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
int ix, iy, nix, niy;
+
if(interpolation == INTERPOLATION_CLOSEST) {
frac(x*width, &ix);
frac(y*height, &iy);
@@ -131,17 +132,84 @@ template<typename T> struct texture_image {
nix = wrap_clamp(ix+1, width);
niy = wrap_clamp(iy+1, height);
}
+
float4 r = (1.0f - ty)*(1.0f - tx)*read(data[ix + iy*width]);
r += (1.0f - ty)*tx*read(data[nix + iy*width]);
r += ty*(1.0f - tx)*read(data[ix + niy*width]);
r += ty*tx*read(data[nix + niy*width]);
+
+ return r;
+ }
+ }
+
+ ccl_always_inline float4 interp_3d(float x, float y, float z, bool periodic = false)
+ {
+ if(!data)
+ return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+
+ int ix, iy, iz, nix, niy, niz;
+
+ if(interpolation == INTERPOLATION_CLOSEST) {
+ frac(x*width, &ix);
+ frac(y*height, &iy);
+ frac(z*depth, &iz);
+
+ if(periodic) {
+ 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);
+ }
+
+ return read(data[ix + iy*width + iz*width*height]);
+ }
+ else {
+ float tx = frac(x*width - 0.5f, &ix);
+ float ty = frac(y*height - 0.5f, &iy);
+ float tz = frac(z*depth - 0.5f, &iz);
+
+ if(periodic) {
+ 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);
+ }
+
+ float4 r;
+
+ r = (1.0f - tz)*(1.0f - ty)*(1.0f - tx)*read(data[ix + iy*width + iz*width*height]);
+ r += (1.0f - tz)*(1.0f - ty)*tx*read(data[nix + iy*width + iz*width*height]);
+ r += (1.0f - tz)*ty*(1.0f - tx)*read(data[ix + niy*width + iz*width*height]);
+ r += (1.0f - tz)*ty*tx*read(data[nix + niy*width + iz*width*height]);
+
+ r += tz*(1.0f - ty)*(1.0f - tx)*read(data[ix + iy*width + niz*width*height]);
+ r += tz*(1.0f - ty)*tx*read(data[nix + iy*width + niz*width*height]);
+ r += tz*ty*(1.0f - tx)*read(data[ix + niy*width + niz*width*height]);
+ r += tz*ty*tx*read(data[nix + niy*width + niz*width*height]);
+
return r;
}
}
- int interpolation;
T *data;
- int width, height;
+ int interpolation;
+ int width, height, depth;
};
typedef texture<float4> texture_float4;
@@ -161,6 +229,8 @@ typedef texture_image<uchar4> texture_image_uchar4;
#define kernel_tex_fetch_m128i(tex, index) (kg->tex.fetch_m128i(index))
#define kernel_tex_lookup(tex, t, offset, size) (kg->tex.lookup(t, offset, size))
#define kernel_tex_image_interp(tex, x, y) ((tex < MAX_FLOAT_IMAGES) ? kg->texture_float_images[tex].interp(x, y) : kg->texture_byte_images[tex - MAX_FLOAT_IMAGES].interp(x, y))
+#define kernel_tex_image_interp_3d(tex, x, y, z) ((tex < MAX_FLOAT_IMAGES) ? kg->texture_float_images[tex].interp_3d(x, y, z) : kg->texture_byte_images[tex - MAX_FLOAT_IMAGES].interp_3d(x, y, z))
+
#define kernel_data (kg->__data)
CCL_NAMESPACE_END