Commit: 70040e7b0b683f2ff6ac30b20a8e426bab294e67
Author: Alexander Gavrilov
Date:   Mon Oct 26 18:32:48 2020 +0100
Branches: master
https://developer.blender.org/rB70040e7b0b683f2ff6ac30b20a8e426bab294e67

Cycles: internal support for alpha output for attribute node

Not exposed in Blender yet.

Ref D2057

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

M       intern/cycles/kernel/shaders/node_attribute.osl
M       intern/cycles/kernel/svm/svm_attribute.h
M       intern/cycles/kernel/svm/svm_types.h
M       intern/cycles/render/nodes.cpp

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

diff --git a/intern/cycles/kernel/shaders/node_attribute.osl 
b/intern/cycles/kernel/shaders/node_attribute.osl
index abec8ebfbf0..205d0a21bed 100644
--- a/intern/cycles/kernel/shaders/node_attribute.osl
+++ b/intern/cycles/kernel/shaders/node_attribute.osl
@@ -20,20 +20,26 @@ shader node_attribute(string bump_offset = "center",
                       string name = "",
                       output point Vector = point(0.0, 0.0, 0.0),
                       output color Color = 0.0,
-                      output float Fac = 0.0)
+                      output float Fac = 0.0,
+                      output float Alpha = 0.0)
 {
-  getattribute(name, Color);
+  float data[4];
+  getattribute(name, data);
+  Color = color(data[0], data[1], data[2]);
   Vector = point(Color);
   getattribute(name, Fac);
+  Alpha = data[3];
 
   if (bump_offset == "dx") {
     Color += Dx(Color);
     Vector += Dx(Vector);
     Fac += Dx(Fac);
+    Alpha += Dx(Alpha);
   }
   else if (bump_offset == "dy") {
     Color += Dy(Color);
     Vector += Dy(Vector);
     Fac += Dy(Fac);
+    Alpha += Dy(Alpha);
   }
 }
