Table of Contents

Class VisualShaderNodeCustom

Namespace
Godot
Assembly
GodotSharp.dll

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
public class VisualShaderNodeCustom : VisualShaderNode, IDisposable
Inheritance
VisualShaderNodeCustom
Implements
Inherited Members

Constructors

VisualShaderNodeCustom()

public VisualShaderNodeCustom()

Properties

Initialized

public bool Initialized { get; set; }

Property Value

bool

Properties

public string Properties { get; set; }

Property Value

string

Methods

GetOptionIndex(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 _GetCode(Array<string>, Array<string>, Mode, Type) or _GetGlobalCode(Mode).

public int GetOptionIndex(int option)

Parameters

option int

Returns

int

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

_GetCategory()

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.

public virtual string _GetCategory()

Returns

string

_GetCode(Array<string>, Array<string>, Mode, Type)

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 inputVars and outputVars 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 (see Shader.Mode) and/or type (see VisualShader.Type).

Defining this method is required.

public virtual string _GetCode(Array<string> inputVars, Array<string> outputVars, Shader.Mode mode, VisualShader.Type type)

Parameters

inputVars Array<string>
outputVars Array<string>
mode Shader.Mode
type VisualShader.Type

Returns

string

_GetDefaultInputPort(PortType)

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.

public virtual int _GetDefaultInputPort(VisualShaderNode.PortType type)

Parameters

type VisualShaderNode.PortType

Returns

int

_GetDescription()

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.

public virtual string _GetDescription()

Returns

string

_GetFuncCode(Mode, Type)

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 (see Shader.Mode) and/or type (see VisualShader.Type).

Defining this method is optional.

public virtual string _GetFuncCode(Shader.Mode mode, VisualShader.Type type)

Parameters

mode Shader.Mode
type VisualShader.Type

Returns

string

_GetGlobalCode(Mode)

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 (see Shader.Mode).

Defining this method is optional.

public virtual string _GetGlobalCode(Shader.Mode mode)

Parameters

mode Shader.Mode

Returns

string

_GetInputPortCount()

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.

public virtual int _GetInputPortCount()

Returns

int

_GetInputPortDefaultValue(int)

Override this method to define the default value for the specified input port. Prefer use this over SetInputPortDefaultValue(int, Variant, Variant).

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

public virtual Variant _GetInputPortDefaultValue(int port)

Parameters

port int

Returns

Variant

_GetInputPortName(int)

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 _GetCode(Array<string>, Array<string>, Mode, Type).

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

public virtual string _GetInputPortName(int port)

Parameters

port int

Returns

string

_GetInputPortType(int)

Override this method to define the returned type of each input port of the associated custom node (see VisualShaderNode.PortType for possible types).

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

public virtual VisualShaderNode.PortType _GetInputPortType(int port)

Parameters

port int

Returns

VisualShaderNode.PortType

_GetName()

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".

public virtual string _GetName()

Returns

string

_GetOutputPortCount()

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.

public virtual int _GetOutputPortCount()

Returns

int

_GetOutputPortName(int)

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 _GetCode(Array<string>, Array<string>, Mode, Type).

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

public virtual string _GetOutputPortName(int port)

Parameters

port int

Returns

string

_GetOutputPortType(int)

Override this method to define the returned type of each output port of the associated custom node (see VisualShaderNode.PortType for possible types).

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

public virtual VisualShaderNode.PortType _GetOutputPortType(int port)

Parameters

port int

Returns

VisualShaderNode.PortType

_GetPropertyCount()

Override this method to define the number of the properties.

Defining this method is optional.

public virtual int _GetPropertyCount()

Returns

int

_GetPropertyDefaultIndex(int)

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

Defining this method is optional.

public virtual int _GetPropertyDefaultIndex(int index)

Parameters

index int

Returns

int

_GetPropertyName(int)

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

Defining this method is optional.

public virtual string _GetPropertyName(int index)

Parameters

index int

Returns

string

_GetPropertyOptions(int)

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

Defining this method is optional.

public virtual string[] _GetPropertyOptions(int index)

Parameters

index int

Returns

string[]

_GetReturnIconType()

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.

public virtual VisualShaderNode.PortType _GetReturnIconType()

Returns

VisualShaderNode.PortType

_IsAvailable(Mode, Type)

Override this method to prevent the node to be visible in the member dialog for the certain mode (see Shader.Mode) and/or type (see VisualShader.Type).

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

public virtual bool _IsAvailable(Shader.Mode mode, VisualShader.Type type)

Parameters

mode Shader.Mode
type VisualShader.Type

Returns

bool

_IsHighend()

Override this method to enable high-end mark in the Visual Shader Editor's members dialog.

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

public virtual bool _IsHighend()

Returns

bool