[Bf-blender-cvs] [31ac2e292e5] master: Cycles: Fix one-tile UDIM rendering

Lukas Stockner noreply at git.blender.org
Mon Dec 16 04:10:29 CET 2019


Commit: 31ac2e292e5fc5d4d85d00d97645bfcb9cd4e6c2
Author: Lukas Stockner
Date:   Mon Dec 16 03:58:01 2019 +0100
Branches: master
https://developer.blender.org/rB31ac2e292e5fc5d4d85d00d97645bfcb9cd4e6c2

Cycles: Fix one-tile UDIM rendering

The code checked for the presence of more than one tile before
substituting the tile number into the filename, so if a one-tile
UDIM was used (or all but one tile were culled), the substitution
was skipped and as a result the file was not found.

With this change, the code explicitly tracks whether substitution
is required, avoiding this problem.

This also fixes another problem: The Environment texture never
does substitution since it doesn't support UDIMs, but before the
syncing code still inserted the placeholder into the filename if the
user selected a tiled background image.

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

M	intern/cycles/blender/blender_shader.cpp
M	intern/cycles/blender/blender_util.h
M	intern/cycles/render/nodes.cpp
M	intern/cycles/render/nodes.h

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

diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index 6bbc73f72ec..215953d1f29 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -655,7 +655,8 @@ static ShaderNode *add_node(Scene *scene,
         image->builtin_data = b_image.ptr.data;
       }
       else {
-        image->filename = image_user_file_path(b_image_user, b_image, b_scene.frame_current());
+        image->filename = image_user_file_path(
+            b_image_user, b_image, b_scene.frame_current(), &image->is_tiled);
         image->builtin_data = NULL;
       }
 
@@ -709,7 +710,7 @@ static ShaderNode *add_node(Scene *scene,
         env->builtin_data = b_image.ptr.data;
       }
       else {
-        env->filename = image_user_file_path(b_image_user, b_image, b_scene.frame_current());
+        env->filename = image_user_file_path(b_image_user, b_image, b_scene.frame_current(), NULL);
         env->builtin_data = NULL;
       }
 
diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h
index efed96ec9f5..fa7646840c9 100644
--- a/intern/cycles/blender/blender_util.h
+++ b/intern/cycles/blender/blender_util.h
@@ -231,16 +231,24 @@ static inline int render_resolution_y(BL::RenderSettings &b_render)
   return b_render.resolution_y() * b_render.resolution_percentage() / 100;
 }
 
-static inline string image_user_file_path(BL::ImageUser &iuser, BL::Image &ima, int cfra)
+static inline string image_user_file_path(BL::ImageUser &iuser,
+                                          BL::Image &ima,
+                                          int cfra,
+                                          bool *is_tiled)
 {
+  if (is_tiled != NULL) {
+    *is_tiled = false;
+  }
+
   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) {
+  if (ima.source() == BL::Image::source_TILED && is_tiled != NULL) {
     char *udim_id = strstr(filepath, "1001");
     if (udim_id != NULL) {
       memcpy(udim_id, "%04d", 4);
+      *is_tiled = true;
     }
   }
   return string(filepath);
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index b8847f92153..cd990393823 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -235,6 +235,8 @@ NODE_DEFINE(ImageTextureNode)
   SOCKET_STRING(filename, "Filename", ustring());
   SOCKET_STRING(colorspace, "Colorspace", u_colorspace_auto);
 
+  SOCKET_BOOLEAN(is_tiled, "Is Tiled", false);
+
   static NodeEnum alpha_type_enum;
   alpha_type_enum.insert("auto", IMAGE_ALPHA_AUTO);
   alpha_type_enum.insert("unassociated", IMAGE_ALPHA_UNASSOCIATED);
@@ -366,15 +368,12 @@ void ImageTextureNode::compile(SVMCompiler &compiler)
   image_manager = compiler.scene->image_manager;
   if (slots.empty()) {
     cull_tiles(compiler.scene, compiler.current_graph);
-  }
-  if (slots.size() < tiles.size()) {
-    slots.clear();
     slots.reserve(tiles.size());
 
     bool have_metadata = false;
     foreach (int tile, tiles) {
       string tile_name = filename.string();
-      if (tiles.size() > 1) {
+      if (is_tiled) {
         tile_name = string_printf(tile_name.c_str(), tile);
       }
 
diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h
index a8fe7644957..5b23ef6929e 100644
--- a/intern/cycles/render/nodes.h
+++ b/intern/cycles/render/nodes.h
@@ -114,6 +114,7 @@ class ImageTextureNode : public ImageSlotTextureNode {
   bool animated;
   float3 vector;
   ccl::vector<int> tiles;
+  bool is_tiled;
 
   /* Runtime. */
   bool is_float;



More information about the Bf-blender-cvs mailing list