Skip to content

Instantly share code, notes, and snippets.

@cmargroff
Last active September 18, 2023 19:26
Show Gist options
  • Save cmargroff/c40fa899dcb0566e6ccd4874b7a12743 to your computer and use it in GitHub Desktop.
Save cmargroff/c40fa899dcb0566e6ccd4874b7a12743 to your computer and use it in GitHub Desktop.
A UV Rotate convenience node for Godot Visual Shader
@tool
class_name VisualShaderNodeUvRotate
extends VisualShaderNodeCustom
func _get_name():
return "UV Rotate"
func _get_description():
return ""
func _get_return_icon_type():
return PORT_TYPE_VECTOR_2D
func _get_input_port_count():
return 3
func _get_input_port_name(port):
if (port == 0): return "UV"
if (port == 1): return "Center"
return "Rotation"
func _get_input_port_type(port):
if (port < 2): return PORT_TYPE_VECTOR_2D
return PORT_TYPE_SCALAR
func _get_output_port_count():
return 1
func _get_output_port_name(port):
return "UV"
func _get_output_port_type(port):
return PORT_TYPE_VECTOR_2D
func _get_code(inputVars, outputVars,
mode, type):
var UV = inputVars[0];
var Center = inputVars[1];
var Rotation = inputVars[2];
var Out = outputVars[0];
return "%s -= %s;\n" % [UV, Center] \
+ "float s = sin(%s);\n" % Rotation \
+ "float c = cos(%s);\n" % Rotation \
+ "%s = vec2(c * %s.x - s * %s.y, s * %s.x + c * %s.y);\n" % [UV, UV, UV, UV, UV] \
+ "%s += %s;\n" % [UV, Center] \
+ "%s = %s;" % [Out, UV];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment