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:
authorMartijn Berger <martijn.berger@gmail.com>2014-03-08 02:16:09 +0400
committerMartijn Berger <martijn.berger@gmail.com>2014-03-08 02:16:33 +0400
commitdd2dca2f7e77e7521d13b78e875ffa58a90846f2 (patch)
tree26c0d371fbca7eb25e9060aabc5ef6fe56939cf2 /intern/cycles/render
parentef51b690090967f5576b88a528a79c5defb1ddd4 (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/render')
-rw-r--r--intern/cycles/render/image.cpp41
-rw-r--r--intern/cycles/render/image.h6
-rw-r--r--intern/cycles/render/nodes.cpp27
-rw-r--r--intern/cycles/render/nodes.h1
4 files changed, 58 insertions, 17 deletions
diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp
index 91aae6f3ec3..b2559c8c824 100644
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@ -145,7 +145,7 @@ bool ImageManager::is_float_image(const string& filename, void *builtin_data, bo
return is_float;
}
-int ImageManager::add_image(const string& filename, void *builtin_data, bool animated, bool& is_float, bool& is_linear)
+int ImageManager::add_image(const string& filename, void *builtin_data, bool animated, bool& is_float, bool& is_linear, InterpolationType interpolation)
{
Image *img;
size_t slot;
@@ -156,7 +156,7 @@ int ImageManager::add_image(const string& filename, void *builtin_data, bool ani
if(is_float) {
/* find existing image */
for(slot = 0; slot < float_images.size(); slot++) {
- if(float_images[slot] && float_images[slot]->filename == filename) {
+ if(float_images[slot] && float_images[slot]->filename == filename && float_images[slot]->interpolation == interpolation) {
float_images[slot]->users++;
return slot;
}
@@ -185,13 +185,14 @@ int ImageManager::add_image(const string& filename, void *builtin_data, bool ani
img->builtin_data = builtin_data;
img->need_load = true;
img->animated = animated;
+ img->interpolation = interpolation;
img->users = 1;
float_images[slot] = img;
}
else {
for(slot = 0; slot < images.size(); slot++) {
- if(images[slot] && images[slot]->filename == filename) {
+ if(images[slot] && images[slot]->filename == filename && images[slot]->interpolation == interpolation) {
images[slot]->users++;
return slot+tex_image_byte_start;
}
@@ -220,6 +221,7 @@ int ImageManager::add_image(const string& filename, void *builtin_data, bool ani
img->builtin_data = builtin_data;
img->need_load = true;
img->animated = animated;
+ img->interpolation = interpolation;
img->users = 1;
images[slot] = img;
@@ -231,12 +233,12 @@ int ImageManager::add_image(const string& filename, void *builtin_data, bool ani
return slot;
}
-void ImageManager::remove_image(const string& filename, void *builtin_data)
+void ImageManager::remove_image(const string& filename, void *builtin_data, InterpolationType interpolation)
{
size_t slot;
for(slot = 0; slot < images.size(); slot++) {
- if(images[slot] && images[slot]->filename == filename && images[slot]->builtin_data == builtin_data) {
+ if(images[slot] && images[slot]->filename == filename && images[slot]->interpolation == interpolation && images[slot]->builtin_data == builtin_data) {
/* decrement user count */
images[slot]->users--;
assert(images[slot]->users >= 0);
@@ -254,7 +256,9 @@ void ImageManager::remove_image(const string& filename, void *builtin_data)
if(slot == images.size()) {
/* see if it's in a float texture slot */
for(slot = 0; slot < float_images.size(); slot++) {
- if(float_images[slot] && float_images[slot]->filename == filename && float_images[slot]->builtin_data == builtin_data) {
+ if(float_images[slot] && float_images[slot]->filename == filename
+ && float_images[slot]->interpolation == interpolation
+ && float_images[slot]->builtin_data == builtin_data) {
/* decrement user count */
float_images[slot]->users--;
assert(float_images[slot]->users >= 0);
@@ -499,7 +503,7 @@ void ImageManager::device_load_image(Device *device, DeviceScene *dscene, int sl
if(!pack_images) {
thread_scoped_lock device_lock(device_mutex);
- device->tex_alloc(name.c_str(), tex_img, true, true);
+ device->tex_alloc(name.c_str(), tex_img, img->interpolation, true);
}
}
else {
@@ -530,7 +534,7 @@ void ImageManager::device_load_image(Device *device, DeviceScene *dscene, int sl
if(!pack_images) {
thread_scoped_lock device_lock(device_mutex);
- device->tex_alloc(name.c_str(), tex_img, true, true);
+ device->tex_alloc(name.c_str(), tex_img, img->interpolation, true);
}
}
@@ -653,16 +657,31 @@ void ImageManager::device_pack_images(Device *device, DeviceScene *dscene, Progr
device_vector<uchar4>& tex_img = dscene->tex_image[slot];
- info[slot] = make_uint4(tex_img.data_width, tex_img.data_height, offset, 1);
+
+ /* The image options are packed
+ bit 0 -> periodic
+ bit 1 + 2 -> interpolation type */
+ u_int8_t interpolation = (images[slot]->interpolation << 1) + 1;
+ info[slot] = make_uint4(tex_img.data_width, tex_img.data_height, offset, interpolation);
memcpy(pixels+offset, (void*)tex_img.data_pointer, tex_img.memory_size());
offset += tex_img.size();
}
- if(dscene->tex_image_packed.size())
+ if(dscene->tex_image_packed.size()) {
+ if(dscene->tex_image_packed.device_pointer) {
+ thread_scoped_lock device_lock(device_mutex);
+ device->tex_free(dscene->tex_image_packed);
+ }
device->tex_alloc("__tex_image_packed", dscene->tex_image_packed);
- if(dscene->tex_image_packed_info.size())
+ }
+ if(dscene->tex_image_packed_info.size()) {
+ if(dscene->tex_image_packed_info.device_pointer) {
+ thread_scoped_lock device_lock(device_mutex);
+ device->tex_free(dscene->tex_image_packed_info);
+ }
device->tex_alloc("__tex_image_packed_info", dscene->tex_image_packed_info);
+ }
}
void ImageManager::device_free(Device *device, DeviceScene *dscene)
diff --git a/intern/cycles/render/image.h b/intern/cycles/render/image.h
index 187c5fd0f02..85b6b512bae 100644
--- a/intern/cycles/render/image.h
+++ b/intern/cycles/render/image.h
@@ -49,8 +49,8 @@ public:
ImageManager();
~ImageManager();
- int add_image(const string& filename, void *builtin_data, bool animated, bool& is_float, bool& is_linear);
- void remove_image(const string& filename, void *builtin_data);
+ int add_image(const string& filename, void *builtin_data, bool animated, bool& is_float, bool& is_linear, InterpolationType interpolation);
+ void remove_image(const string& filename, void *builtin_data, InterpolationType interpolation);
bool is_float_image(const string& filename, void *builtin_data, bool& is_linear);
void device_update(Device *device, DeviceScene *dscene, Progress& progress);
@@ -79,6 +79,8 @@ private:
bool need_load;
bool animated;
+ InterpolationType interpolation;
+
int users;
};
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index af6fca29ab0..e2ee3a949fd 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -193,6 +193,7 @@ ImageTextureNode::ImageTextureNode()
builtin_data = NULL;
color_space = ustring("Color");
projection = ustring("Flat");
+ interpolation = INTERPOLATION_LINEAR;
projection_blend = 0.0f;
animated = false;
@@ -204,7 +205,7 @@ ImageTextureNode::ImageTextureNode()
ImageTextureNode::~ImageTextureNode()
{
if(image_manager)
- image_manager->remove_image(filename, builtin_data);
+ image_manager->remove_image(filename, builtin_data, interpolation);
}
ShaderNode *ImageTextureNode::clone() const
@@ -241,7 +242,7 @@ void ImageTextureNode::compile(SVMCompiler& compiler)
image_manager = compiler.image_manager;
if(is_float == -1) {
bool is_float_bool;
- slot = image_manager->add_image(filename, builtin_data, animated, is_float_bool, is_linear);
+ slot = image_manager->add_image(filename, builtin_data, animated, is_float_bool, is_linear, interpolation);
is_float = (int)is_float_bool;
}
@@ -315,6 +316,24 @@ void ImageTextureNode::compile(OSLCompiler& compiler)
compiler.parameter("projection_blend", projection_blend);
compiler.parameter("is_float", is_float);
compiler.parameter("use_alpha", !alpha_out->links.empty());
+
+ switch (interpolation){
+ case INTERPOLATION_LINEAR:
+ compiler.parameter("interpolation", "linear");
+ break;
+ case INTERPOLATION_CLOSEST:
+ compiler.parameter("interpolation", "closest");
+ break;
+ case INTERPOLATION_CUBIC:
+ compiler.parameter("interpolation", "cubic");
+ break;
+ case INTERPOLATION_SMART:
+ compiler.parameter("interpolation", "smart");
+ break;
+ default:
+ compiler.parameter("interpolation", "linear");
+ break;
+ }
compiler.add(this, "node_image_texture");
}
@@ -354,7 +373,7 @@ EnvironmentTextureNode::EnvironmentTextureNode()
EnvironmentTextureNode::~EnvironmentTextureNode()
{
if(image_manager)
- image_manager->remove_image(filename, builtin_data);
+ image_manager->remove_image(filename, builtin_data, INTERPOLATION_LINEAR);
}
ShaderNode *EnvironmentTextureNode::clone() const
@@ -389,7 +408,7 @@ void EnvironmentTextureNode::compile(SVMCompiler& compiler)
image_manager = compiler.image_manager;
if(slot == -1) {
bool is_float_bool;
- slot = image_manager->add_image(filename, builtin_data, animated, is_float_bool, is_linear);
+ slot = image_manager->add_image(filename, builtin_data, animated, is_float_bool, is_linear, INTERPOLATION_LINEAR);
is_float = (int)is_float_bool;
}
diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h
index 86c4f490875..497a367a2a6 100644
--- a/intern/cycles/render/nodes.h
+++ b/intern/cycles/render/nodes.h
@@ -76,6 +76,7 @@ public:
void *builtin_data;
ustring color_space;
ustring projection;
+ InterpolationType interpolation;
float projection_blend;
bool animated;