Nodes: Add new shader for node sockets #119243

Open
Leon Schittek wants to merge 34 commits from lone_noel/blender:node-socket-shader into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

Experiment to create a shader specifically for node sockets rather than
using the keyframe shader.

Motivation:

  1. Simplify socket drawing by avoiding special handling of multi-inputs
  2. Support multi-input sockets for all socket types (diamond, square, etc.)

While there currently is no need for (2.) internally, there are a few
obvious use-cases for multi-input field (diamond) sockets like generalized
math nodes with an arbitrary number of inputs (Add, Multiply, Minimum etc.).

Screenshots
The changes for the wide reroute node below are not included in this PR.
It's only there to show how the socket shader can be used.

Round Diamond Square
socket-showcase_round_2.png socket-showcase_diamond_2.png socket-showcase_square_2.png
Experiment to create a shader specifically for node sockets rather than using the keyframe shader. Motivation: 1. Simplify socket drawing by avoiding special handling of multi-inputs 2. Support multi-input sockets for all socket types (diamond, square, etc.) While there currently is no need for (2.) internally, there are a few obvious use-cases for multi-input field (diamond) sockets like generalized math nodes with an arbitrary number of inputs (Add, Multiply, Minimum etc.). **Screenshots** The changes for the wide reroute node below are not included in this PR. It's only there to show how the socket shader can be used. |Round|Diamond|Square| |---|---|---| |![socket-showcase_round_2.png](/attachments/9b7ec0de-c963-4d62-9bc0-d09e6c7e0385)|![socket-showcase_diamond_2.png](/attachments/df4eea2f-83ad-473b-876a-e2d97256ee53)|![socket-showcase_square_2.png](/attachments/f6e23395-f0cc-40ee-9abb-26d6ecec8b8c)|
Leon Schittek added 4 commits 2024-03-09 10:55:52 +01:00
Leon Schittek changed title from WIP: Experiment: Add new shader specifically for node sockets to WIP: Experiment: Nodes: Add new shader for node sockets 2024-03-09 10:56:28 +01:00
Leon Schittek added the
Interest
Nodes & Physics
label 2024-03-09 10:57:05 +01:00
Iliya Katushenock added the
Interest
Viewport & EEVEE
label 2024-03-09 11:07:01 +01:00
Leon Schittek added 2 commits 2024-03-15 14:13:18 +01:00
Leon Schittek added 3 commits 2024-03-29 13:27:29 +01:00
Jacques Lucke added 1 commit 2024-06-04 14:59:27 +02:00
Jacques Lucke added 5 commits 2024-06-04 15:18:18 +02:00
Member

Generally looks like the right direction. Right now I mainly wonder why per-socket properties are passed as uniform parameters instead of as separate buffer which can have arbitrary size. It seems unconventional to have to limit the batch size to e.g. 32 sockets.

Generally looks like the right direction. Right now I mainly wonder why per-socket properties are passed as uniform parameters instead of as separate buffer which can have arbitrary size. It seems unconventional to have to limit the batch size to e.g. 32 sockets.
Jacques Lucke requested review from Jacques Lucke 2024-06-04 15:20:10 +02:00
Leon Schittek added 2 commits 2024-11-03 14:57:17 +01:00
Leon Schittek added 4 commits 2024-11-08 13:22:57 +01:00
Leon Schittek added 1 commit 2024-11-08 13:47:29 +01:00
Hans Goudey requested changes 2024-11-13 01:50:52 +01:00
Hans Goudey left a comment
Member

Looks nice overall, thanks for working on this. Just noticed a few cleanup changes.

Looks nice overall, thanks for working on this. Just noticed a few cleanup changes.
@ -1813,0 +1817,4 @@
/* Node Socket shader parameters, must match the shader layout. */
struct NodeSocketShaderParameters {
rctf rect;
float color_inner[4];
Member

Seems like float4 would simplify this code a bit

Seems like `float4` would simplify this code a bit
@ -1813,0 +1833,4 @@
gpu::Batch *batch;
Vector<NodeSocketShaderParameters, MAX_SOCKET_INSTANCE> params;
bool enabled;
} g_batch_nodesocket;
Member

Because of the static initialization order fiasco, better to declare this static variable inside of nodesocket_batch_init.

Because of the [static initialization order fiasco](https://en.cppreference.com/w/cpp/language/siof), better to declare this static variable inside of `nodesocket_batch_init`.
Author
Member

I see. I'm unsure how a declaration in nodesocket_batch_init would resolve this but I tried to apply the "construct on first use" idiom.

I see. I'm unsure how a declaration in `nodesocket_batch_init` would resolve this but I tried to apply the "construct on first use" idiom.
@ -1813,0 +1835,4 @@
bool enabled;
} g_batch_nodesocket;
static gpu::Batch *nodesocket_batch_init(void)
Member

