AlphaMerge VisualShaderNode 4.4

A simple boilerplate convenience node that merges RGB + A -> RGBA. Shows up in Addons/Utility folder in shadernode search menu

To use, copypaste this code into a .gd file. You may need to reload your project for it to show up

Shader code
@tool
class_name VSNode_Alpha_Merge
extends VisualShaderNodeCustom

###################
## Base Props
###################
func _get_name() -> String:
	return "AlphaMerge"


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


func _get_description() -> String:
	return "Merges an alpha channel from two inputs"


func _get_return_icon_type() -> PortType:
	return PORT_TYPE_VECTOR_4D

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


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

func _get_input_port_type(port: int) -> PortType:
	match port:
		0: return PORT_TYPE_VECTOR_3D
		1: return PORT_TYPE_SCALAR
	return PORT_TYPE_SCALAR

func _get_input_port_default_value(port: int) -> Variant:
	match port:
		0: return Vector3(1, 1, 1)
		1: return 1.0
	return Vector3(0, 0, 0)

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


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


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

func _get_code(input_vars: Array[String], output_vars: Array[String],
		mode: Shader.Mode, type: VisualShader.Type) -> String:
	return output_vars[0] + " = vec4(%s.rgb, %s);" % [input_vars[0], input_vars[1]]
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