Page MenuHome
Paste P3073

Eeevee Socket Function Signature
ArchivedPublic

Authored by Charlie Jolly (charlie) on Jul 12 2022, 6:32 PM.
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h
index c0633f0323d8..9e0c97e24f51 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -99,6 +99,7 @@ typedef struct GPUNodeStack {
bool hasinput;
bool hasoutput;
short sockettype;
+ short socketflag;
bool end;
} GPUNodeStack;
diff --git a/source/blender/gpu/intern/gpu_node_graph.c b/source/blender/gpu/intern/gpu_node_graph.c
index 1338c5312c20..f6101a858a5d 100644
--- a/source/blender/gpu/intern/gpu_node_graph.c
+++ b/source/blender/gpu/intern/gpu_node_graph.c
@@ -655,7 +655,9 @@ static bool gpu_stack_link_v(GPUMaterial *material,
if (in) {
for (i = 0; !in[i].end; i++) {
if (in[i].type != GPU_NONE) {
- gpu_node_input_socket(material, bnode, node, &in[i], i);
+ if (!(in[i].socketflag & SOCK_UNAVAIL)) {
+ gpu_node_input_socket(material, bnode, node, &in[i], i);
+ }
totin++;
}
}
@@ -664,7 +666,9 @@ static bool gpu_stack_link_v(GPUMaterial *material,
if (out) {
for (i = 0; !out[i].end; i++) {
if (out[i].type != GPU_NONE) {
- gpu_node_output(node, out[i].type, &out[i].link);
+ if (!(out[i].socketflag & SOCK_UNAVAIL)) {
+ gpu_node_output(node, out[i].type, &out[i].link);
+ }
totout++;
}
}
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_mix_color.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_mix_color.glsl
index 2d20172511e8..fff35617755b 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_mix_color.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_mix_color.glsl
@@ -1,5 +1,11 @@
#pragma BLENDER_REQUIRE(gpu_shader_common_color_utils.glsl)
+void node_mix_blend(float fac, vec4 col1, vec4 col2, out vec4 outcol)
+{
+ outcol = mix(col1, col2, fac);
+ outcol.a = col1.a;
+}
+
void node_mix_blend(float fac,
vec3 facvec,
float f1,
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index e559b6040809..ccf7c3677366 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -46,11 +46,13 @@ typedef struct bNodeStack {
short datatype;
/** Type of socket stack comes from, to remap linking different sockets. */
short sockettype;
+ /** Socket flags. */
+ short socketflag;
/** Data is a copy of external data (no freeing). */
short is_copy;
/** Data is used by external nodes (no freeing). */
short external;
- char _pad[4];
+ short _pad;
} bNodeStack;
/* ns->datatype, shadetree only */
diff --git a/source/blender/nodes/intern/node_exec.cc b/source/blender/nodes/intern/node_exec.cc
index 724d6f1a1e11..038d6a17341e 100644
--- a/source/blender/nodes/intern/node_exec.cc
+++ b/source/blender/nodes/intern/node_exec.cc
@@ -120,6 +120,7 @@ static struct bNodeStack *setup_stack(bNodeStack *stack,
}
ns->sockettype = sock->type;
+ ns->socketflag = sock->flag;
switch (sock->type) {
case SOCK_FLOAT:
diff --git a/source/blender/nodes/shader/node_shader_util.cc b/source/blender/nodes/shader/node_shader_util.cc
index 059d7800fc5d..3faf3a6e8804 100644
--- a/source/blender/nodes/shader/node_shader_util.cc
+++ b/source/blender/nodes/shader/node_shader_util.cc
@@ -134,6 +134,7 @@ void node_gpu_stack_from_data(struct GPUNodeStack *gs, int type, bNodeStack *ns)
*/
gs->hasoutput = ns->hasoutput /*&& ns->data*/;
gs->sockettype = ns->sockettype;
+ gs->socketflag = ns->socketflag;
}
}
@@ -142,6 +143,7 @@ void node_data_from_gpu_stack(bNodeStack *ns, GPUNodeStack *gs)
copy_v4_v4(ns->vec, gs->vec);
ns->data = gs->link;
ns->sockettype = gs->sockettype;
+ ns->socketflag = gs->socketflag;
}
static void gpu_stack_from_data_list(GPUNodeStack *gs, ListBase *sockets, bNodeStack **ns)

Event Timeline

@Clément Foucault (fclem) Can I get your thoughts on this please?

Currently the function generator for Eevee uses all sockets in the calling function. Whether they are available or not.
The above patch is designed to omit the unavailable sockets and compact the signature.
This is useful for dynamic nodes that make sockets available depending on the mode.

E.g. From

void node_mix_blend(float fac,
                    vec3 facvec,
                    float f1,
                    float f2,
                    vec3 v1,
                    vec3 v2,
                    vec4 col1,
                    vec4 col2,
                    out float outfloat,
                    out vec3 outvec,
                    out vec4 outcol)
{
  outcol = mix(col1, col2, fac);
  outcol.a = col1.a;
}

to

void node_mix_blend(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{
  outcol = mix(col1, col2, fac);
  outcol.a = col1.a;
}