diff options
author | Martijn Berger <martijn.berger@gmail.com> | 2014-03-08 02:16:09 +0400 |
---|---|---|
committer | Martijn Berger <martijn.berger@gmail.com> | 2014-03-08 02:16:33 +0400 |
commit | dd2dca2f7e77e7521d13b78e875ffa58a90846f2 (patch) | |
tree | 26c0d371fbca7eb25e9060aabc5ef6fe56939cf2 /intern/cycles/kernel | |
parent | ef51b690090967f5576b88a528a79c5defb1ddd4 (diff) |
Add support for multiple interpolation modes on cycles image textures
All textures are sampled bi-linear currently with the exception of OSL there texture sampling is fixed and set to smart bi-cubic.
This patch adds user control to this setting.
Added:
- bits to DNA / RNA in the form of an enum for supporting multiple interpolations types
- changes to the image texture node drawing code ( add enum)
- to ImageManager (this needs to know to allocate second texture when interpolation type is different)
- to node compiler (pass on interpolation type)
- to device tex_alloc this also needs to get the concept of multiple interpolation types
- implementation for doing non interpolated lookup for cuda and cpu
- implementation where we pass this along to osl ( this makes OSL also do linear untill I add smartcubic to the interface / DNA/ RNA)
Reviewers: brecht, dingto
Reviewed By: brecht
CC: dingto, venomgfx
Differential Revision: https://developer.blender.org/D317
Diffstat (limited to 'intern/cycles/kernel')
-rw-r--r-- | intern/cycles/kernel/kernel.cpp | 4 | ||||
-rw-r--r-- | intern/cycles/kernel/kernel.h | 2 | ||||
-rw-r--r-- | intern/cycles/kernel/kernel_compat_cpu.h | 18 | ||||
-rw-r--r-- | intern/cycles/kernel/shaders/node_image_texture.osl | 13 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_image.h | 17 |
5 files changed, 34 insertions, 20 deletions
diff --git a/intern/cycles/kernel/kernel.cpp b/intern/cycles/kernel/kernel.cpp index 6cd14d3c51c..5d74feed9f4 100644 --- a/intern/cycles/kernel/kernel.cpp +++ b/intern/cycles/kernel/kernel.cpp @@ -37,7 +37,7 @@ void kernel_const_copy(KernelGlobals *kg, const char *name, void *host, size_t s assert(0); } -void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t width, size_t height) +void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t width, size_t height, InterpolationType interpolation) { if(0) { } @@ -63,6 +63,7 @@ void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t tex->data = (float4*)mem; tex->width = width; tex->height = height; + tex->interpolation = interpolation; } } else if(strstr(name, "__tex_image")) { @@ -78,6 +79,7 @@ void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t tex->data = (uchar4*)mem; tex->width = width; tex->height = height; + tex->interpolation = interpolation; } } else diff --git a/intern/cycles/kernel/kernel.h b/intern/cycles/kernel/kernel.h index 039dc791b08..a4f13e78006 100644 --- a/intern/cycles/kernel/kernel.h +++ b/intern/cycles/kernel/kernel.h @@ -32,7 +32,7 @@ void *kernel_osl_memory(KernelGlobals *kg); bool kernel_osl_use(KernelGlobals *kg); void kernel_const_copy(KernelGlobals *kg, const char *name, void *host, size_t size); -void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t width, size_t height); +void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t width, size_t height, InterpolationType interpolation=INTERPOLATION_LINEAR); void kernel_cpu_path_trace(KernelGlobals *kg, float *buffer, unsigned int *rng_state, int sample, int x, int y, int offset, int stride); diff --git a/intern/cycles/kernel/kernel_compat_cpu.h b/intern/cycles/kernel/kernel_compat_cpu.h index a9c66ec2d68..55f4484ba1f 100644 --- a/intern/cycles/kernel/kernel_compat_cpu.h +++ b/intern/cycles/kernel/kernel_compat_cpu.h @@ -117,14 +117,19 @@ template<typename T> struct texture_image { 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; + if(interpolation == INTERPOLATION_CLOSEST) { + return read(data[ix + iy*width]); + } + else { + 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; + } } + int interpolation; T *data; int width, height; }; @@ -146,7 +151,6 @@ 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_data (kg->__data) CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/shaders/node_image_texture.osl b/intern/cycles/kernel/shaders/node_image_texture.osl index caa755636b9..7238a1e8862 100644 --- a/intern/cycles/kernel/shaders/node_image_texture.osl +++ b/intern/cycles/kernel/shaders/node_image_texture.osl @@ -17,9 +17,9 @@ #include "stdosl.h" #include "node_color.h" -color image_texture_lookup(string filename, string color_space, float u, float v, output float Alpha, int use_alpha, int is_float) +color image_texture_lookup(string filename, string color_space, float u, float v, output float Alpha, int use_alpha, int is_float, string interpolation) { - color rgb = (color)texture(filename, u, 1.0 - v, "wrap", "periodic", "alpha", Alpha); + color rgb = (color)texture(filename, u, 1.0 - v, "wrap", "periodic", "interp", interpolation, "alpha", Alpha); if (use_alpha) { rgb = color_unpremultiply(rgb, Alpha); @@ -42,6 +42,7 @@ shader node_image_texture( string filename = "", string color_space = "sRGB", string projection = "Flat", + string interpolation = "smartcubic", float projection_blend = 0.0, int is_float = 1, int use_alpha = 1, @@ -54,7 +55,7 @@ shader node_image_texture( p = transform(mapping, p); if (projection == "Flat") { - Color = image_texture_lookup(filename, color_space, p[0], p[1], Alpha, use_alpha, is_float); + Color = image_texture_lookup(filename, color_space, p[0], p[1], Alpha, use_alpha, is_float, interpolation); } else if (projection == "Box") { /* object space normal */ @@ -119,15 +120,15 @@ shader node_image_texture( float tmp_alpha; if (weight[0] > 0.0) { - Color += weight[0] * image_texture_lookup(filename, color_space, p[1], p[2], tmp_alpha, use_alpha, is_float); + Color += weight[0] * image_texture_lookup(filename, color_space, p[1], p[2], tmp_alpha, use_alpha, is_float, interpolation); Alpha += weight[0] * tmp_alpha; } if (weight[1] > 0.0) { - Color += weight[1] * image_texture_lookup(filename, color_space, p[0], p[2], tmp_alpha, use_alpha, is_float); + Color += weight[1] * image_texture_lookup(filename, color_space, p[0], p[2], tmp_alpha, use_alpha, is_float, interpolation); Alpha += weight[1] * tmp_alpha; } if (weight[2] > 0.0) { - Color += weight[2] * image_texture_lookup(filename, color_space, p[1], p[0], tmp_alpha, use_alpha, is_float); + Color += weight[2] * image_texture_lookup(filename, color_space, p[1], p[0], tmp_alpha, use_alpha, is_float, interpolation); Alpha += weight[2] * tmp_alpha; } } diff --git a/intern/cycles/kernel/svm/svm_image.h b/intern/cycles/kernel/svm/svm_image.h index bc76ea1e662..750af97150e 100644 --- a/intern/cycles/kernel/svm/svm_image.h +++ b/intern/cycles/kernel/svm/svm_image.h @@ -60,7 +60,8 @@ ccl_device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y, uint width = info.x; uint height = info.y; uint offset = info.z; - uint periodic = info.w; + uint periodic = (info.w & 0x1); + uint interpolation = info.w >> 1; int ix, iy, nix, niy; float tx = svm_image_texture_frac(x*width, &ix); @@ -81,10 +82,16 @@ ccl_device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y, niy = svm_image_texture_wrap_clamp(iy+1, height); } - float4 r = (1.0f - ty)*(1.0f - tx)*svm_image_texture_read(kg, offset + ix + iy*width); - r += (1.0f - ty)*tx*svm_image_texture_read(kg, offset + nix + iy*width); - r += ty*(1.0f - tx)*svm_image_texture_read(kg, offset + ix + niy*width); - r += ty*tx*svm_image_texture_read(kg, offset + nix + niy*width); + float4 r; + if (interpolation == INTERPOLATION_CLOSEST){ + r = svm_image_texture_read(kg, offset + ix + iy*width); + } + else { /* We default to linear interpolation if it is not closest */ + r = (1.0f - ty)*(1.0f - tx)*svm_image_texture_read(kg, offset + ix + iy*width); + r += (1.0f - ty)*tx*svm_image_texture_read(kg, offset + nix + iy*width); + r += ty*(1.0f - tx)*svm_image_texture_read(kg, offset + ix + niy*width); + r += ty*tx*svm_image_texture_read(kg, offset + nix + niy*width); + } if(use_alpha && r.w != 1.0f && r.w != 0.0f) { float invw = 1.0f/r.w; |