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:
authorCarlo Andreacchio <carlorules@gmail.com>2014-05-07 18:36:44 +0400
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2014-05-07 18:43:50 +0400
commit8b8d5a441f5815e83f83bacf8023e2cc3fbb2a04 (patch)
tree777b695333e690b56f501f9fe037f650c0e50a69
parent1d03a8b30932e6a4c4e511eef3f543590b0bcd2a (diff)
Cycles: add support for "Use Alpha" option on image datablocks.
Reviewed By: brecht Differential Revision: https://developer.blender.org/D486
-rw-r--r--intern/cycles/blender/blender_mesh.cpp2
-rw-r--r--intern/cycles/blender/blender_shader.cpp2
-rw-r--r--intern/cycles/render/image.cpp32
-rw-r--r--intern/cycles/render/image.h3
-rw-r--r--intern/cycles/render/nodes.cpp6
-rw-r--r--intern/cycles/render/nodes.h2
6 files changed, 38 insertions, 9 deletions
diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index c49086d83a7..83514879477 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -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)
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index 2eafcecf026..7f384d9a1e7 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -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;
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<uchar4>& 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<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(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<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;
}
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;