diff options
author | Lukas Stockner <lukas.stockner@freenet.de> | 2019-12-12 18:06:08 +0300 |
---|---|---|
committer | Lukas Stockner <lukas.stockner@freenet.de> | 2019-12-12 20:40:37 +0300 |
commit | c30d6571bb47734e0bcb2fced5cf11cb6d8b1169 (patch) | |
tree | f92f065147296e6c72e6cd85f26711157d81e09c /intern/cycles/blender | |
parent | d7a8a606889fed58775c88bfdc079bee3c9333e2 (diff) |
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
Diffstat (limited to 'intern/cycles/blender')
-rw-r--r-- | intern/cycles/blender/blender_session.cpp | 10 | ||||
-rw-r--r-- | intern/cycles/blender/blender_session.h | 2 | ||||
-rw-r--r-- | intern/cycles/blender/blender_shader.cpp | 6 | ||||
-rw-r--r-- | intern/cycles/blender/blender_sync.cpp | 3 | ||||
-rw-r--r-- | intern/cycles/blender/blender_util.h | 19 |
5 files changed, 30 insertions, 10 deletions
diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp index 53f2fdb91b9..78fb49db6c8 100644 --- a/intern/cycles/blender/blender_session.cpp +++ b/intern/cycles/blender/blender_session.cpp @@ -142,9 +142,9 @@ void BlenderSession::create_session() 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, _6); + &BlenderSession::builtin_image_pixels, this, _1, _2, _3, _4, _5, _6, _7); scene->image_manager->builtin_image_float_pixels_cb = function_bind( - &BlenderSession::builtin_image_float_pixels, this, _1, _2, _3, _4, _5, _6); + &BlenderSession::builtin_image_float_pixels, this, _1, _2, _3, _4, _5, _6, _7); session->scene = scene; @@ -1210,6 +1210,7 @@ void BlenderSession::builtin_image_info(const string &builtin_name, bool BlenderSession::builtin_image_pixels(const string &builtin_name, void *builtin_data, + int tile, unsigned char *pixels, const size_t pixels_size, const bool associate_alpha, @@ -1229,7 +1230,7 @@ bool BlenderSession::builtin_image_pixels(const string &builtin_name, const int height = b_image.size()[1]; const int channels = b_image.channels(); - unsigned char *image_pixels = image_get_pixels_for_frame(b_image, frame); + unsigned char *image_pixels = image_get_pixels_for_frame(b_image, frame, tile); const size_t num_pixels = ((size_t)width) * height; if (image_pixels && num_pixels * channels == pixels_size) { @@ -1276,6 +1277,7 @@ bool BlenderSession::builtin_image_pixels(const string &builtin_name, bool BlenderSession::builtin_image_float_pixels(const string &builtin_name, void *builtin_data, + int tile, float *pixels, const size_t pixels_size, const bool, @@ -1299,7 +1301,7 @@ bool BlenderSession::builtin_image_float_pixels(const string &builtin_name, const int channels = b_image.channels(); float *image_pixels; - image_pixels = image_get_float_pixels_for_frame(b_image, frame); + image_pixels = image_get_float_pixels_for_frame(b_image, frame, tile); const size_t num_pixels = ((size_t)width) * height; if (image_pixels && num_pixels * channels == pixels_size) { diff --git a/intern/cycles/blender/blender_session.h b/intern/cycles/blender/blender_session.h index 7445fb53458..2f25ec740f9 100644 --- a/intern/cycles/blender/blender_session.h +++ b/intern/cycles/blender/blender_session.h @@ -157,12 +157,14 @@ class BlenderSession { void builtin_image_info(const string &builtin_name, void *builtin_data, ImageMetaData &metadata); bool builtin_image_pixels(const string &builtin_name, void *builtin_data, + int tile, unsigned char *pixels, const size_t pixels_size, const bool associate_alpha, const bool free_cache); bool builtin_image_float_pixels(const string &builtin_name, void *builtin_data, + int tile, float *pixels, const size_t pixels_size, const bool associate_alpha, diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index c3564eac940..6bbc73f72ec 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -665,6 +665,12 @@ static ShaderNode *add_node(Scene *scene, image->animated = b_image_node.image_user().use_auto_refresh(); image->alpha_type = get_image_alpha_type(b_image); + image->tiles.clear(); + BL::Image::tiles_iterator b_iter; + for (b_image.tiles.begin(b_iter); b_iter != b_image.tiles.end(); ++b_iter) { + image->tiles.push_back(b_iter->number()); + } + /* TODO: restore */ /* TODO(sergey): Does not work properly when we change builtin type. */ #if 0 diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp index bb52c740bfb..332ee3575c0 100644 --- a/intern/cycles/blender/blender_sync.cpp +++ b/intern/cycles/blender/blender_sync.cpp @@ -729,6 +729,9 @@ SceneParams BlenderSync::get_scene_params(BL::Scene &b_scene, bool background) params.bvh_layout = RNA_boolean_get(&cscene, "use_bvh_embree") ? BVH_LAYOUT_EMBREE : params.bvh_layout; #endif + + params.background = background; + return params; } diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h index cbe61e367fa..efed96ec9f5 100644 --- a/intern/cycles/blender/blender_util.h +++ b/intern/cycles/blender/blender_util.h @@ -34,8 +34,8 @@ extern "C" { void BKE_image_user_frame_calc(void *ima, void *iuser, int cfra); void BKE_image_user_file_path(void *iuser, void *ima, char *path); -unsigned char *BKE_image_get_pixels_for_frame(void *image, int frame); -float *BKE_image_get_float_pixels_for_frame(void *image, int frame); +unsigned char *BKE_image_get_pixels_for_frame(void *image, int frame, int tile); +float *BKE_image_get_float_pixels_for_frame(void *image, int frame, int tile); } CCL_NAMESPACE_BEGIN @@ -234,8 +234,15 @@ static inline int render_resolution_y(BL::RenderSettings &b_render) static inline string image_user_file_path(BL::ImageUser &iuser, BL::Image &ima, int cfra) { char filepath[1024]; + iuser.tile(0); BKE_image_user_frame_calc(NULL, iuser.ptr.data, cfra); BKE_image_user_file_path(iuser.ptr.data, ima.ptr.data, filepath); + if (ima.source() == BL::Image::source_TILED) { + char *udim_id = strstr(filepath, "1001"); + if (udim_id != NULL) { + memcpy(udim_id, "%04d", 4); + } + } return string(filepath); } @@ -245,14 +252,14 @@ static inline int image_user_frame_number(BL::ImageUser &iuser, int cfra) return iuser.frame_current(); } -static inline unsigned char *image_get_pixels_for_frame(BL::Image &image, int frame) +static inline unsigned char *image_get_pixels_for_frame(BL::Image &image, int frame, int tile) { - return BKE_image_get_pixels_for_frame(image.ptr.data, frame); + return BKE_image_get_pixels_for_frame(image.ptr.data, frame, tile); } -static inline float *image_get_float_pixels_for_frame(BL::Image &image, int frame) +static inline float *image_get_float_pixels_for_frame(BL::Image &image, int frame, int tile) { - return BKE_image_get_float_pixels_for_frame(image.ptr.data, frame); + return BKE_image_get_float_pixels_for_frame(image.ptr.data, frame, tile); } static inline void render_add_metadata(BL::RenderResult &b_rr, string name, string value) |