[Bf-blender-cvs] [9bc177d8ded] master: Materials: support true float4 attributes in the Attribute node.

Alexander Gavrilov noreply at git.blender.org
Tue Nov 3 14:37:28 CET 2020


Commit: 9bc177d8ded4ba498762813a0d5106005fef0e67
Author: Alexander Gavrilov
Date:   Tue Aug 4 17:56:39 2020 +0300
Branches: master
https://developer.blender.org/rB9bc177d8ded4ba498762813a0d5106005fef0e67

Materials: support true float4 attributes in the Attribute node.

Add a new Alpha socket to the Attribute node that outputs the
fourth component of the attribute. Currently the only such
attribute is vertex color, but there may be more in the future.
If the attribute has no alpha channel, the expected value is 1.

The Cycles code is already refactored and committed by Brecht.

Ref D2057

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

M	source/blender/gpu/intern/gpu_codegen.c
M	source/blender/gpu/intern/gpu_node_graph.c
M	source/blender/gpu/shaders/material/gpu_shader_material_attribute.glsl
M	source/blender/nodes/shader/nodes/node_shader_attribute.c

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

diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index 2d76e793fc0..39c3119cc39 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -478,7 +478,7 @@ static void codegen_call_functions(DynStr *ds, GPUNodeGraph *graph, GPUOutput *f
         BLI_dynstr_appendf(ds, "cons%d", input->id);
       }
       else if (input->source == GPU_SOURCE_ATTR) {
-        BLI_dynstr_appendf(ds, "var%d", input->attr->id);
+        codegen_convert_datatype(ds, input->attr->gputype, input->type, "var", input->attr->id);
       }
 
       BLI_dynstr_append(ds, ", ");
diff --git a/source/blender/gpu/intern/gpu_node_graph.c b/source/blender/gpu/intern/gpu_node_graph.c
index c890d56994f..fdf8ba172cb 100644
--- a/source/blender/gpu/intern/gpu_node_graph.c
+++ b/source/blender/gpu/intern/gpu_node_graph.c
@@ -132,7 +132,10 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const eGPUType
     case GPU_NODE_LINK_ATTR:
       input->source = GPU_SOURCE_ATTR;
       input->attr = link->attr;
-      input->attr->gputype = type;
+      /* Failsafe handling if the same attribute is used with different datatypes for
+       * some reason (only really makes sense with float/vec2/vec3/vec4 though). This
+       * can happen if mixing the generic Attribute node with specialized ones. */
+      CLAMP_MIN(input->attr->gputype, type);
       break;
     case GPU_NODE_LINK_CONSTANT:
       input->source = (type == GPU_CLOSURE) ? GPU_SOURCE_STRUCT : GPU_SOURCE_CONSTANT;
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_attribute.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_attribute.glsl
index 10e1b4563bc..631d91c89d6 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_attribute.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_attribute.glsl
@@ -1,6 +1,7 @@
-void node_attribute(vec3 attr, out vec4 outcol, out vec3 outvec, out float outf)
+void node_attribute(vec4 attr, out vec4 outcol, out vec3 outvec, out float outf, out float outalpha)
 {
-  outcol = vec4(attr, 1.0);
-  outvec = attr;
-  outf = avg(attr);
+  outcol = vec4(attr.xyz, 1.0);
+  outvec = attr.xyz;
+  outf = avg(attr.xyz);
+  outalpha = attr.w;
 }
diff --git a/source/blender/nodes/shader/nodes/node_shader_attribute.c b/source/blender/nodes/shader/nodes/node_shader_attribute.c
index 4fd0ce4f1ef..37472aeec2e 100644
--- a/source/blender/nodes/shader/nodes/node_shader_attribute.c
+++ b/source/blender/nodes/shader/nodes/node_shader_attribute.c
@@ -25,6 +25,7 @@ static bNodeSocketTemplate sh_node_attribute_out[] = {
     {SOCK_RGBA, N_("Color")},
     {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
     {SOCK_FLOAT, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_FACTOR},
+    {SOCK_FLOAT, N_("Alpha"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_FACTOR},
     {-1, ""},
 };
 
@@ -52,6 +53,10 @@ static int node_shader_gpu_attribute(GPUMaterial *mat,
     if (out[2].hasoutput) {
       out[2].link = GPU_volume_grid(mat, attr->name, GPU_VOLUME_DEFAULT_0);
     }
+    if (out[3].hasoutput) {
+      static const float default_alpha = 1.0f;
+      out[3].link = GPU_constant(&default_alpha);
+    }
 
     return 1;
   }



More information about the Bf-blender-cvs mailing list