diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-02-28 02:08:16 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-02-28 02:08:16 +0300 |
commit | 11100faa5cfbeb735194c6d2d5ed951dc5ae063a (patch) | |
tree | c27c2047640aa4773ea7953ee8bed06d7bec4a30 /intern | |
parent | bc71aa5a4c5e0ce961803d7d0b7649ad6d384006 (diff) | |
parent | 2eb94be7503f0931d02a65243ae116d7879faa9c (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/blender/blender_mesh.cpp | 8 | ||||
-rw-r--r-- | intern/cycles/blender/blender_session.cpp | 55 | ||||
-rw-r--r-- | intern/cycles/blender/blender_session.h | 8 | ||||
-rw-r--r-- | intern/cycles/render/image.cpp | 151 | ||||
-rw-r--r-- | intern/cycles/render/image.h | 32 | ||||
-rw-r--r-- | intern/cycles/render/nodes.cpp | 64 |
6 files changed, 158 insertions, 160 deletions
diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp index 9c8d317e6de..77819d2a9a8 100644 --- a/intern/cycles/blender/blender_mesh.cpp +++ b/intern/cycles/blender/blender_mesh.cpp @@ -337,8 +337,9 @@ static void create_mesh_volume_attribute(BL::Object& b_ob, Attribute *attr = mesh->attributes.add(std); VoxelAttribute *volume_data = attr->data_voxel(); - bool is_float, is_linear; + ImageMetaData metadata; bool animated = false; + bool use_alpha = true; volume_data->manager = image_manager; volume_data->slot = image_manager->add_image( @@ -346,11 +347,10 @@ static void create_mesh_volume_attribute(BL::Object& b_ob, b_ob.ptr.data, animated, frame, - is_float, - is_linear, INTERPOLATION_LINEAR, EXTENSION_CLIP, - true); + use_alpha, + metadata); } static void create_mesh_volume_attributes(Scene *scene, diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp index 86a0baf59ea..12b707d8f95 100644 --- a/intern/cycles/blender/blender_session.cpp +++ b/intern/cycles/blender/blender_session.cpp @@ -135,7 +135,7 @@ void BlenderSession::create_session() scene = new Scene(scene_params, session->device); /* setup callbacks for builtin image support */ - scene->image_manager->builtin_image_info_cb = function_bind(&BlenderSession::builtin_image_info, this, _1, _2, _3, _4, _5, _6, _7, _8); + scene->image_manager->builtin_image_info_cb = function_bind(&BlenderSession::builtin_image_info, this, _1, _2, _3); scene->image_manager->builtin_image_pixels_cb = function_bind(&BlenderSession::builtin_image_pixels, this, _1, _2, _3, _4, _5); scene->image_manager->builtin_image_float_pixels_cb = function_bind(&BlenderSession::builtin_image_float_pixels, this, _1, _2, _3, _4, _5); @@ -997,20 +997,11 @@ int BlenderSession::builtin_image_frame(const string &builtin_name) void BlenderSession::builtin_image_info(const string &builtin_name, void *builtin_data, - bool &is_float, - int &width, - int &height, - int &depth, - int &channels, - bool& free_cache) + ImageMetaData& metadata) { /* empty image */ - is_float = false; - width = 1; - height = 1; - depth = 0; - channels = 0; - free_cache = false; + metadata.width = 1; + metadata.height = 1; if(!builtin_data) return; @@ -1024,21 +1015,21 @@ void BlenderSession::builtin_image_info(const string &builtin_name, /* image data */ BL::Image b_image(b_id); - free_cache = !b_image.has_data(); - is_float = b_image.is_float(); - width = b_image.size()[0]; - height = b_image.size()[1]; - depth = 1; - channels = b_image.channels(); + metadata.builtin_free_cache = !b_image.has_data(); + metadata.is_float = b_image.is_float(); + metadata.width = b_image.size()[0]; + metadata.height = b_image.size()[1]; + metadata.depth = 1; + metadata.channels = b_image.channels(); } else if(b_id.is_a(&RNA_Object)) { /* smoke volume data */ BL::Object b_ob(b_id); BL::SmokeDomainSettings b_domain = object_smoke_domain_find(b_ob); - is_float = true; - depth = 1; - channels = 1; + metadata.is_float = true; + metadata.depth = 1; + metadata.channels = 1; if(!b_domain) return; @@ -1047,11 +1038,11 @@ void BlenderSession::builtin_image_info(const string &builtin_name, builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_FLAME) || builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_HEAT) || builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_TEMPERATURE)) - channels = 1; + metadata.channels = 1; else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_COLOR)) - channels = 4; + metadata.channels = 4; else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_VELOCITY)) - channels = 3; + metadata.channels = 3; else return; @@ -1065,9 +1056,9 @@ void BlenderSession::builtin_image_info(const string &builtin_name, amplify = 1; } - width = resolution.x * amplify; - height = resolution.y * amplify; - depth = resolution.z * amplify; + metadata.width = resolution.x * amplify; + metadata.height = resolution.y * amplify; + metadata.depth = resolution.z * amplify; } else { /* TODO(sergey): Check we're indeed in shader node tree. */ @@ -1076,9 +1067,11 @@ void BlenderSession::builtin_image_info(const string &builtin_name, BL::Node b_node(ptr); if(b_node.is_a(&RNA_ShaderNodeTexPointDensity)) { BL::ShaderNodeTexPointDensity b_point_density_node(b_node); - channels = 4; - width = height = depth = b_point_density_node.resolution(); - is_float = true; + metadata.channels = 4; + metadata.width = b_point_density_node.resolution(); + metadata.height = metadata.width; + metadata.depth = metadata.width; + metadata.is_float = true; } } } diff --git a/intern/cycles/blender/blender_session.h b/intern/cycles/blender/blender_session.h index bd71087c16a..77a64031da1 100644 --- a/intern/cycles/blender/blender_session.h +++ b/intern/cycles/blender/blender_session.h @@ -26,6 +26,7 @@ CCL_NAMESPACE_BEGIN +class ImageMetaData; class Scene; class Session; class RenderBuffers; @@ -153,12 +154,7 @@ protected: int builtin_image_frame(const string &builtin_name); void builtin_image_info(const string &builtin_name, void *builtin_data, - bool &is_float, - int &width, - int &height, - int &depth, - int &channels, - bool &free_cache); + ImageMetaData& metadata); bool builtin_image_pixels(const string &builtin_name, void *builtin_data, unsigned char *pixels, diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp index dbe15a67b9e..de46599e1db 100644 --- a/intern/cycles/render/image.cpp +++ b/intern/cycles/render/image.cpp @@ -84,99 +84,109 @@ bool ImageManager::set_animation_frame_update(int frame) return false; } -ImageDataType ImageManager::get_image_metadata(const string& filename, - void *builtin_data, - bool& is_linear, - bool& builtin_free_cache) +bool ImageManager::get_image_metadata(const string& filename, + void *builtin_data, + ImageMetaData& metadata) { - bool is_float = false, is_half = false; - is_linear = false; - builtin_free_cache = false; - int channels = 4; + memset(&metadata, 0, sizeof(metadata)); if(builtin_data) { if(builtin_image_info_cb) { - int width, height, depth; - builtin_image_info_cb(filename, builtin_data, is_float, width, height, depth, channels, builtin_free_cache); + builtin_image_info_cb(filename, builtin_data, metadata); + } + else { + return false; } - if(is_float) { - is_linear = true; - return (channels > 1) ? IMAGE_DATA_TYPE_FLOAT4 : IMAGE_DATA_TYPE_FLOAT; + if(metadata.is_float) { + metadata.is_linear = true; + metadata.type = (metadata.channels > 1) ? IMAGE_DATA_TYPE_FLOAT4 : IMAGE_DATA_TYPE_FLOAT; } else { - return (channels > 1) ? IMAGE_DATA_TYPE_BYTE4 : IMAGE_DATA_TYPE_BYTE; + metadata.type = (metadata.channels > 1) ? IMAGE_DATA_TYPE_BYTE4 : IMAGE_DATA_TYPE_BYTE; } + + return true; } /* Perform preliminary checks, with meaningful logging. */ if(!path_exists(filename)) { VLOG(1) << "File '" << filename << "' does not exist."; - return IMAGE_DATA_TYPE_BYTE4; + return false; } if(path_is_directory(filename)) { VLOG(1) << "File '" << filename << "' is a directory, can't use as image."; - return IMAGE_DATA_TYPE_BYTE4; + return false; } ImageInput *in = ImageInput::create(filename); - if(in) { - ImageSpec spec; - - if(in->open(filename, spec)) { - /* check the main format, and channel formats; - * if any take up more than one byte, we'll need a float texture slot */ - if(spec.format.basesize() > 1) { - is_float = true; - is_linear = true; - } + if(!in) { + return false; + } - for(size_t channel = 0; channel < spec.channelformats.size(); channel++) { - if(spec.channelformats[channel].basesize() > 1) { - is_float = true; - is_linear = true; - } - } + ImageSpec spec; + if(!in->open(filename, spec)) { + delete in; + return false; + } - /* check if it's half float */ - if(spec.format == TypeDesc::HALF) - is_half = true; + metadata.width = spec.width; + metadata.height = spec.height; + metadata.depth = spec.depth; - channels = spec.nchannels; + /* check the main format, and channel formats; + * if any take up more than one byte, we'll need a float texture slot */ + if(spec.format.basesize() > 1) { + metadata.is_float = true; + metadata.is_linear = true; + } - /* basic color space detection, not great but better than nothing - * before we do OpenColorIO integration */ - if(is_float) { - string colorspace = spec.get_string_attribute("oiio:ColorSpace"); + for(size_t channel = 0; channel < spec.channelformats.size(); channel++) { + if(spec.channelformats[channel].basesize() > 1) { + metadata.is_float = true; + metadata.is_linear = true; + } + } - is_linear = !(colorspace == "sRGB" || - colorspace == "GammaCorrected" || - (colorspace == "" && - (strcmp(in->format_name(), "png") == 0 || - strcmp(in->format_name(), "tiff") == 0 || - strcmp(in->format_name(), "dpx") == 0 || - strcmp(in->format_name(), "jpeg2000") == 0))); - } - else { - is_linear = false; - } + /* check if it's half float */ + if(spec.format == TypeDesc::HALF) + metadata.is_half = true; - in->close(); - } + /* basic color space detection, not great but better than nothing + * before we do OpenColorIO integration */ + if(metadata.is_float) { + string colorspace = spec.get_string_attribute("oiio:ColorSpace"); - delete in; + metadata.is_linear = !(colorspace == "sRGB" || + colorspace == "GammaCorrected" || + (colorspace == "" && + (strcmp(in->format_name(), "png") == 0 || + strcmp(in->format_name(), "tiff") == 0 || + strcmp(in->format_name(), "dpx") == 0 || + strcmp(in->format_name(), "jpeg2000") == 0))); } + else { + metadata.is_linear = false; + } + + /* set type and channels */ + metadata.channels = spec.nchannels; - if(is_half) { - return (channels > 1) ? IMAGE_DATA_TYPE_HALF4 : IMAGE_DATA_TYPE_HALF; + if(metadata.is_half) { + metadata.type = (metadata.channels > 1) ? IMAGE_DATA_TYPE_HALF4 : IMAGE_DATA_TYPE_HALF; } - else if(is_float) { - return (channels > 1) ? IMAGE_DATA_TYPE_FLOAT4 : IMAGE_DATA_TYPE_FLOAT; + else if(metadata.is_float) { + metadata.type = (metadata.channels > 1) ? IMAGE_DATA_TYPE_FLOAT4 : IMAGE_DATA_TYPE_FLOAT; } else { - return (channels > 1) ? IMAGE_DATA_TYPE_BYTE4 : IMAGE_DATA_TYPE_BYTE; + metadata.type = (metadata.channels > 1) ? IMAGE_DATA_TYPE_BYTE4 : IMAGE_DATA_TYPE_BYTE; } + + in->close(); + delete in; + + return true; } int ImageManager::max_flattened_slot(ImageDataType type) @@ -237,23 +247,19 @@ int ImageManager::add_image(const string& filename, void *builtin_data, bool animated, float frame, - bool& is_float, - bool& is_linear, InterpolationType interpolation, ExtensionType extension, - bool use_alpha) + bool use_alpha, + ImageMetaData& metadata) { Image *img; size_t slot; - bool builtin_free_cache; - ImageDataType type = get_image_metadata(filename, builtin_data, is_linear, builtin_free_cache); + get_image_metadata(filename, builtin_data, metadata); + ImageDataType type = metadata.type; thread_scoped_lock device_lock(device_mutex); - /* Check whether it's a float texture. */ - is_float = (type == IMAGE_DATA_TYPE_FLOAT || type == IMAGE_DATA_TYPE_FLOAT4); - /* No half textures on OpenCL, use full float instead. */ if(!has_half_images) { if(type == IMAGE_DATA_TYPE_HALF4) { @@ -313,7 +319,7 @@ int ImageManager::add_image(const string& filename, img = new Image(); img->filename = filename; img->builtin_data = builtin_data; - img->builtin_free_cache = builtin_free_cache; + img->builtin_free_cache = metadata.builtin_free_cache; img->need_load = true; img->animated = animated; img->frame = frame; @@ -444,8 +450,13 @@ bool ImageManager::file_load_image_generic(Image *img, if(!builtin_image_info_cb || !builtin_image_pixels_cb) return false; - bool is_float, free_cache; - builtin_image_info_cb(img->filename, img->builtin_data, is_float, width, height, depth, components, free_cache); + ImageMetaData metadata; + builtin_image_info_cb(img->filename, img->builtin_data, metadata); + + width = metadata.width; + height = metadata.height; + depth = metadata.depth; + components = metadata.channels; } /* we only handle certain number of components */ diff --git a/intern/cycles/render/image.h b/intern/cycles/render/image.h index 6fca3ca20d3..989416e089a 100644 --- a/intern/cycles/render/image.h +++ b/intern/cycles/render/image.h @@ -31,6 +31,19 @@ class Device; class Progress; class Scene; +class ImageMetaData { +public: + /* Must be set by image file or builtin callback. */ + bool is_float, is_half; + int channels; + size_t width, height, depth; + bool builtin_free_cache; + + /* Automatically set. */ + ImageDataType type; + bool is_linear; +}; + class ImageManager { public: explicit ImageManager(const DeviceInfo& info); @@ -40,11 +53,10 @@ public: void *builtin_data, bool animated, float frame, - bool& is_float, - bool& is_linear, InterpolationType interpolation, ExtensionType extension, - bool use_alpha); + bool use_alpha, + ImageMetaData& metadata); void remove_image(int flat_slot); void remove_image(const string& filename, void *builtin_data, @@ -56,10 +68,9 @@ public: InterpolationType interpolation, ExtensionType extension, bool use_alpha); - ImageDataType get_image_metadata(const string& filename, - void *builtin_data, - bool& is_linear, - bool& builtin_free_cache); + bool get_image_metadata(const string& filename, + void *builtin_data, + ImageMetaData& metadata); void device_update(Device *device, Scene *scene, @@ -82,12 +93,7 @@ public: */ function<void(const string &filename, void *data, - bool &is_float, - int &width, - int &height, - int &depth, - int &channels, - bool &free_cache)> builtin_image_info_cb; + ImageMetaData& metadata)> builtin_image_info_cb; function<bool(const string &filename, void *data, unsigned char *pixels, diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 7006fb6fe1d..41c9730e6fb 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -302,17 +302,17 @@ void ImageTextureNode::compile(SVMCompiler& compiler) image_manager = compiler.image_manager; if(is_float == -1) { - bool is_float_bool; + ImageMetaData metadata; slot = image_manager->add_image(filename.string(), builtin_data, animated, 0, - is_float_bool, - is_linear, interpolation, extension, - use_alpha); - is_float = (int)is_float_bool; + use_alpha, + metadata); + is_float = metadata.is_float; + is_linear = metadata.is_linear; } if(slot != -1) { @@ -363,26 +363,22 @@ void ImageTextureNode::compile(OSLCompiler& compiler) image_manager = compiler.image_manager; if(is_float == -1) { + ImageMetaData metadata; if(builtin_data == NULL) { - ImageDataType type; - bool builtin_free_cache; - type = image_manager->get_image_metadata(filename.string(), NULL, is_linear, builtin_free_cache); - if(type == IMAGE_DATA_TYPE_FLOAT || type == IMAGE_DATA_TYPE_FLOAT4) - is_float = 1; + image_manager->get_image_metadata(filename.string(), NULL, metadata); } else { - bool is_float_bool; slot = image_manager->add_image(filename.string(), builtin_data, animated, 0, - is_float_bool, - is_linear, interpolation, extension, - use_alpha); - is_float = (int)is_float_bool; + use_alpha, + metadata); } + is_float = metadata.is_float; + is_linear = metadata.is_linear; } if(slot == -1) { @@ -501,17 +497,17 @@ void EnvironmentTextureNode::compile(SVMCompiler& compiler) image_manager = compiler.image_manager; if(slot == -1) { - bool is_float_bool; + ImageMetaData metadata; slot = image_manager->add_image(filename.string(), builtin_data, animated, 0, - is_float_bool, - is_linear, interpolation, EXTENSION_REPEAT, - use_alpha); - is_float = (int)is_float_bool; + use_alpha, + metadata); + is_float = metadata.is_float; + is_linear = metadata.is_linear; } if(slot != -1) { @@ -553,26 +549,22 @@ void EnvironmentTextureNode::compile(OSLCompiler& compiler) */ image_manager = compiler.image_manager; if(is_float == -1) { + ImageMetaData metadata; if(builtin_data == NULL) { - ImageDataType type; - bool builtin_free_cache; - type = image_manager->get_image_metadata(filename.string(), NULL, is_linear, builtin_free_cache); - if(type == IMAGE_DATA_TYPE_FLOAT || type == IMAGE_DATA_TYPE_FLOAT4) - is_float = 1; + image_manager->get_image_metadata(filename.string(), NULL, metadata); } else { - bool is_float_bool; slot = image_manager->add_image(filename.string(), builtin_data, animated, 0, - is_float_bool, - is_linear, interpolation, EXTENSION_REPEAT, - use_alpha); - is_float = (int)is_float_bool; + use_alpha, + metadata); } + is_float = metadata.is_float; + is_linear = metadata.is_linear; } if(slot == -1) { @@ -1421,13 +1413,13 @@ void PointDensityTextureNode::compile(SVMCompiler& compiler) if(use_density || use_color) { if(slot == -1) { - bool is_float, is_linear; + ImageMetaData metadata; slot = image_manager->add_image(filename.string(), builtin_data, false, 0, - is_float, is_linear, interpolation, EXTENSION_CLIP, - true); + true, + metadata); } if(slot != -1) { @@ -1473,13 +1465,13 @@ void PointDensityTextureNode::compile(OSLCompiler& compiler) if(use_density || use_color) { if(slot == -1) { - bool is_float, is_linear; + ImageMetaData metadata; slot = image_manager->add_image(filename.string(), builtin_data, false, 0, - is_float, is_linear, interpolation, EXTENSION_CLIP, - true); + true, + metadata); } if(slot != -1) { |