Alpha Separate VisualShaderNode 4.4

A boilerplate convenience mode that converts RGBA -> RGB + A

To use: Create a .gd file and paste the code into it. It will show up in the Addons/Utilities folder in the node search box.

Shader code
@tool
class_name VSNode_Alpha_Separate
extends VisualShaderNodeCustom

###################
## Base Props
###################
func _get_name() -> String:
	return "AlphaSeparate" ## No spaces are allowed


func _get_category() -> String:
	return "Utility"


func _get_description() -> String:
	return "Splits the alpha from a v4."


func _get_return_icon_type() -> PortType:
	return VisualShaderNode.PORT_TYPE_VECTOR_4D


#################
## Input props
#################
func _get_input_port_count() -> int:
	return 1


func _get_input_port_name(port: int) -> String:
	return "RGBA"


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


###############
## Output props
###############
func _get_output_port_count() -> int:
	return 2


func _get_output_port_name(port: int) -> String:
	match port:
		0: return "RGB"
		1: return "A"
	return "Alpha"


func _get_output_port_type(port: int) -> PortType:
	match port:
		0: return VisualShaderNode.PORT_TYPE_VECTOR_3D
		1: return VisualShaderNode.PORT_TYPE_SCALAR
	return VisualShaderNode.PORT_TYPE_SCALAR


func _get_code(input_vars: Array[String], output_vars: Array[String],
		mode: Shader.Mode, type: VisualShader.Type) -> String:
	
	var code : String = """
	%s = %s.rgb;
	%s = %s.a;

	""" % [	output_vars[0],
		input_vars[0] if input_vars[0]!= "" else "vec3(1.0,1.0,1.0)",
		output_vars[1],
		input_vars[0] if input_vars[0]!= "" else "1.0" 
		]

	return code
Live Preview
Tags
godot 4, Godot 4.0, LKS, pbr
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from wendallhitherd

Related shaders

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments