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.

VisualShaderNodeCustom

繼承: VisualShaderNode < Resource < RefCounted < Object

用於定義自訂 VisualShaderNode 的虛類,以便在視覺化著色器編輯器中使用。

說明

繼承這個類可以建立自訂的 VisualShader 腳本擴充,會自動加入到 Visual Shader 編輯器中。VisualShaderNode 的行為可以通過覆蓋虛方法定義。

要讓節點註冊為編輯器擴充,你必須為你的自訂腳本使用 @tool 注解並提供 class_name。例如:

@tool
extends VisualShaderNodeCustom
class_name VisualShaderNodeNoise

教學

方法

String

_get_category() virtual const

String

_get_code(input_vars: Array[String], output_vars: Array[String], mode: Mode, type: Type) virtual const

int

_get_default_input_port(type: PortType) virtual const

String

_get_description() virtual const

String

_get_func_code(mode: Mode, type: Type) virtual const

String

_get_global_code(mode: Mode) virtual const

int

_get_input_port_count() virtual const

Variant

_get_input_port_default_value(port: int) virtual const

String

_get_input_port_name(port: int) virtual const

PortType

_get_input_port_type(port: int) virtual const

String

_get_name() virtual const

int

_get_output_port_count() virtual const

String

_get_output_port_name(port: int) virtual const

PortType

_get_output_port_type(port: int) virtual const

int

_get_property_count() virtual const

int

_get_property_default_index(index: int) virtual const

String

_get_property_name(index: int) virtual const

PackedStringArray

_get_property_options(index: int) virtual const

PortType

_get_return_icon_type() virtual const

bool

_is_available(mode: Mode, type: Type) virtual const

bool

_is_highend() virtual const

int

get_option_index(option: int) const


方法說明

String _get_category() virtual const 🔗

覆蓋這個方法可以定義 Visual Shader 編輯器的成員對話方塊中關聯的自訂節點的路徑。路徑類似於 "MyGame/MyFunctions/Noise"

定義這個方法是可選的。不覆蓋時,該節點會被歸在“Addons”分類下。


String _get_code(input_vars: Array[String], output_vars: Array[String], mode: Mode, type: Type) virtual const 🔗

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.


int _get_default_input_port(type: PortType) virtual const 🔗

覆蓋此方法來定義視覺化著色器編輯器的成員對話方塊和圖中的相關自訂節點的名稱。

定義這個方法是可選的,但推薦使用。如果不覆蓋,節點將被命名為 "Unnamed"。


String _get_description() virtual const 🔗

覆蓋這個方法可以定義視覺化著色器編輯器的成員對話方塊中的相關自訂節點的描述。

定義這個方法是可選的。


String _get_func_code(mode: Mode, type: Type) virtual const 🔗

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.


String _get_global_code(mode: Mode) virtual const 🔗

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.


int _get_input_port_count() virtual const 🔗

覆蓋該方法以定義關聯的自訂節點的輸入埠數。

定義該方法是必需的。如果沒有被覆蓋,則該節點沒有輸入埠。


Variant _get_input_port_default_value(port: int) virtual const 🔗

覆蓋該方法以定義關聯的自訂節點的輸入埠數。

定義該方法是必需的。如果沒有被覆蓋,則該節點沒有輸入埠。


String _get_input_port_name(port: int) virtual const 🔗

覆蓋此方法來定義相關自訂節點的輸入埠的名稱。這些名稱既用於編輯器中的輸入槽,也作為著色器程式碼中的識別字,並在_get_code()中的input_vars陣列中傳遞。

定義這個方法是可選的,但推薦使用。如果沒有被覆蓋,輸入埠被命名為"in"+str(port)


PortType _get_input_port_type(port: int) virtual const 🔗

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.


String _get_name() virtual const 🔗

覆蓋此方法來定義視覺化著色器編輯器的成員對話方塊和圖中的相關自訂節點的名稱。

定義這個方法是可選的,但推薦使用。如果不覆蓋,節點將被命名為 "Unnamed"。


int _get_output_port_count() virtual const 🔗

覆蓋該方法以定義關聯的自訂節點的輸出埠數。

定義該方法是必需的。如果沒有被覆蓋,則該節點沒有輸出埠。


String _get_output_port_name(port: int) virtual const 🔗

覆蓋此方法來定義相關自訂節點的輸出埠的名稱。這些名字既用於編輯器中的輸出槽,也作為著色器程式碼中的識別字,並在_get_code()中的output_vars陣列中傳遞。

定義這個方法是可選的,但推薦使用。如果沒有被覆蓋,輸出埠被命名為"out" + str(port)


PortType _get_output_port_type(port: int) virtual const 🔗

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.


int _get_property_count() virtual const 🔗

覆蓋這個方法可以定義視覺化著色器編輯器的成員對話方塊中的相關自訂節點的描述。

定義這個方法是可選的。


int _get_property_default_index(index: int) virtual const 🔗

覆蓋這個方法可以定義視覺化著色器編輯器的成員對話方塊中的相關自訂節點的描述。

定義這個方法是可選的。


String _get_property_name(index: int) virtual const 🔗

覆蓋這個方法可以定義視覺化著色器編輯器的成員對話方塊中的相關自訂節點的描述。

定義這個方法是可選的。


PackedStringArray _get_property_options(index: int) virtual const 🔗

覆蓋這個方法可以定義視覺化著色器編輯器的成員對話方塊中的相關自訂節點的描述。

定義這個方法是可選的。


PortType _get_return_icon_type() virtual const 🔗

覆蓋此方法來定義視覺化著色器編輯器的成員對話方塊中相關自訂節點的返回圖示。

定義這個方法是可選的。如果不覆蓋,就不會顯示返回圖示。


bool _is_available(mode: Mode, type: Type) virtual const 🔗

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.


bool _is_highend() virtual const 🔗

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


int get_option_index(option: int) const 🔗

傳回圖形中下拉列表選項的選定索引。您可以使用此函式在 _get_code()_get_global_code() 中定義特定行為。