Cycles: add support for "Use Alpha" option on image datablocks.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D486
This commit is contained in:
Carlo Andreacchio 2014-05-07 16:36:44 +02:00 committed by Brecht Van Lommel
parent 1d03a8b309
commit 8b8d5a441f
6 changed files with 38 additions and 9 deletions

@ -222,7 +222,7 @@ static void create_mesh_volume_attribute(BL::Object b_ob, Mesh *mesh, ImageManag
volume_data->manager = image_manager;
volume_data->slot = image_manager->add_image(Attribute::standard_name(std),
b_ob.ptr.data, animated, is_float, is_linear, INTERPOLATION_LINEAR);
b_ob.ptr.data, animated, is_float, is_linear, INTERPOLATION_LINEAR, true);
}
static void create_mesh_volume_attributes(Scene *scene, BL::Object b_ob, Mesh *mesh)

@ -548,6 +548,7 @@ static ShaderNode *add_node(Scene *scene, BL::BlendData b_data, BL::Scene b_scen
image->animated = b_image_node.image_user().use_auto_refresh();
}
image->color_space = ImageTextureNode::color_space_enum[(int)b_image_node.color_space()];
image->use_alpha = b_image.use_alpha();
image->projection = ImageTextureNode::projection_enum[(int)b_image_node.projection()];
image->interpolation = (InterpolationType)b_image_node.interpolation();
image->projection_blend = b_image_node.projection_blend();
@ -576,6 +577,7 @@ static ShaderNode *add_node(Scene *scene, BL::BlendData b_data, BL::Scene b_scen
}
}
env->color_space = EnvironmentTextureNode::color_space_enum[(int)b_env_node.color_space()];
env->use_alpha = b_image.use_alpha();
env->projection = EnvironmentTextureNode::projection_enum[(int)b_env_node.projection()];
get_tex_mapping(&env->tex_mapping, b_env_node.texture_mapping());
node = env;

@ -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<uchar4>& tex_img)
if(!in)
return false;
ImageSpec spec;
ImageSpec spec = ImageSpec();
ImageSpec config = ImageSpec();
if(!in->open(img->filename, spec)) {
if(img->use_alpha == false)
config.attribute("oiio:UnassociatedAlpha", 1);
if(!in->open(img->filename, spec, config)) {
delete in;
return false;
}
@ -387,6 +393,12 @@ bool ImageManager::file_load_image(Image *img, device_vector<uchar4>& 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<float4>& tex_
if(!in)
return false;
ImageSpec spec;
ImageSpec spec = ImageSpec();
ImageSpec config = ImageSpec();
if(!in->open(img->filename, spec)) {
if(img->use_alpha == false)
config.attribute("oiio:UnassociatedAlpha",1);
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<float4>& tex_
}
}
if(img->use_alpha == false) {
for(int i = width*height*depth-1; i >= 0; i--) {
pixels[i*4+3] = 1.0f;
}
}
return true;
}

@ -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;

@ -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;
}

@ -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;