(void) -> ()

`(void)` -> `()`
lone_noel marked this conversation as resolved
@ -1813,0 +1837,4 @@
static gpu::Batch *nodesocket_batch_init(void)
{
if (g_batch_nodesocket.batch == NULL) {
Member

NULL -> nullptr

`NULL` -> `nullptr`
lone_noel marked this conversation as resolved
@ -1813,0 +1862,4 @@
/* draw single */
GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_NODE_SOCKET);
GPU_batch_uniform_4fv_array(
batch, "parameters", 4, (const float(*)[4])g_batch_nodesocket.params.data());
Member

reinterpret_cast<const float(*)[4]>(

Same below

`reinterpret_cast<const float(*)[4]>(` Same below
lone_noel marked this conversation as resolved
@ -1420,4 +1377,0 @@
immVertex2f(pos_id, locx, locy);
}
static void node_socket_tooltip_set(uiBlock &block,
Member

I don't fully understand the reasoning for the removal of this tooltip code. Am I missing something?

I don't fully understand the reasoning for the removal of this tooltip code. Am I missing something?
Author
Member

No, this is just an oversight on my part!

No, this is just an oversight on my part!
lone_noel marked this conversation as resolved
@ -2426,0 +2277,4 @@
&rect, socket_color, outline_color, outline_thickness, dot_radius, sock.display_shape);
}
void node_draw_sockets(const SpaceNode &snode,
Member

static void

`static void`
lone_noel marked this conversation as resolved
@ -4467,6 +4161,32 @@ static StringRefNull reroute_node_get_auto_label(TreeDrawContext &tree_draw_ctx,
return label;
}
void reroute_node_draw_body(const bContext &C,
Member

static void

`static void`
lone_noel marked this conversation as resolved
@ -150,13 +150,6 @@ static bool node_under_mouse_tweak(const SpaceNode &snode, const float2 &mouse)
{
for (bNode *node : tree_draw_order_calc_nodes_reversed(*snode.edittree)) {
switch (node->type) {
case NODE_REROUTE: {
Member

Things seem to work fine with this change too, just checking to make this change is purposeful though.

Things seem to work fine with this change too, just checking to make this change is purposeful though.
Author
Member

It was intentional but not really related to this patch anymore (it used to be part of the reroute changes).

node_to_view(*node, {node->locx, node->locy}) is not getting the node location, but the coordinates offset by {node->locx, node->locy} relative to the node.
The only reason this doesn't break currently is because the check for tweaking also looks for the node sockets, which for reroutes are identical to the node itself and therefore work as a fallback.

I made a separate PR for this: #130222

It was intentional but not really related to this patch anymore (it used to be part of the reroute changes). `node_to_view(*node, {node->locx, node->locy})` is not getting the node location, but the coordinates *offset by* `{node->locx, node->locy}` relative to the node. The only reason this doesn't break currently is because the check for tweaking also looks for the node sockets, which for reroutes are identical to the node itself and therefore work as a fallback. I made a separate PR for this: #130222
Member

Great, thanks!

Great, thanks!
@ -0,0 +1,104 @@
/* SPDX-FileCopyrightText: 2018-2022 Blender Authors
Member

2024

`2024`
lone_noel marked this conversation as resolved
@ -0,0 +20,4 @@
/* Round the sharp corners of the square and diamond a little bit. */
#define CORNER_ROUNDING 0.15
/* Calculates a squared distance fiels of a square. */
Member

fiels -> field

`fiels` -> `field`
lone_noel marked this conversation as resolved
Leon Schittek added 9 commits 2024-11-13 10:50:03 +01:00
Leon Schittek added 1 commit 2024-11-13 11:02:11 +01:00
Hans Goudey requested changes 2024-11-13 13:24:24 +01:00
@ -1813,0 +1837,4 @@
static GBatchNodesocket &g_batch_nodesocket()
{
static GBatchNodesocket *nodesocket_batch = new GBatchNodesocket();
Member

This should be a static variable rather than allocated on the heap. So just static GBatchNodesocket nodesocket_batch;

Currently this leaks memory.

This should be a static variable rather than allocated on the heap. So just `static GBatchNodesocket nodesocket_batch;` Currently this leaks memory.
lone_noel marked this conversation as resolved
Leon Schittek added 2 commits 2024-11-13 22:48:43 +01:00
Leon Schittek changed title from WIP: Experiment: Nodes: Add new shader for node sockets to Nodes: Add new shader for node sockets 2024-11-13 22:50:37 +01:00
This pull request can be merged automatically.
You are not authorized to merge this pull request.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u node-socket-shader:lone_noel-node-socket-shader
git checkout lone_noel-node-socket-shader
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#119243
No description provided.