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:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2019-05-18 21:52:20 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-05-19 15:36:42 +0300
commit7aaa7aa9dd79b8c6e37f351fd67a93ba07fbb883 (patch)
tree6d64084b9b104ad3d9f2bbff2b3d0404ec356862 /intern/cycles
parent3b23b5c638feae0ad6319440771b83a64a1f9ebe (diff)
Images: change alpha settings to support channel packing
This also replaces the Use Alpha setting. We now have these alpha modes: * Straight: store RGB and alpha channels separately with alpha acting as a mask, also known as unassociated alpha. * Premultiplied: transparent RGB pixels are multiplied by the alpha channel. The natural format for renders. * Channel Packed: different images are packed in the RGB and alpha channels, and they should not influence each other. Channel packing is commonly used by game engines to save memory. * None: ignore alpha channel from the file and make image fully opaque. Cycles OSL does not correctly support Channel Packed and None yet, we are missing fine control over the OpenImageIO texture cache to do that. Fixes T53672
Diffstat (limited to 'intern/cycles')
-rw-r--r--intern/cycles/blender/blender_mesh.cpp3
-rw-r--r--intern/cycles/blender/blender_shader.cpp12
-rw-r--r--intern/cycles/render/image.cpp30
-rw-r--r--intern/cycles/render/image.h8
-rw-r--r--intern/cycles/render/nodes.cpp64
-rw-r--r--intern/cycles/render/nodes.h4
-rw-r--r--intern/cycles/util/util_texture.h12
7 files changed, 85 insertions, 48 deletions
diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index 1b47c4123e3..2a5c163aaeb 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -292,7 +292,6 @@ static void create_mesh_volume_attribute(
VoxelAttribute *volume_data = attr->data_voxel();
ImageMetaData metadata;
bool animated = false;
- bool use_alpha = true;
volume_data->manager = image_manager;
volume_data->slot = image_manager->add_image(Attribute::standard_name(std),
@@ -301,7 +300,7 @@ static void create_mesh_volume_attribute(
frame,
INTERPOLATION_LINEAR,
EXTENSION_CLIP,
- use_alpha,
+ IMAGE_ALPHA_AUTO,
u_colorspace_raw,
metadata);
}
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index f42a15706e7..13097f6bf8e 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -90,6 +90,12 @@ template<typename NodeType> static ExtensionType get_image_extension(NodeType &b
return (ExtensionType)validate_enum_value(value, EXTENSION_NUM_TYPES, EXTENSION_REPEAT);
}
+static ImageAlphaType get_image_alpha_type(BL::Image &b_image)
+{
+ int value = b_image.alpha_mode();
+ return (ImageAlphaType)validate_enum_value(value, IMAGE_ALPHA_NUM_TYPES, IMAGE_ALPHA_AUTO);
+}
+
/* Graph */
static BL::NodeSocket get_node_output(BL::Node &b_node, const string &name)
@@ -655,7 +661,7 @@ static ShaderNode *add_node(Scene *scene,
image->colorspace = get_enum_identifier(colorspace_ptr, "name");
image->animated = b_image_node.image_user().use_auto_refresh();
- image->use_alpha = b_image.use_alpha();
+ image->alpha_type = get_image_alpha_type(b_image);
/* TODO: restore */
/* TODO(sergey): Does not work properly when we change builtin type. */
@@ -703,7 +709,7 @@ static ShaderNode *add_node(Scene *scene,
env->colorspace = get_enum_identifier(colorspace_ptr, "name");
env->animated = b_env_node.image_user().use_auto_refresh();
- env->use_alpha = b_image.use_alpha();
+ env->alpha_type = get_image_alpha_type(b_image);
/* TODO: restore */
/* TODO(sergey): Does not work properly when we change builtin type. */
@@ -868,7 +874,7 @@ static ShaderNode *add_node(Scene *scene,
point_density->builtin_data,
point_density->interpolation,
EXTENSION_CLIP,
- true,
+ IMAGE_ALPHA_AUTO,
u_colorspace_raw);
}
node = point_density;
diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp
index 6301b416724..160e7d9ff1e 100644
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@ -299,12 +299,12 @@ static bool image_equals(ImageManager::Image *image,
void *builtin_data,
InterpolationType interpolation,
ExtensionType extension,
- bool use_alpha,
+ ImageAlphaType alpha_type,
ustring colorspace)
{
return image->filename == filename && image->builtin_data == builtin_data &&
image->interpolation == interpolation && image->extension == extension &&
- image->use_alpha == use_alpha && image->colorspace == colorspace;
+ image->alpha_type == alpha_type && image->colorspace == colorspace;
}
int ImageManager::add_image(const string &filename,
@@ -313,7 +313,7 @@ int ImageManager::add_image(const string &filename,
float frame,
InterpolationType interpolation,
ExtensionType extension,
- bool use_alpha,
+ ImageAlphaType alpha_type,
ustring colorspace,
ImageMetaData &metadata)
{
@@ -338,14 +338,15 @@ int ImageManager::add_image(const string &filename,
/* Fnd existing image. */
for (slot = 0; slot < images[type].size(); slot++) {
img = images[type][slot];
- if (img && image_equals(
- img, filename, builtin_data, interpolation, extension, use_alpha, colorspace)) {
+ if (img &&
+ image_equals(
+ img, filename, builtin_data, interpolation, extension, alpha_type, colorspace)) {
if (img->frame != frame) {
img->frame = frame;
img->need_load = true;
}
- if (img->use_alpha != use_alpha) {
- img->use_alpha = use_alpha;
+ if (img->alpha_type != alpha_type) {
+ img->alpha_type = alpha_type;
img->need_load = true;
}
if (img->colorspace != colorspace) {
@@ -399,7 +400,7 @@ int ImageManager::add_image(const string &filename,
img->interpolation = interpolation;
img->extension = extension;
img->users = 1;
- img->use_alpha = use_alpha;
+ img->alpha_type = alpha_type;
img->colorspace = colorspace;
img->mem = NULL;
@@ -445,7 +446,7 @@ void ImageManager::remove_image(const string &filename,
void *builtin_data,
InterpolationType interpolation,
ExtensionType extension,
- bool use_alpha,
+ ImageAlphaType alpha_type,
ustring colorspace)
{
size_t slot;
@@ -457,7 +458,7 @@ void ImageManager::remove_image(const string &filename,
builtin_data,
interpolation,
extension,
- use_alpha,
+ alpha_type,
colorspace)) {
remove_image(type_index_to_flattened_slot(slot, (ImageDataType)type));
return;
@@ -474,7 +475,7 @@ void ImageManager::tag_reload_image(const string &filename,
void *builtin_data,
InterpolationType interpolation,
ExtensionType extension,
- bool use_alpha,
+ ImageAlphaType alpha_type,
ustring colorspace)
{
for (size_t type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
@@ -484,7 +485,7 @@ void ImageManager::tag_reload_image(const string &filename,
builtin_data,
interpolation,
extension,
- use_alpha,
+ alpha_type,
colorspace)) {
images[type][slot]->need_load = true;
break;
@@ -516,7 +517,8 @@ bool ImageManager::file_load_image_generic(Image *img, unique_ptr<ImageInput> *i
/* For typical RGBA images we let OIIO convert to associated alpha,
* but some types we want to leave the RGB channels untouched. */
const bool associate_alpha = !(ColorSpaceManager::colorspace_is_data(img->colorspace) ||
- img->use_alpha == false);
+ img->alpha_type == IMAGE_ALPHA_IGNORE ||
+ img->alpha_type == IMAGE_ALPHA_CHANNEL_PACKED);
if (!associate_alpha) {
config.attribute("oiio:UnassociatedAlpha", 1);
@@ -692,7 +694,7 @@ bool ImageManager::file_load_image(Image *img,
}
/* Disable alpha if requested by the user. */
- if (img->use_alpha == false) {
+ if (img->alpha_type == IMAGE_ALPHA_IGNORE) {
for (size_t i = num_pixels - 1, pixel = 0; pixel < num_pixels; pixel++, i--) {
pixels[i * 4 + 3] = one;
}
diff --git a/intern/cycles/render/image.h b/intern/cycles/render/image.h
index 70d7fd3632d..ed2780f8471 100644
--- a/intern/cycles/render/image.h
+++ b/intern/cycles/render/image.h
@@ -83,7 +83,7 @@ class ImageManager {
float frame,
InterpolationType interpolation,
ExtensionType extension,
- bool use_alpha,
+ ImageAlphaType alpha_type,
ustring colorspace,
ImageMetaData &metadata);
void add_image_user(int flat_slot);
@@ -92,13 +92,13 @@ class ImageManager {
void *builtin_data,
InterpolationType interpolation,
ExtensionType extension,
- bool use_alpha,
+ ImageAlphaType alpha_type,
ustring colorspace);
void tag_reload_image(const string &filename,
void *builtin_data,
InterpolationType interpolation,
ExtensionType extension,
- bool use_alpha,
+ ImageAlphaType alpha_type,
ustring colorspace);
bool get_image_metadata(const string &filename,
void *builtin_data,
@@ -147,7 +147,7 @@ class ImageManager {
ImageMetaData metadata;
ustring colorspace;
- bool use_alpha;
+ ImageAlphaType alpha_type;
bool need_load;
bool animated;
float frame;
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 3905189c8b0..c5b0f6a1e79 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -210,7 +210,13 @@ NODE_DEFINE(ImageTextureNode)
SOCKET_STRING(filename, "Filename", ustring());
SOCKET_STRING(colorspace, "Colorspace", u_colorspace_auto);
- SOCKET_BOOLEAN(use_alpha, "Use Alpha", true);
+ static NodeEnum alpha_type_enum;
+ alpha_type_enum.insert("auto", IMAGE_ALPHA_AUTO);
+ alpha_type_enum.insert("unassociated", IMAGE_ALPHA_UNASSOCIATED);
+ alpha_type_enum.insert("associated", IMAGE_ALPHA_ASSOCIATED);
+ alpha_type_enum.insert("channel_packed", IMAGE_ALPHA_CHANNEL_PACKED);
+ alpha_type_enum.insert("ignore", IMAGE_ALPHA_IGNORE);
+ SOCKET_ENUM(alpha_type, "Alpha Type", alpha_type_enum, IMAGE_ALPHA_AUTO);
static NodeEnum interpolation_enum;
interpolation_enum.insert("closest", INTERPOLATION_CLOSEST);
@@ -257,7 +263,7 @@ ImageTextureNode::~ImageTextureNode()
{
if (image_manager) {
image_manager->remove_image(
- filename.string(), builtin_data, interpolation, extension, use_alpha, colorspace);
+ filename.string(), builtin_data, interpolation, extension, alpha_type, colorspace);
}
}
@@ -300,12 +306,12 @@ void ImageTextureNode::compile(SVMCompiler &compiler)
0,
interpolation,
extension,
- use_alpha,
+ alpha_type,
colorspace,
metadata);
is_float = metadata.is_float;
compress_as_srgb = metadata.compress_as_srgb;
- colorspace = metadata.colorspace;
+ known_colorspace = metadata.colorspace;
}
if (slot != -1) {
@@ -317,7 +323,8 @@ void ImageTextureNode::compile(SVMCompiler &compiler)
}
if (!alpha_out->links.empty()) {
const bool unassociate_alpha = !(ColorSpaceManager::colorspace_is_data(colorspace) ||
- use_alpha == false);
+ alpha_type == IMAGE_ALPHA_CHANNEL_PACKED ||
+ alpha_type == IMAGE_ALPHA_IGNORE);
if (unassociate_alpha) {
flags |= NODE_IMAGE_ALPHA_UNASSOCIATE;
@@ -378,29 +385,30 @@ void ImageTextureNode::compile(OSLCompiler &compiler)
0,
interpolation,
extension,
- use_alpha,
+ alpha_type,
colorspace,
metadata);
}
is_float = metadata.is_float;
compress_as_srgb = metadata.compress_as_srgb;
- colorspace = metadata.colorspace;
+ known_colorspace = metadata.colorspace;
}
if (slot == -1) {
- compiler.parameter_texture("filename", filename, colorspace);
+ compiler.parameter_texture("filename", filename, known_colorspace);
}
else {
compiler.parameter_texture("filename", slot);
}
const bool unassociate_alpha = !(ColorSpaceManager::colorspace_is_data(colorspace) ||
- use_alpha == false);
+ alpha_type == IMAGE_ALPHA_CHANNEL_PACKED ||
+ alpha_type == IMAGE_ALPHA_IGNORE);
compiler.parameter(this, "projection");
compiler.parameter(this, "projection_blend");
- compiler.parameter("convert_from_srgb", compress_as_srgb);
- compiler.parameter("ignore_alpha", !use_alpha);
+ compiler.parameter("compress_as_srgb", compress_as_srgb);
+ compiler.parameter("ignore_alpha", alpha_type == IMAGE_ALPHA_IGNORE);
compiler.parameter("unassociate_alpha", !alpha_out->links.empty() && unassociate_alpha);
compiler.parameter("is_float", is_float);
compiler.parameter(this, "interpolation");
@@ -420,7 +428,13 @@ NODE_DEFINE(EnvironmentTextureNode)
SOCKET_STRING(filename, "Filename", ustring());
SOCKET_STRING(colorspace, "Colorspace", u_colorspace_auto);
- SOCKET_BOOLEAN(use_alpha, "Use Alpha", true);
+ static NodeEnum alpha_type_enum;
+ alpha_type_enum.insert("auto", IMAGE_ALPHA_AUTO);
+ alpha_type_enum.insert("unassociated", IMAGE_ALPHA_UNASSOCIATED);
+ alpha_type_enum.insert("associated", IMAGE_ALPHA_ASSOCIATED);
+ alpha_type_enum.insert("channel_packed", IMAGE_ALPHA_CHANNEL_PACKED);
+ alpha_type_enum.insert("ignore", IMAGE_ALPHA_IGNORE);
+ SOCKET_ENUM(alpha_type, "Alpha Type", alpha_type_enum, IMAGE_ALPHA_AUTO);
static NodeEnum interpolation_enum;
interpolation_enum.insert("closest", INTERPOLATION_CLOSEST);
@@ -457,7 +471,7 @@ EnvironmentTextureNode::~EnvironmentTextureNode()
{
if (image_manager) {
image_manager->remove_image(
- filename.string(), builtin_data, interpolation, EXTENSION_REPEAT, use_alpha, colorspace);
+ filename.string(), builtin_data, interpolation, EXTENSION_REPEAT, alpha_type, colorspace);
}
}
@@ -498,12 +512,12 @@ void EnvironmentTextureNode::compile(SVMCompiler &compiler)
0,
interpolation,
EXTENSION_REPEAT,
- use_alpha,
+ alpha_type,
colorspace,
metadata);
is_float = metadata.is_float;
compress_as_srgb = metadata.compress_as_srgb;
- colorspace = metadata.colorspace;
+ known_colorspace = metadata.colorspace;
}
if (slot != -1) {
@@ -558,17 +572,17 @@ void EnvironmentTextureNode::compile(OSLCompiler &compiler)
0,
interpolation,
EXTENSION_REPEAT,
- use_alpha,
+ alpha_type,
colorspace,
metadata);
}
is_float = metadata.is_float;
compress_as_srgb = metadata.compress_as_srgb;
- colorspace = metadata.colorspace;
+ known_colorspace = metadata.colorspace;
}
if (slot == -1) {
- compiler.parameter_texture("filename", filename, colorspace);
+ compiler.parameter_texture("filename", filename, known_colorspace);
}
else {
compiler.parameter_texture("filename", slot);
@@ -576,8 +590,8 @@ void EnvironmentTextureNode::compile(OSLCompiler &compiler)
compiler.parameter(this, "projection");
compiler.parameter(this, "interpolation");
- compiler.parameter("convert_from_srgb", compress_as_srgb);
- compiler.parameter("ignore_alpha", !use_alpha);
+ compiler.parameter("compress_as_srgb", compress_as_srgb);
+ compiler.parameter("ignore_alpha", alpha_type == IMAGE_ALPHA_IGNORE);
compiler.parameter("is_float", is_float);
compiler.add(this, "node_environment_texture");
}
@@ -1490,8 +1504,12 @@ PointDensityTextureNode::PointDensityTextureNode() : ShaderNode(node_type)
PointDensityTextureNode::~PointDensityTextureNode()
{
if (image_manager) {
- image_manager->remove_image(
- filename.string(), builtin_data, interpolation, EXTENSION_CLIP, true, ustring());
+ image_manager->remove_image(filename.string(),
+ builtin_data,
+ interpolation,
+ EXTENSION_CLIP,
+ IMAGE_ALPHA_AUTO,
+ ustring());
}
}
@@ -1524,7 +1542,7 @@ void PointDensityTextureNode::add_image()
0,
interpolation,
EXTENSION_CLIP,
- true,
+ IMAGE_ALPHA_AUTO,
u_colorspace_raw,
metadata);
}
diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h
index 3dd84ad8dca..6b21be88663 100644
--- a/intern/cycles/render/nodes.h
+++ b/intern/cycles/render/nodes.h
@@ -100,10 +100,10 @@ class ImageTextureNode : public ImageSlotTextureNode {
}
/* Parameters. */
- bool use_alpha;
ustring filename;
void *builtin_data;
ustring colorspace;
+ ImageAlphaType alpha_type;
NodeImageProjection projection;
InterpolationType interpolation;
ExtensionType extension;
@@ -141,10 +141,10 @@ class EnvironmentTextureNode : public ImageSlotTextureNode {
}
/* Parameters. */
- bool use_alpha;
ustring filename;
void *builtin_data;
ustring colorspace;
+ ImageAlphaType alpha_type;
NodeEnvironmentProjection projection;
InterpolationType interpolation;
bool animated;
diff --git a/intern/cycles/util/util_texture.h b/intern/cycles/util/util_texture.h
index 5ce16e0095a..d43852480d1 100644
--- a/intern/cycles/util/util_texture.h
+++ b/intern/cycles/util/util_texture.h
@@ -59,6 +59,18 @@ typedef enum ImageDataType {
IMAGE_DATA_NUM_TYPES
} ImageDataType;
+/* Alpha types
+ * How to treat alpha in images. */
+typedef enum ImageAlphaType {
+ IMAGE_ALPHA_UNASSOCIATED = 0,
+ IMAGE_ALPHA_ASSOCIATED = 1,
+ IMAGE_ALPHA_CHANNEL_PACKED = 2,
+ IMAGE_ALPHA_IGNORE = 3,
+ IMAGE_ALPHA_AUTO = 4,
+
+ IMAGE_ALPHA_NUM_TYPES,
+} ImageAlphaType;
+
#define IMAGE_DATA_TYPE_SHIFT 3
#define IMAGE_DATA_TYPE_MASK 0x7