[Bf-blender-cvs] [7aaa7aa9dd7] master: Images: change alpha settings to support channel packing

Brecht Van Lommel noreply at git.blender.org
Sun May 19 14:37:44 CEST 2019


Commit: 7aaa7aa9dd79b8c6e37f351fd67a93ba07fbb883
Author: Brecht Van Lommel
Date:   Sat May 18 20:52:20 2019 +0200
Branches: master
https://developer.blender.org/rB7aaa7aa9dd79b8c6e37f351fd67a93ba07fbb883

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

===================================================================

M	intern/cycles/blender/blender_mesh.cpp
M	intern/cycles/blender/blender_shader.cpp
M	intern/cycles/render/image.cpp
M	intern/cycles/render/image.h
M	intern/cycles/render/nodes.cpp
M	intern/cycles/render/nodes.h
M	intern/cycles/util/util_texture.h
M	source/blender/blenkernel/BKE_blender_version.h
M	source/blender/blenkernel/intern/image.c
M	source/blender/blenloader/intern/versioning_260.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/editors/space_image/image_buttons.c
M	source/blender/imbuf/IMB_imbuf.h
M	source/blender/imbuf/IMB_imbuf_types.h
M	source/blender/imbuf/intern/colormanagement.c
M	source/blender/imbuf/intern/divers.c
M	source/blender/imbuf/intern/readimage.c
M	source/blender/makesdna/DNA_image_types.h
M	source/blender/makesrna/intern/rna_image.c
M	source/blender/nodes/shader/nodes/node_shader_tex_image.c
M	source/blender/render/intern/source/imagetexture.c

===================================================================

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)
  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list