Created
September 20, 2023 01:51
-
-
Save cmargroff/4e533ceedec07b49d41c734b3191e607 to your computer and use it in GitHub Desktop.
Ellipse node for Godot Visual Shader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@tool | |
class_name VisualShaderNodeEllipse | |
extends VisualShaderNodeCustom | |
func _get_name(): | |
return "Ellipse" | |
func _get_category(): | |
return "" | |
func _get_description(): | |
return "Draws an ellipse" | |
func _get_return_icon_type(): | |
return PORT_TYPE_SCALAR | |
func _get_input_port_count(): | |
return 3 | |
func _get_input_port_name(port): | |
if(port == 0): return "UV" | |
if(port == 1): return "Width" | |
return "Height" | |
func _get_input_port_type(port): | |
if(port == 0): return PORT_TYPE_VECTOR_2D | |
return PORT_TYPE_SCALAR | |
func _get_output_port_count(): | |
return 1 | |
func _get_output_port_name(port): | |
return "Out" | |
func _get_output_port_type(port): | |
return PORT_TYPE_SCALAR | |
func _get_code(input_vars, output_vars, | |
mode, type): | |
var UV = input_vars[0] | |
var Width = input_vars[1] | |
var Height = input_vars[2] | |
var Out = output_vars[0] | |
return "float d = length((%s * 2.0 - 1.0) / vec2(%s, %s));\n" % [UV, Width, Height] \ | |
+ "%s = clamp((1.0 - d) / fwidth(d), 0.0, 1.0);" % Out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment