Index · Object → RefCounted → Resource → VisualShaderNode → VisualShaderNodeCustom

VisualShaderNodeCustom

Virtual class to define custom VisualShaderNodes for use in the Visual Shader Editor.

Class Description

By inheriting this class you can create a custom VisualShader script addon which will be automatically added to the Visual Shader Editor. The VisualShaderNode's behavior is defined by overriding the provided virtual methods.

In order for the node to be registered as an editor addon, you must use the @tool annotation and provide a class_name for your custom script. For example:

@tool
extends VisualShaderNodeCustom
class_name VisualShaderNodeNoise

Properties

Inherited from VisualShaderNode (2)
Inherited from Resource (4)

Methods

func _get_category() -> String

Override this method to define the path to the associated custom node in the Visual Shader Editor's members dialog. The path may look like "MyGame/MyFunctions/Noise".

Defining this method is optional. If not overridden, the node will be filed under the "Addons" category.

func _get_code(input_vars: String[], output_vars: String[], mode: Shader.Mode, type: VisualShader.Type) -> String

Override this method to define the actual shader code of the associated custom node. The shader code should be returned as a string, which can have multiple lines (the """ multiline string construct can be used for convenience).

The input_vars and output_vars arrays contain the string names of the various input and output variables, as defined by _get_input_* and _get_output_* virtual methods in this class.

The output ports can be assigned values in the shader code. For example, return output_vars[0] + " = " + input_vars[0] + ";".

You can customize the generated code based on the shader mode and/or type.

Defining this method is required.

func _get_default_input_port(type: VisualShaderNode.PortType) -> int

Override this method to define the input port which should be connected by default when this node is created as a result of dragging a connection from an existing node to the empty space on the graph.

Defining this method is optional. If not overridden, the connection will be created to the first valid port.

func _get_description() -> String

Override this method to define the description of the associated custom node in the Visual Shader Editor's members dialog.

Defining this method is optional.

func _get_func_code(mode: Shader.Mode, type: VisualShader.Type) -> String

Override this method to add a shader code to the beginning of each shader function (once). The shader code should be returned as a string, which can have multiple lines (the """ multiline string construct can be used for convenience).

If there are multiple custom nodes of different types which use this feature the order of each insertion is undefined.

You can customize the generated code based on the shader mode and/or type.

Defining this method is optional.

func _get_global_code(mode: Shader.Mode) -> String

