From df8683ec2a0dee0edb5f959ffd607f86c0a52c5c Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Tue, 14 Oct 2025 13:24:17 +0200 Subject: [PATCH] EEVEE: Support different dimensions vector sockets This patch adds support for the dimensions property of vector sockets, support 2D and 4D sockets in addition to the currently supported 3D one. This just involves assigning the correct GPU type when constructing the GPU materials from nodes. The only node that uses 2D sockets for now is the Radial Tilling node, so we just need to update its interface. Pull Request: https://projects.blender.org/blender/blender/pulls/148034 --- .../gpu_shader_material_radial_tiling.glsl | 2 +- .../blender/nodes/shader/node_shader_util.cc | 33 ++++++++++++------- .../blender/nodes/shader/node_shader_util.hh | 2 +- .../nodes/shader/nodes/node_shader_common.cc | 2 +- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_radial_tiling.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_radial_tiling.glsl index eda13dca56d..7b82a3fe1d6 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_radial_tiling.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_radial_tiling.glsl @@ -15,7 +15,7 @@ /* Undefine macro flags used for code adaption. */ /* No macro flags necessary, as code is adapted to GLSL by default. */ -void node_radial_tiling(float3 coord, +void node_radial_tiling(float2 coord, float r_gon_sides, float r_gon_roundness, float normalize_r_gon_parameter, diff --git a/source/blender/nodes/shader/node_shader_util.cc b/source/blender/nodes/shader/node_shader_util.cc index 1e5b8b0314c..9a9b8d3aecc 100644 --- a/source/blender/nodes/shader/node_shader_util.cc +++ b/source/blender/nodes/shader/node_shader_util.cc @@ -169,7 +169,7 @@ static void nodestack_get_vec(float *in, short type_in, bNodeStack *ns) } } -void node_gpu_stack_from_data(GPUNodeStack *gs, int type, bNodeStack *ns) +void node_gpu_stack_from_data(GPUNodeStack *gs, bNodeSocket *socket, bNodeStack *ns) { memset(gs, 0, sizeof(*gs)); @@ -181,28 +181,39 @@ void node_gpu_stack_from_data(GPUNodeStack *gs, int type, bNodeStack *ns) gs->type = GPU_NONE; gs->hasinput = false; gs->hasoutput = false; - gs->sockettype = type; + gs->sockettype = socket->type; } else { - nodestack_get_vec(gs->vec, type, ns); + nodestack_get_vec(gs->vec, socket->type, ns); gs->link = (GPUNodeLink *)ns->data; - if (type == SOCK_FLOAT) { + if (socket->type == SOCK_FLOAT) { gs->type = GPU_FLOAT; } - else if (type == SOCK_INT) { + else if (socket->type == SOCK_INT) { gs->type = GPU_FLOAT; /* HACK: Support as float. */ } - else if (type == SOCK_BOOLEAN) { + else if (socket->type == SOCK_BOOLEAN) { gs->type = GPU_FLOAT; /* HACK: Support as float. */ } - else if (type == SOCK_VECTOR) { - gs->type = GPU_VEC3; + else if (socket->type == SOCK_VECTOR) { + switch (socket->default_value_typed()->dimensions) { + case 2: + gs->type = GPU_VEC2; + break; + case 3: + default: + gs->type = GPU_VEC3; + break; + case 4: + gs->type = GPU_VEC4; + break; + } } - else if (type == SOCK_RGBA) { + else if (socket->type == SOCK_RGBA) { gs->type = GPU_VEC4; } - else if (type == SOCK_SHADER) { + else if (socket->type == SOCK_SHADER) { gs->type = GPU_CLOSURE; } else { @@ -230,7 +241,7 @@ static void gpu_stack_from_data_list(GPUNodeStack *gs, ListBase *sockets, bNodeS { int i; LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, sockets, i) { - node_gpu_stack_from_data(&gs[i], socket->type, ns[i]); + node_gpu_stack_from_data(&gs[i], socket, ns[i]); } gs[i].end = true; diff --git a/source/blender/nodes/shader/node_shader_util.hh b/source/blender/nodes/shader/node_shader_util.hh index 355b5c6bf28..d63cbb05aa9 100644 --- a/source/blender/nodes/shader/node_shader_util.hh +++ b/source/blender/nodes/shader/node_shader_util.hh @@ -65,7 +65,7 @@ struct XYZ_to_RGB /* Transposed #imbuf_xyz_to_rgb, passed as 3x vec3. */ float r[3], g[3], b[3]; }; -void node_gpu_stack_from_data(GPUNodeStack *gs, int type, bNodeStack *ns); +void node_gpu_stack_from_data(GPUNodeStack *gs, bNodeSocket *socket, bNodeStack *ns); void node_data_from_gpu_stack(bNodeStack *ns, GPUNodeStack *gs); void node_shader_gpu_bump_tex_coord(GPUMaterial *mat, bNode *node, GPUNodeLink **link); void node_shader_gpu_default_tex_coord(GPUMaterial *mat, bNode *node, GPUNodeLink **link); diff --git a/source/blender/nodes/shader/nodes/node_shader_common.cc b/source/blender/nodes/shader/nodes/node_shader_common.cc index 48a53aad6f5..ac514843a43 100644 --- a/source/blender/nodes/shader/nodes/node_shader_common.cc +++ b/source/blender/nodes/shader/nodes/node_shader_common.cc @@ -56,7 +56,7 @@ static void group_gpu_move_outputs(bNode *gnode, GPUNodeStack *out, bNodeStack * bNodeStack *ns = node_get_socket_stack(gstack, sock); if (ns) { /* convert the node stack data result back to gpu stack */ - node_gpu_stack_from_data(&out[a], sock->type, ns); + node_gpu_stack_from_data(&out[a], sock, ns); } } }