From 8b8d5a441f5815e83f83bacf8023e2cc3fbb2a04 Mon Sep 17 00:00:00 2001 From: Carlo Andreacchio Date: Wed, 7 May 2014 16:36:44 +0200 Subject: Cycles: add support for "Use Alpha" option on image datablocks. Reviewed By: brecht Differential Revision: https://developer.blender.org/D486 --- intern/cycles/render/image.cpp | 32 +++++++++++++++++++++++++++----- intern/cycles/render/image.h | 3 ++- intern/cycles/render/nodes.cpp | 6 ++++-- intern/cycles/render/nodes.h | 2 ++ 4 files changed, 35 insertions(+), 8 deletions(-) (limited to 'intern/cycles/render') diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp index 6348c9e6706..8dde642f70b 100644 --- a/intern/cycles/render/image.cpp +++ b/intern/cycles/render/image.cpp @@ -152,7 +152,7 @@ static bool image_equals(ImageManager::Image *image, const string& filename, voi image->interpolation == interpolation; } -int ImageManager::add_image(const string& filename, void *builtin_data, bool animated, bool& is_float, bool& is_linear, InterpolationType interpolation) +int ImageManager::add_image(const string& filename, void *builtin_data, bool animated, bool& is_float, bool& is_linear, InterpolationType interpolation, bool use_alpha) { Image *img; size_t slot; @@ -194,6 +194,7 @@ int ImageManager::add_image(const string& filename, void *builtin_data, bool ani img->animated = animated; img->interpolation = interpolation; img->users = 1; + img->use_alpha = use_alpha; float_images[slot] = img; } @@ -230,6 +231,7 @@ int ImageManager::add_image(const string& filename, void *builtin_data, bool ani img->animated = animated; img->interpolation = interpolation; img->users = 1; + img->use_alpha = use_alpha; images[slot] = img; @@ -307,9 +309,13 @@ bool ImageManager::file_load_image(Image *img, device_vector& tex_img) if(!in) return false; - ImageSpec spec; + ImageSpec spec = ImageSpec(); + ImageSpec config = ImageSpec(); + + if(img->use_alpha == false) + config.attribute("oiio:UnassociatedAlpha", 1); - if(!in->open(img->filename, spec)) { + if(!in->open(img->filename, spec, config)) { delete in; return false; } @@ -387,6 +393,12 @@ bool ImageManager::file_load_image(Image *img, device_vector& tex_img) } } + if(img->use_alpha == false) { + for(int i = width*height*depth-1; i >= 0; i--) { + pixels[i*4+3] = 255; + } + } + return true; } @@ -405,9 +417,13 @@ bool ImageManager::file_load_float_image(Image *img, device_vector& tex_ if(!in) return false; - ImageSpec spec; + ImageSpec spec = ImageSpec(); + ImageSpec config = ImageSpec(); + + if(img->use_alpha == false) + config.attribute("oiio:UnassociatedAlpha",1); - if(!in->open(img->filename, spec)) { + if(!in->open(img->filename, spec, config)) { delete in; return false; } @@ -484,6 +500,12 @@ bool ImageManager::file_load_float_image(Image *img, device_vector& tex_ } } + if(img->use_alpha == false) { + for(int i = width*height*depth-1; i >= 0; i--) { + pixels[i*4+3] = 1.0f; + } + } + return true; } diff --git a/intern/cycles/render/image.h b/intern/cycles/render/image.h index a52ab2853b9..a862ffce5c3 100644 --- a/intern/cycles/render/image.h +++ b/intern/cycles/render/image.h @@ -49,7 +49,7 @@ public: ImageManager(); ~ImageManager(); - int add_image(const string& filename, void *builtin_data, bool animated, bool& is_float, bool& is_linear, InterpolationType interpolation); + int add_image(const string& filename, void *builtin_data, bool animated, bool& is_float, bool& is_linear, InterpolationType interpolation, bool use_alpha); void remove_image(int slot); void remove_image(const string& filename, void *builtin_data, InterpolationType interpolation); bool is_float_image(const string& filename, void *builtin_data, bool& is_linear); @@ -72,6 +72,7 @@ public: string filename; void *builtin_data; + bool use_alpha; bool need_load; bool animated; InterpolationType interpolation; diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 28d2a41a113..e269074763c 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -189,6 +189,7 @@ ImageTextureNode::ImageTextureNode() slot = -1; is_float = -1; is_linear = false; + use_alpha = true; filename = ""; builtin_data = NULL; color_space = ustring("Color"); @@ -242,7 +243,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, interpolation); + slot = image_manager->add_image(filename, builtin_data, animated, is_float_bool, is_linear, interpolation, use_alpha); is_float = (int)is_float_bool; } @@ -357,6 +358,7 @@ EnvironmentTextureNode::EnvironmentTextureNode() slot = -1; is_float = -1; is_linear = false; + use_alpha = true; filename = ""; builtin_data = NULL; color_space = ustring("Color"); @@ -406,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, INTERPOLATION_LINEAR); + slot = image_manager->add_image(filename, builtin_data, animated, is_float_bool, is_linear, INTERPOLATION_LINEAR, use_alpha); is_float = (int)is_float_bool; } diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h index 054ae0f613c..d94d8ce6033 100644 --- a/intern/cycles/render/nodes.h +++ b/intern/cycles/render/nodes.h @@ -72,6 +72,7 @@ public: int slot; int is_float; bool is_linear; + bool use_alpha; string filename; void *builtin_data; ustring color_space; @@ -95,6 +96,7 @@ public: int slot; int is_float; bool is_linear; + bool use_alpha; string filename; void *builtin_data; ustring color_space; -- cgit v1.2.3