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.
Checking the stable version of the documentation...
VisualShader¶
Inherits: Shader < Resource < RefCounted < Object
A custom shader program with a visual editor.
描述¶
This class provides a graph-like visual editor for creating a Shader. Although VisualShaders do not require coding, they share the same logic with script shaders. They use VisualShaderNodes that can be connected to each other to control the flow of the shader. The visual shader graph is converted to a script shader behind the scenes.
教程¶
属性¶
|
Methods¶
void |
add_node ( Type type, VisualShaderNode node, Vector2 position, int id ) |
void |
add_varying ( String name, VaryingMode mode, VaryingType type ) |
can_connect_nodes ( Type type, int from_node, int from_port, int to_node, int to_port ) const |
|
connect_nodes ( Type type, int from_node, int from_port, int to_node, int to_port ) |
|
void |
connect_nodes_forced ( Type type, int from_node, int from_port, int to_node, int to_port ) |
void |
disconnect_nodes ( Type type, int from_node, int from_port, int to_node, int to_port ) |
get_node_connections ( Type type ) const |
|
get_node_list ( Type type ) const |
|
get_node_position ( Type type, int id ) const |
|
get_valid_node_id ( Type type ) const |
|
has_varying ( String name ) const |
|
is_node_connection ( Type type, int from_node, int from_port, int to_node, int to_port ) const |
|
void |
remove_node ( Type type, int id ) |
void |
remove_varying ( String name ) |
void |
replace_node ( Type type, int id, StringName new_class ) |
void |
|
void |
set_node_position ( Type type, int id, Vector2 position ) |
Enumerations¶
enum Type:
Type TYPE_VERTEX = 0
A vertex shader, operating on vertices.
Type TYPE_FRAGMENT = 1
A fragment shader, operating on fragments (pixels).
Type TYPE_LIGHT = 2
A shader for light calculations.
Type TYPE_START = 3
A function for the "start" stage of particle shader.
Type TYPE_PROCESS = 4
A function for the "process" stage of particle shader.
Type TYPE_COLLIDE = 5
A function for the "collide" stage (particle collision handler) of particle shader.
Type TYPE_START_CUSTOM = 6
A function for the "start" stage of particle shader, with customized output.
Type TYPE_PROCESS_CUSTOM = 7
A function for the "process" stage of particle shader, with customized output.
Type TYPE_SKY = 8
A shader for 3D environment's sky.
Type TYPE_FOG = 9
A compute shader that runs for each froxel of the volumetric fog map.
Type TYPE_MAX = 10
Represents the size of the Type enum.
enum VaryingMode:
VaryingMode VARYING_MODE_VERTEX_TO_FRAG_LIGHT = 0
Varying is passed from Vertex
function to Fragment
and Light
functions.
VaryingMode VARYING_MODE_FRAG_TO_LIGHT = 1
Varying is passed from Fragment
function to Light
function.
VaryingMode VARYING_MODE_MAX = 2
Represents the size of the VaryingMode enum.
enum VaryingType:
VaryingType VARYING_TYPE_FLOAT = 0
Varying is of type float.
VaryingType VARYING_TYPE_INT = 1
Varying is of type int.
VaryingType VARYING_TYPE_UINT = 2
Varying is of type unsigned int.
VaryingType VARYING_TYPE_VECTOR_2D = 3
Varying is of type Vector2.
VaryingType VARYING_TYPE_VECTOR_3D = 4
Varying is of type Vector3.
VaryingType VARYING_TYPE_VECTOR_4D = 5
Varying is of type Vector4.
VaryingType VARYING_TYPE_BOOLEAN = 6
Varying is of type bool.
VaryingType VARYING_TYPE_TRANSFORM = 7
Varying is of type Transform3D.
VaryingType VARYING_TYPE_MAX = 8
Represents the size of the VaryingType enum.
常量¶
NODE_ID_INVALID = -1
Denotes invalid VisualShader node.
NODE_ID_OUTPUT = 0
Denotes output node of VisualShader.
Property Descriptions¶
Vector2 graph_offset = Vector2(0, 0)
The offset vector of the whole graph.
Method Descriptions¶
void add_node ( Type type, VisualShaderNode node, Vector2 position, int id )
Adds the specified node
to the shader.
void add_varying ( String name, VaryingMode mode, VaryingType type )
Adds a new varying value node to the shader.
bool can_connect_nodes ( Type type, int from_node, int from_port, int to_node, int to_port ) const
Returns true
if the specified nodes and ports can be connected together.
Error connect_nodes ( Type type, int from_node, int from_port, int to_node, int to_port )
Connects the specified nodes and ports.
void connect_nodes_forced ( Type type, int from_node, int from_port, int to_node, int to_port )
Connects the specified nodes and ports, even if they can't be connected. Such connection is invalid and will not function properly.
void disconnect_nodes ( Type type, int from_node, int from_port, int to_node, int to_port )
Connects the specified nodes and ports.
VisualShaderNode get_node ( Type type, int id ) const
Returns the shader node instance with specified type
and id
.
Dictionary[] get_node_connections ( Type type ) const
Returns the list of connected nodes with the specified type.
PackedInt32Array get_node_list ( Type type ) const
Returns the list of all nodes in the shader with the specified type.
Vector2 get_node_position ( Type type, int id ) const
Returns the position of the specified node within the shader graph.
int get_valid_node_id ( Type type ) const
Returns next valid node ID that can be added to the shader graph.
bool has_varying ( String name ) const
Returns true
if the shader has a varying with the given name
.
bool is_node_connection ( Type type, int from_node, int from_port, int to_node, int to_port ) const
Returns true
if the specified node and port connection exist.
void remove_node ( Type type, int id )
Removes the specified node from the shader.
void remove_varying ( String name )
Removes a varying value node with the given name
. Prints an error if a node with this name is not found.
void replace_node ( Type type, int id, StringName new_class )
Replaces the specified node with a node of new class type.
void set_mode ( Mode mode )
Sets the mode of this shader.
void set_node_position ( Type type, int id, Vector2 position )
Sets the position of the specified node.