Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

VisualShaderGroup

Inherits: Resource < RefCounted < Object

A reusable group of VisualShaderNodes similar to a function in programming.

Description

A VisualShaderGroup encapsulates a graph of VisualShaderNodes into a reusable component. It defines its own input and output ports, which become the interface when the group is used as a VisualShaderNodeGroup node inside a VisualShader or another VisualShaderGroup.

Since an actual shader function is created for each VisualShaderGroup, you can only use global built-in variables. Parameter and Varying related nodes are not allowed.

If the group contains nodes that are incompatible with the shader context it is used in (e.g. particle nodes in a spatial shader), the group's outputs will silently fall back to default values.

Properties

String

group_name

"NodeGroup"

int

input_port_count

0

String

input_port_{index}/name

""

int

input_port_{index}/type

0

int

output_port_count

0

String

output_port_{index}/name

""

int

output_port_{index}/type

0

Methods

void

add_node(node: VisualShaderNode, position: Vector2, id: int)

void

attach_node_to_frame(id: int, frame: int)

bool

can_connect_nodes(from_node: int, from_port: int, to_node: int, to_port: int) const

Error

connect_nodes(from_node: int, from_port: int, to_node: int, to_port: int)

void

connect_nodes_forced(from_node: int, from_port: int, to_node: int, to_port: int)

void

detach_node_from_frame(id: int)

void

disconnect_nodes(from_node: int, from_port: int, to_node: int, to_port: int)

String

get_input_port_name(id: int) const

PortType

get_input_port_type(id: int) const

VisualShaderNode

get_node(id: int) const

Array[Dictionary]

get_node_connections() const

PackedInt32Array

get_node_list() const

Vector2

get_node_position(id: int) const

String

get_output_port_name(id: int) const

PortType

get_output_port_type(id: int) const

int

get_valid_node_id() const

String

insert_input_port(id: int, type: PortType, name: String)

String

insert_output_port(id: int, type: PortType, name: String)

bool

is_node_connection(from_node: int, from_port: int, to_node: int, to_port: int) const

void

move_input_port(from: int, to: int)

void

move_output_port(from: int, to: int)

void

remove_input_port(id: int)

void

remove_node(id: int)

void

remove_output_port(id: int)

void

replace_node(id: int, new_class: StringName)

void

set_input_port_name(id: int, name: String)

void

set_input_port_type(id: int, type: PortType)

void

set_node_position(id: int, position: Vector2)

void

set_output_port_name(id: int, name: String)

void

set_output_port_type(id: int, type: PortType)


Property Descriptions

String group_name = "NodeGroup" 🔗

  • void set_group_name(value: String)

  • String get_group_name()

The display name of this group. This name is shown as the caption of the VisualShaderNodeGroup node in the editor.


int input_port_count = 0 🔗

  • void set_input_port_count(value: int)

  • int get_input_port_count()

The number of input ports defined for this group. Shrinking the array removes the trailing ports along with any connections made to them.


String input_port_{index}/name = "" 🔗

The name of the input port at index. It's used as a parameter name in the generated shader function, so it's converted into a valid identifier and made unique within the group.


int input_port_{index}/type = 0 🔗

The PortType of the input port at index.


int output_port_count = 0 🔗

  • void set_output_port_count(value: int)

  • int get_output_port_count()

The number of output ports defined for this group. Shrinking the array removes the trailing ports along with any connections made to them.


String output_port_{index}/name = "" 🔗

The name of the output port at index. It's used as a parameter name in the generated shader function, so it's converted into a valid identifier and made unique within the group.


int output_port_{index}/type = 0 🔗

The PortType of the output port at index.


Method Descriptions

void add_node(node: VisualShaderNode, position: Vector2, id: int) 🔗

Adds the specified node to the group.


void attach_node_to_frame(id: int, frame: int) 🔗

Attaches the given node to the given frame.


bool can_connect_nodes(from_node: int, from_port: int, to_node: int, to_port: int) const 🔗

Returns true if the specified nodes and ports can be connected.


Error connect_nodes(from_node: int, from_port: int, to_node: int, to_port: int) 🔗

Connects the specified nodes and ports.


void connect_nodes_forced(from_node: int, from_port: int, to_node: int, to_port: int) 🔗

Connects the specified nodes and ports, even if they can't be connected.


void detach_node_from_frame(id: int) 🔗

Detaches the given node from the frame it is attached to.


void disconnect_nodes(from_node: int, from_port: int, to_node: int, to_port: int) 🔗

Disconnects the specified nodes and ports.


String get_input_port_name(id: int) const 🔗

Returns the name of the input port at the given id.


PortType get_input_port_type(id: int) const 🔗

Returns the type of the input port at the given id.


VisualShaderNode get_node(id: int) const 🔗

Returns the shader node instance with the specified id.


Array[Dictionary] get_node_connections() const 🔗

Returns the list of connected nodes.


PackedInt32Array get_node_list() const 🔗

Returns the list of all nodes in the group.


Vector2 get_node_position(id: int) const 🔗

Returns the position of the specified node within the shader graph.


String get_output_port_name(id: int) const 🔗

Returns the name of the output port at the given id.


PortType get_output_port_type(id: int) const 🔗

Returns the type of the output port at the given id.


int get_valid_node_id() const 🔗

Returns the next valid node ID that can be added to the shader graph.


String insert_input_port(id: int, type: PortType, name: String) 🔗

Inserts an input port at the given id with the specified type and name.

Returns the validated port name, which may differ from name if a port with the same name already exists. Port names must be unique across both input and output ports.


String insert_output_port(id: int, type: PortType, name: String) 🔗

Inserts an output port at the given id with the specified type and name.

Returns the validated port name, which may differ from name if a port with the same name already exists. Port names must be unique across both input and output ports.


bool is_node_connection(from_node: int, from_port: int, to_node: int, to_port: int) const 🔗

Returns true if the specified node and port connection exists.


void move_input_port(from: int, to: int) 🔗

Moves the input port at index from to index to. Connections from input nodes inside the group will be updated accordingly.


void move_output_port(from: int, to: int) 🔗

Moves the output port at index from to index to. Connections to output nodes inside the group will be updated accordingly.


void remove_input_port(id: int) 🔗

Removes the input port at the given id.


void remove_node(id: int) 🔗

Removes the specified node from the group.


void remove_output_port(id: int) 🔗

Removes the output port at the given id.


void replace_node(id: int, new_class: StringName) 🔗

Replaces the specified node with a node of the new class type.


void set_input_port_name(id: int, name: String) 🔗

Sets the name of the input port at the given id.


void set_input_port_type(id: int, type: PortType) 🔗

Sets the type of the input port at the given id.


void set_node_position(id: int, position: Vector2) 🔗

Sets the position of the specified node.


void set_output_port_name(id: int, name: String) 🔗

Sets the name of the output port at the given id.


void set_output_port_type(id: int, type: PortType) 🔗

Sets the type of the output port at the given id.


User-contributed notes

Please read the User-contributed notes policy before submitting a comment.