diff --git a/intern/cycles/kernel/svm/svm_attribute.h 
b/intern/cycles/kernel/svm/svm_attribute.h
index 079aac6ae44..f598bfb8f8f 100644
--- a/intern/cycles/kernel/svm/svm_attribute.h
+++ b/intern/cycles/kernel/svm/svm_attribute.h
@@ -19,10 +19,10 @@ CCL_NAMESPACE_BEGIN
 /* Attribute Node */
 
 ccl_device AttributeDescriptor svm_node_attr_init(
-    KernelGlobals *kg, ShaderData *sd, uint4 node, NodeAttributeType *type, 
uint *out_offset)
+    KernelGlobals *kg, ShaderData *sd, uint4 node, NodeAttributeOutputType 
*type, uint *out_offset)
 {
   *out_offset = node.z;
-  *type = (NodeAttributeType)node.w;
+  *type = (NodeAttributeOutputType)node.w;
 
   AttributeDescriptor desc;
 
@@ -46,7 +46,7 @@ ccl_device AttributeDescriptor svm_node_attr_init(
 
 ccl_device void svm_node_attr(KernelGlobals *kg, ShaderData *sd, float *stack, 
uint4 node)
 {
-  NodeAttributeType type = NODE_ATTR_FLOAT;
+  NodeAttributeOutputType type = NODE_ATTR_OUTPUT_FLOAT;
   uint out_offset = 0;
   AttributeDescriptor desc = svm_node_attr_init(kg, sd, node, &type, 
&out_offset);
 
@@ -56,72 +56,91 @@ ccl_device void svm_node_attr(KernelGlobals *kg, ShaderData 
*sd, float *stack, u
   if (primitive_is_volume_attribute(sd, desc)) {
     const float4 value = volume_attribute_float4(kg, sd, desc);
 
-    if (type == NODE_ATTR_FLOAT) {
+    if (type == NODE_ATTR_OUTPUT_FLOAT) {
       const float f = volume_attribute_value_to_float(value);
       stack_store_float(stack, out_offset, f);
     }
-    else {
+    else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
       const float3 f = volume_attribute_value_to_float3(value);
       stack_store_float3(stack, out_offset, f);
     }
+    else {
+      const float f = volume_attribute_value_to_alpha(value);
+      stack_store_float(stack, out_offset, f);
+    }
     return;
   }
 #endif
 
-  /* Surface */
+  /* Surface. */
   if (desc.type == NODE_ATTR_FLOAT) {
     float f = primitive_surface_attribute_float(kg, sd, desc, NULL, NULL);
-    if (type == NODE_ATTR_FLOAT) {
+    if (type == NODE_ATTR_OUTPUT_FLOAT) {
       stack_store_float(stack, out_offset, f);
     }
-    else {
+    else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
       stack_store_float3(stack, out_offset, make_float3(f, f, f));
     }
+    else {
+      stack_store_float(stack, out_offset, 1.0f);
+    }
   }
   else if (desc.type == NODE_ATTR_FLOAT2) {
     float2 f = primitive_surface_attribute_float2(kg, sd, desc, NULL, NULL);
-    if (type == NODE_ATTR_FLOAT) {
+    if (type == NODE_ATTR_OUTPUT_FLOAT) {
       stack_store_float(stack, out_offset, f.x);
     }
-    else {
+    else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
       stack_store_float3(stack, out_offset, make_float3(f.x, f.y, 0.0f));
     }
+    else {
+      stack_store_float(stack, out_offset, 1.0f);
+    }
   }
   else if (desc.type == NODE_ATTR_FLOAT4 || desc.type == NODE_ATTR_RGBA) {
     float4 f = primitive_surface_attribute_float4(kg, sd, desc, NULL, NULL);
-    if (type == NODE_ATTR_FLOAT) {
+    if (type == NODE_ATTR_OUTPUT_FLOAT) {
       stack_store_float(stack, out_offset, average(float4_to_float3(f)));
     }
-    else {
+    else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
       stack_store_float3(stack, out_offset, float4_to_float3(f));
     }
+    else {
+      stack_store_float(stack, out_offset, f.w);
+    }
   }
   else {
     float3 f = primitive_surface_attribute_float3(kg, sd, desc, NULL, NULL);
-    if (type == NODE_ATTR_FLOAT) {
+    if (type == NODE_ATTR_OUTPUT_FLOAT) {
       stack_store_float(stack, out_offset, average(f));
     }
-    else {
+    else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
       stack_store_float3(stack, out_offset, f);
     }
+    else {
+      stack_store_float(stack, out_offset, 1.0f);
+    }
   }
 }
 
 ccl_device void svm_node_attr_bump_dx(KernelGlobals *kg, ShaderData *sd, float 
*stack, uint4 node)
 {
-  NodeAttributeType type = NODE_ATTR_FLOAT;
+  NodeAttributeOutputType type = NODE_ATTR_OUTPUT_FLOAT;
   uint out_offset = 0;
   AttributeDescriptor desc = svm_node_attr_init(kg, sd, node, &type, 
&out_offset);
 
 #ifdef __VOLUME__
   /* Volume */
   if (primitive_is_volume_attribute(sd, desc)) {
-    if (type == NODE_ATTR_FLOAT) {
+    if (type == NODE_ATTR_OUTPUT_FLOAT) {
       stack_store_float(stack, out_offset, 0.0f);
     }
-    else {
+    else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
       stack_store_float3(stack, out_offset, make_float3(0.0f, 0.0f, 0.0f));
     }
+    else {
+      stack_store_float(stack, out_offset, 1.0f);
+    }
     return;
   }
 #endif
@@ -130,60 +149,75 @@ ccl_device void svm_node_attr_bump_dx(KernelGlobals *kg, 
ShaderData *sd, float *
   if (desc.type == NODE_ATTR_FLOAT) {
     float dx;
     float f = primitive_surface_attribute_float(kg, sd, desc, &dx, NULL);
-    if (type == NODE_ATTR_FLOAT) {
+    if (type == NODE_ATTR_OUTPUT_FLOAT) {
       stack_store_float(stack, out_offset, f + dx);
     }
-    else {
+    else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
       stack_store_float3(stack, out_offset, make_float3(f + dx, f + dx, f + 
dx));
     }
+    else {
+      stack_store_float(stack, out_offset, 1.0f);
+    }
   }
   else if (desc.type == NODE_ATTR_FLOAT2) {
     float2 dx;
     float2 f = primitive_surface_attribute_float2(kg, sd, desc, &dx, NULL);
-    if (type == NODE_ATTR_FLOAT) {
+    if (type == NODE_ATTR_OUTPUT_FLOAT) {
       stack_store_float(stack, out_offset, f.x + dx.x);
     }
-    else {
+    else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
       stack_store_float3(stack, out_offset, make_float3(f.x + dx.x, f.y + 
dx.y, 0.0f));
     }
+    else {
+      stack_store_float(stack, out_offset, 1.0f);
+    }
   }
   else if (desc.type == NODE_ATTR_FLOAT4 || desc.type == NODE_ATTR_RGBA) {
     float4 dx;
     float4 f = primitive_surface_attribute_float4(kg, sd, desc, &dx, NULL);
-    if (type == NODE_ATTR_FLOAT) {
+    if (type == NODE_ATTR_OUTPUT_FLOAT) {
       stack_store_float(stack, out_offset, average(float4_to_float3(f + dx)));
     }
-    else {
+    else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
       stack_store_float3(stack, out_offset, float4_to_float3(f + dx));
     }
+    else {
+      stack_store_float(stack, out_offset, f.w + dx.w);
+    }
   }
   else {
     float3 dx;
     float3 f = primitive_surface_attribute_float3(kg, sd, desc, &dx, NULL);
-    if (type == NODE_ATTR_FLOAT) {
+    if (type == NODE_ATTR_OUTPUT_FLOAT) {
       stack_store_float(stack, out_offset, average(f + dx));
     }
-    else {
+    else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
       stack_store_float3(stack, out_offset, f + dx);
     }
+    else {
+      stack_store_float(stack, out_offset, 1.0f);
+    }
   }
 }
 
 ccl_device void svm_node_attr_bump_dy(KernelGlobals *kg, ShaderData *sd, float 
*stack, uint4 node)
 {
-  NodeAttributeType type = NODE_ATTR_FLOAT;
+  NodeAttributeOutputType type = NODE_ATTR_OUTPUT_FLOAT;
   uint out_offset = 0;
   AttributeDescriptor desc = svm_node_attr_init(kg, sd, node, &type, 
&out_offset);
 
 #ifdef __VOLUME__
   /* Volume */
   if (primitive_is_volume_attribute(sd, desc)) {
-    if (type == NODE_ATTR_FLOAT) {
+    if (type == NODE_ATTR_OUTPUT_FLOAT) {
       stack_store_float(stack, out_offset, 0.0f);
     }
-    else {
+    else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
       stack_store_float3(stack, out_offset, make_float3(0.0f, 0.0f, 0.0f));
     }
+    else {
+      stack_store_float(stack, out_offset, 1.0f);
+    }
     return;
   }
 #endif
@@ -192,42 +226,54 @@ ccl_device void svm_node_attr_bump_dy(KernelGlobals *kg, 
ShaderData *sd, float *
   if (desc.type == NODE_ATTR_FLOAT) {
     float dy;
     float f = primitive_surface_attribute_float(kg, sd, desc, NULL, &dy);
-    if (type == NODE_ATTR_FLOAT) {
+    if (type == NODE_ATTR_OUTPUT_FLOAT) {
       stack_store_float(stack, out_offset, f + dy);
     }
-    else {
+    else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
       stack_store_float3(stack, out_offset, make_float3(f + dy, f + dy, f + 
dy));
     }
+    else {
+      stack_store_float(stack, out_offset, 1.0f);
+    }
   }
   else if (desc.type == NODE_ATTR_FLOAT2) {
     float2 dy;
     float2 f = primitive_surface_attribute_float2(kg, sd, desc, NULL, &dy);
-    if (type == NODE_ATTR_FLOAT) {
+    if (type == NODE_ATTR_OUTPUT_FLOAT) {
       stack_store_float(stack, out_offset, f.x + dy.x);
     }
-    else {
+    else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
       stack_store_float3(stack, out_offset, make_float3(f.x + dy.x, f.y + 
dy.y, 0.0f));
     }
+    else {
+      stack_store_float(stack, out_offset, 1.0f);
+    }
   }
   else if (desc.type == NODE_ATTR_FLOAT4 || desc.type == NODE_ATTR_RGBA) {
     float4 dy;
     float4 f = primitive_surface_attribute_float4(kg, sd, desc, NULL, &dy);
-    if (type == NODE_ATTR_FLOAT) {
+    if (type == NODE_ATTR_OUTPUT_FLOAT) {
       stack_store_float(stack, out_offset, average(float4_to_float3(f + dy)));
     }
-    else {
+    else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
       stack_store_float3(stack, out_offset, float4_to_float3(f + dy));
     }
+    else {
+      stack_store_float(stack, out_offset, f.w + dy.w);
+    }
   }
   else {
     float3 dy;
     float3 f = primitiv

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to