Override this method to add shader code on top of the global shader, to define your own standard library of reusable methods, varyings, constants, uniforms, etc. The shader code should be returned as a string, which can have multiple lines (the """ multiline string construct can be used for convenience).

Be careful with this functionality as it can cause name conflicts with other custom nodes, so be sure to give the defined entities unique names.

You can customize the generated code based on the shader mode.

Defining this method is optional.

func _get_input_port_count() -> int

Override this method to define the number of input ports of the associated custom node.

Defining this method is required. If not overridden, the node has no input ports.

func _get_input_port_default_value(port: int) -> Variant

Override this method to define the default value for the specified input port. Prefer use this over VisualShaderNode.set_input_port_default_value().

Defining this method is required. If not overridden, the node has no default values for their input ports.

func _get_input_port_name(port: int) -> String

Override this method to define the names of input ports of the associated custom node. The names are used both for the input slots in the editor and as identifiers in the shader code, and are passed in the input_vars array in _get_code().

Defining this method is optional, but recommended. If not overridden, input ports are named as "in" + str(port).

func _get_input_port_type(port: int) -> VisualShaderNode.PortType

Override this method to define the returned type of each input port of the associated custom node.

Defining this method is optional, but recommended. If not overridden, input ports will return the VisualShaderNode.PORT_TYPE_SCALAR type.

func _get_name() -> String

Override this method to define the name of the associated custom node in the Visual Shader Editor's members dialog and graph.

Defining this method is optional, but recommended. If not overridden, the node will be named as "Unnamed".

func _get_output_port_count() -> int

Override this method to define the number of output ports of the associated custom node.

Defining this method is required. If not overridden, the node has no output ports.

func _get_output_port_name(port: int) -> String

Override this method to define the names of output ports of the associated custom node. The names are used both for the output slots in the editor and as identifiers in the shader code, and are passed in the output_vars array in _get_code().

Defining this method is optional, but recommended. If not overridden, output ports are named as "out" + str(port).

func _get_output_port_type(port: int) -> VisualShaderNode.PortType

Override this method to define the returned type of each output port of the associated custom node.

Defining this method is optional, but recommended. If not overridden, output ports will return the VisualShaderNode.PORT_TYPE_SCALAR type.

func _get_property_count() -> int

Override this method to define the number of the properties.

Defining this method is optional.

func _get_property_default_index(index: int) -> int

Override this method to define the default index of the property of the associated custom node.

Defining this method is optional.

func _get_property_name(index: int) -> String

Override this method to define the names of the property of the associated custom node.

Defining this method is optional.

func _get_property_options(index: int) -> PackedStringArray

Override this method to define the options inside the drop-down list property of the associated custom node.

Defining this method is optional.

func _get_return_icon_type() -> VisualShaderNode.PortType

Override this method to define the return icon of the associated custom node in the Visual Shader Editor's members dialog.

Defining this method is optional. If not overridden, no return icon is shown.

func _is_available(mode: Shader.Mode, type: VisualShader.Type) -> bool

Override this method to prevent the node to be visible in the member dialog for the certain mode and/or type.

Defining this method is optional. If not overridden, it's true.

func _is_highend() -> bool

Override this method to enable the high-end mark in the Visual Shader Editor's members dialog. This should return true for nodes that only work when using the Forward+ and Mobile renderers.

Defining this method is optional. If not overridden, it's false, which indicates this node works with all renderers (including Compatibility).

func get_option_index(option: int) -> int

Returns the selected index of the drop-down list option within a graph. You may use this function to define the specific behavior in the _get_code() or _get_global_code().

Inherited from VisualShaderNode (7)
func set_default_input_values(values: Array) -> void
func set_input_port_default_value(port: int, value: Variant, prev_value: Variant = null) -> void
Inherited from Resource (18)
func _get_rid() -> RID
func _reset_state() -> void
func _set_path_cache(path: String) -> void
func _setup_local_to_scene() -> void
func copy_from_resource(resource: Resource) -> Error
func duplicate(deep: bool = false) -> Resource
func duplicate_deep(deep_subresources_mode: Resource.DeepDuplicateMode = 1) -> Resource
func emit_changed() -> void
func get_rid() -> RID
func is_built_in() -> bool
func reset_state() -> void
func set_id_for_path(path: String, id: String) -> void
func set_path_cache(path: String) -> void
func setup_local_to_scene() -> void
func take_over_path(path: String) -> void
Inherited from RefCounted (4)
func init_ref() -> bool
func reference() -> bool
func unreference() -> bool
Inherited from Object (62)
func _get(property: StringName) -> Variant
func _get_property_list() -> Dictionary[]
func _init() -> void
func _iter_get(iter: Variant) -> Variant
func _iter_init(iter: Array) -> bool
func _iter_next(iter: Array) -> bool
func _notification(what: int) -> void
func _set(property: StringName, value: Variant) -> bool
func _to_string() -> String
func _validate_property(property: Dictionary) -> void
func add_user_signal(signal: String, arguments: Array = []) -> void
func call(method: StringName) -> Variant
func callv(method: StringName, arg_array: Array) -> Variant
func cancel_free() -> void
func connect(signal: StringName, callable: Callable, flags: int = 0) -> Error
func disconnect(signal: StringName, callable: Callable) -> void
func emit_signal(signal: StringName) -> Error
func free() -> void
func get(property: StringName) -> Variant
func get_class() -> String
func get_incoming_connections() -> Dictionary[]
func get_indexed(property_path: NodePath) -> Variant
func get_meta(name: StringName, default: Variant = null) -> Variant
func get_meta_list() -> StringName[]
func get_method_list() -> Dictionary[]
func get_property_list() -> Dictionary[]
func get_signal_connection_list(signal: StringName) -> Dictionary[]
func get_signal_list() -> Dictionary[]
func has_meta(name: StringName) -> bool
func has_method(method: StringName) -> bool
func has_signal(signal: StringName) -> bool
func is_class(class: StringName) -> bool
func is_connected(signal: StringName, callable: Callable) -> bool
func notification(what: int, reversed: bool = false) -> void
func remove_meta(name: StringName) -> void
func remove_user_signal(signal: StringName) -> void
func set(property: StringName, value: Variant) -> void
func set_block_signals(enable: bool) -> void
func set_deferred(property: StringName, value: Variant) -> void
func set_indexed(property_path: NodePath, value: Variant) -> void
func set_message_translation(enable: bool) -> void
func set_meta(name: StringName, value: Variant) -> void
func set_script(script: Variant) -> void
func set_translation_domain(domain: StringName) -> void
func to_string() -> String
func tr(message: StringName, context: StringName = &"") -> String
func tr_n(message: StringName, plural_message: StringName, n: int, context: StringName = &"") -> String

Signals

Inherited from Resource (2)
signal changed()
Inherited from Object (2)