[Bf-blender-cvs] [fa5e28ab08c] master: Cycles: Support UDIMs with OSL shading

Lukas Stockner noreply at git.blender.org
Thu Dec 26 00:33:42 CET 2019


Commit: fa5e28ab08c74bcb4971e71926deab695281ef78
Author: Lukas Stockner
Date:   Wed Dec 25 21:12:56 2019 +0100
Branches: master
https://developer.blender.org/rBfa5e28ab08c74bcb4971e71926deab695281ef78

Cycles: Support UDIMs with OSL shading

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

M	intern/cycles/kernel/shaders/node_image_texture.osl
M	intern/cycles/render/nodes.cpp

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

diff --git a/intern/cycles/kernel/shaders/node_image_texture.osl b/intern/cycles/kernel/shaders/node_image_texture.osl
index f78ca7ec0e8..96ce39a08c8 100644
--- a/intern/cycles/kernel/shaders/node_image_texture.osl
+++ b/intern/cycles/kernel/shaders/node_image_texture.osl
@@ -63,11 +63,21 @@ color image_texture_lookup(string filename,
                            int ignore_alpha,
                            int unassociate_alpha,
                            int is_float,
+                           int is_tiled,
                            string interpolation,
                            string extension)
 {
+  /* Flip the y coordinate, but preserve UDIM tiles. */
+  float flip_v;
+  if (is_tiled) {
+    float v_i = (int) v;
+    flip_v = v_i + (1.0 - (v - v_i));
+  }
+  else {
+    flip_v = 1.0 - v;
+  }
   color rgb = (color)texture(
-      filename, u, 1.0 - v, "wrap", extension, "interp", interpolation, "alpha", Alpha);
+      filename, u, flip_v, "wrap", extension, "interp", interpolation, "alpha", Alpha);
 
   if (ignore_alpha) {
     Alpha = 1.0;
@@ -97,6 +107,7 @@ shader node_image_texture(int use_mapping = 0,
                           int compress_as_srgb = 0,
                           int ignore_alpha = 0,
                           int unassociate_alpha = 0,
+                          int is_tiled = 0,
                           int is_float = 1,
                           output color Color = 0.0,
                           output float Alpha = 1.0)
@@ -115,6 +126,7 @@ shader node_image_texture(int use_mapping = 0,
                                  ignore_alpha,
                                  unassociate_alpha,
                                  is_float,
+                                 is_tiled,
                                  interpolation,
                                  extension);
   }
@@ -193,6 +205,7 @@ shader node_image_texture(int use_mapping = 0,
                                                 ignore_alpha,
                                                 unassociate_alpha,
                                                 is_float,
+                                                0,
                                                 interpolation,
                                                 extension);
       Alpha += weight[0] * tmp_alpha;
@@ -206,6 +219,7 @@ shader node_image_texture(int use_mapping = 0,
                                                 ignore_alpha,
                                                 unassociate_alpha,
                                                 is_float,
+                                                0,
                                                 interpolation,
                                                 extension);
       Alpha += weight[1] * tmp_alpha;
@@ -219,6 +233,7 @@ shader node_image_texture(int use_mapping = 0,
                                                 ignore_alpha,
                                                 unassociate_alpha,
                                                 is_float,
+                                                0,
                                                 interpolation,
                                                 extension);
       Alpha += weight[2] * tmp_alpha;
@@ -234,6 +249,7 @@ shader node_image_texture(int use_mapping = 0,
                                  ignore_alpha,
                                  unassociate_alpha,
                                  is_float,
+                                 0,
                                  interpolation,
                                  extension);
   }
@@ -247,6 +263,7 @@ shader node_image_texture(int use_mapping = 0,
                                  ignore_alpha,
                                  unassociate_alpha,
                                  is_float,
+                                 0,
                                  interpolation,
                                  extension);
   }
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 5af22e0c2c3..d176f58e636 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -504,11 +504,14 @@ void ImageTextureNode::compile(OSLCompiler &compiler)
   if (slots.size() == 0) {
     ImageMetaData metadata;
     if (builtin_data == NULL) {
-      image_manager->get_image_metadata(filename.string(), NULL, colorspace, metadata);
+      string tile_name = filename.string();
+      if (is_tiled) {
+        tile_name = string_printf(tile_name.c_str(), 1001);
+      }
+      image_manager->get_image_metadata(tile_name, NULL, colorspace, metadata);
       slots.push_back(-1);
     }
     else {
-      /* TODO(lukas): OSL UDIMs */
       int slot = image_manager->add_image(filename.string(),
                                           builtin_data,
                                           animated,
@@ -526,8 +529,17 @@ void ImageTextureNode::compile(OSLCompiler &compiler)
   }
 
   if (slots[0] == -1) {
+    ustring texture_name = filename;
+    if (is_tiled) {
+      size_t udim_pos = filename.rfind("%04d");
+      if (udim_pos != string::npos) {
+        string texture_name_str = filename.string();
+        texture_name_str.replace(udim_pos, 4, "<UDIM>");
+        texture_name = ustring(texture_name_str);
+      }
+    }
     compiler.parameter_texture(
-        "filename", filename, compress_as_srgb ? u_colorspace_raw : known_colorspace);
+        "filename", texture_name, compress_as_srgb ? u_colorspace_raw : known_colorspace);
   }
   else {
     compiler.parameter_texture("filename", slots[0]);
@@ -543,6 +555,7 @@ void ImageTextureNode::compile(OSLCompiler &compiler)
   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("is_tiled", is_tiled);
   compiler.parameter(this, "interpolation");
   compiler.parameter(this, "extension");



More information about the Bf-blender-cvs mailing list