[Bf-blender-cvs] [7c78c20b6bf] master: Cleanup: refactor image texture node code for coming changes

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


Commit: 7c78c20b6bf6f7dd00397c456fb9e2116febfca7
Author: Brecht Van Lommel
Date:   Sun May 19 02:46:24 2019 +0200
Branches: master
https://developer.blender.org/rB7c78c20b6bf6f7dd00397c456fb9e2116febfca7

Cleanup: refactor image texture node code for coming changes

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

M	intern/cycles/kernel/shaders/node_environment_texture.osl
M	intern/cycles/kernel/shaders/node_image_texture.osl
M	intern/cycles/kernel/svm/svm_image.h
M	intern/cycles/kernel/svm/svm_types.h
M	intern/cycles/render/nodes.cpp

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

diff --git a/intern/cycles/kernel/shaders/node_environment_texture.osl b/intern/cycles/kernel/shaders/node_environment_texture.osl
index eb32dad392f..43f607f7cb0 100644
--- a/intern/cycles/kernel/shaders/node_environment_texture.osl
+++ b/intern/cycles/kernel/shaders/node_environment_texture.osl
@@ -47,9 +47,10 @@ shader node_environment_texture(
     string filename = "",
     string projection = "equirectangular",
     string interpolation = "linear",
-    string color_space = "sRGB",
+    int compress_as_srgb = 0,
+    int ignore_alpha = 0,
+    int unassociate_alpha = 0,
     int is_float = 1,
-    int use_alpha = 1,
     output color Color = 0.0,
     output float Alpha = 1.0)
 {
@@ -69,13 +70,16 @@ shader node_environment_texture(
   Color = (color)texture(
       filename, p[0], 1.0 - p[1], "wrap", "periodic", "interp", interpolation, "alpha", Alpha);
 
-  if (use_alpha) {
+  if (ignore_alpha) {
+    Alpha = 1.0;
+  }
+  else if (unassociate_alpha) {
     Color = color_unpremultiply(Color, Alpha);
 
     if (!is_float)
       Color = min(Color, 1.0);
   }
 
-  if (color_space == "sRGB")
+  if (compress_as_srgb)
     Color = color_srgb_to_scene_linear(Color);
 }
diff --git a/intern/cycles/kernel/shaders/node_image_texture.osl b/intern/cycles/kernel/shaders/node_image_texture.osl
index df5eda39985..f78ca7ec0e8 100644
--- a/intern/cycles/kernel/shaders/node_image_texture.osl
+++ b/intern/cycles/kernel/shaders/node_image_texture.osl
@@ -56,11 +56,12 @@ point map_to_sphere(vector dir)
 }
 
 color image_texture_lookup(string filename,
-                           string color_space,
                            float u,
                            float v,
                            output float Alpha,
-                           int use_alpha,
+                           int compress_as_srgb,
+                           int ignore_alpha,
+                           int unassociate_alpha,
                            int is_float,
                            string interpolation,
                            string extension)
@@ -68,14 +69,17 @@ color image_texture_lookup(string filename,
   color rgb = (color)texture(
       filename, u, 1.0 - v, "wrap", extension, "interp", interpolation, "alpha", Alpha);
 
-  if (use_alpha) {
+  if (ignore_alpha) {
+    Alpha = 1.0;
+  }
+  else if (unassociate_alpha) {
     rgb = color_unpremultiply(rgb, Alpha);
 
     if (!is_float)
       rgb = min(rgb, 1.0);
   }
 
-  if (color_space == "sRGB") {
+  if (compress_as_srgb) {
     rgb = color_srgb_to_scene_linear(rgb);
   }
 
@@ -86,13 +90,14 @@ shader node_image_texture(int use_mapping = 0,
                           matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
                           point Vector = P,
                           string filename = "",
-                          string color_space = "sRGB",
                           string projection = "flat",
                           string interpolation = "smartcubic",
                           string extension = "periodic",
                           float projection_blend = 0.0,
+                          int compress_as_srgb = 0,
+                          int ignore_alpha = 0,
+                          int unassociate_alpha = 0,
                           int is_float = 1,
-                          int use_alpha = 1,
                           output color Color = 0.0,
                           output float Alpha = 1.0)
 {
@@ -102,8 +107,16 @@ shader node_image_texture(int use_mapping = 0,
     p = transform(mapping, p);
 
   if (projection == "flat") {
-    Color = image_texture_lookup(
-        filename, color_space, p[0], p[1], Alpha, use_alpha, is_float, interpolation, extension);
+    Color = image_texture_lookup(filename,
+                                 p[0],
+                                 p[1],
+                                 Alpha,
+                                 compress_as_srgb,
+                                 ignore_alpha,
+                                 unassociate_alpha,
+                                 is_float,
+                                 interpolation,
+                                 extension);
   }
   else if (projection == "box") {
     /* object space normal */
@@ -173,11 +186,12 @@ shader node_image_texture(int use_mapping = 0,
 
     if (weight[0] > 0.0) {
       Color += weight[0] * image_texture_lookup(filename,
-                                                color_space,
                                                 p[1],
                                                 p[2],
                                                 tmp_alpha,
-                                                use_alpha,
+                                                compress_as_srgb,
+                                                ignore_alpha,
+                                                unassociate_alpha,
                                                 is_float,
                                                 interpolation,
                                                 extension);
@@ -185,11 +199,12 @@ shader node_image_texture(int use_mapping = 0,
     }
     if (weight[1] > 0.0) {
       Color += weight[1] * image_texture_lookup(filename,
-                                                color_space,
                                                 p[0],
                                                 p[2],
                                                 tmp_alpha,
-                                                use_alpha,
+                                                compress_as_srgb,
+                                                ignore_alpha,
+                                                unassociate_alpha,
                                                 is_float,
                                                 interpolation,
                                                 extension);
@@ -197,11 +212,12 @@ shader node_image_texture(int use_mapping = 0,
     }
     if (weight[2] > 0.0) {
       Color += weight[2] * image_texture_lookup(filename,
-                                                color_space,
                                                 p[1],
                                                 p[0],
                                                 tmp_alpha,
-                                                use_alpha,
+                                                compress_as_srgb,
+                                                ignore_alpha,
+                                                unassociate_alpha,
                                                 is_float,
                                                 interpolation,
                                                 extension);
@@ -211,11 +227,12 @@ shader node_image_texture(int use_mapping = 0,
   else if (projection == "sphere") {
     point projected = map_to_sphere(texco_remap_square(p));
     Color = image_texture_lookup(filename,
-                                 color_space,
                                  projected[0],
                                  projected[1],
                                  Alpha,
-                                 use_alpha,
+                                 compress_as_srgb,
+                                 ignore_alpha,
+                                 unassociate_alpha,
                                  is_float,
                                  interpolation,
                                  extension);
@@ -223,11 +240,12 @@ shader node_image_texture(int use_mapping = 0,
   else if (projection == "tube") {
     point projected = map_to_tube(texco_remap_square(p));
     Color = image_texture_lookup(filename,
-                                 color_space,
                                  projected[0],
                                  projected[1],
                                  Alpha,
-                                 use_alpha,
+                                 compress_as_srgb,
+                                 ignore_alpha,
+                                 unassociate_alpha,
                                  is_float,
                                  interpolation,
                                  extension);
diff --git a/intern/cycles/kernel/svm/svm_image.h b/intern/cycles/kernel/svm/svm_image.h
index ee4b8b6e50c..2ef64662d0e 100644
--- a/intern/cycles/kernel/svm/svm_image.h
+++ b/intern/cycles/kernel/svm/svm_image.h
@@ -16,13 +16,12 @@
 
 CCL_NAMESPACE_BEGIN
 
-ccl_device float4
-svm_image_texture(KernelGlobals *kg, int id, float x, float y, uint srgb, uint use_alpha)
+ccl_device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y, uint flags)
 {
   float4 r = kernel_tex_image_interp(kg, id, x, y);
   const float alpha = r.w;
 
-  if (use_alpha && alpha != 1.0f && alpha != 0.0f) {
+  if ((flags & NODE_IMAGE_ALPHA_UNASSOCIATE) && alpha != 1.0f && alpha != 0.0f) {
     r /= alpha;
     const int texture_type = kernel_tex_type(id);
     if (texture_type == IMAGE_DATA_TYPE_BYTE4 || texture_type == IMAGE_DATA_TYPE_BYTE) {
@@ -31,8 +30,7 @@ svm_image_texture(KernelGlobals *kg, int id, float x, float y, uint srgb, uint u
     r.w = alpha;
   }
 
-  if (srgb) {
-    /* TODO(lukas): Implement proper conversion for image textures. */
+  if (flags & NODE_IMAGE_COMPRESS_AS_SRGB) {
     r = color_srgb_to_linear_v4(r);
   }
 
@@ -48,13 +46,12 @@ ccl_device_inline float3 texco_remap_square(float3 co)
 ccl_device void svm_node_tex_image(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node)
 {
   uint id = node.y;
-  uint co_offset, out_offset, alpha_offset, srgb;
+  uint co_offset, out_offset, alpha_offset, flags;
 
-  decode_node_uchar4(node.z, &co_offset, &out_offset, &alpha_offset, &srgb);
+  decode_node_uchar4(node.z, &co_offset, &out_offset, &alpha_offset, &flags);
 
   float3 co = stack_load_float3(stack, co_offset);
   float2 tex_co;
-  uint use_alpha = stack_valid(alpha_offset);
   if (node.w == NODE_IMAGE_PROJ_SPHERE) {
     co = texco_remap_square(co);
     tex_co = map_to_sphere(co);
@@ -66,7 +63,7 @@ ccl_device void svm_node_tex_image(KernelGlobals *kg, ShaderData *sd, float *sta
   else {
     tex_co = make_float2(co.x, co.y);
   }
-  float4 f = svm_image_textu

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list