diff --git a/addons/ShaderLib/Input/NodeScaleWorld.gd b/addons/ShaderLib/Input/NodeScaleWorld.gd new file mode 100644 index 0000000..7cb3313 --- /dev/null +++ b/addons/ShaderLib/Input/NodeScaleWorld.gd @@ -0,0 +1,36 @@ +@tool +class_name VisualShaderNodeInputNodeScaleWorld extends VisualShaderNodeCustom + +func _get_name() -> String: + return "NodeScaleWorld" + +func _get_category() -> String: + return "Input" + +func _get_description() -> String: + return "Provides accees to node scale in world space." + +func _get_input_port_count() -> int: + return 0 + +func _get_input_port_name(port: int) -> String: + return "" + +func _get_return_icon_type() -> VisualShaderNode.PortType: + return PORT_TYPE_VECTOR_3D + +func _get_output_port_count() -> int: + return 1 + +func _get_output_port_name(port: int) -> String: + return "scale" + +func _get_output_port_type(port: int) -> VisualShaderNode.PortType: + return PORT_TYPE_VECTOR_3D + +func _get_global_code(mode: Shader.Mode) -> String: + var code: String = preload("NodeScaleWorld.gdshaderinc").code + return code + +func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: + return output_vars[0] + " = node_scale_world(MODEL_MATRIX);" diff --git a/addons/ShaderLib/Input/NodeScaleWorld.gdshaderinc b/addons/ShaderLib/Input/NodeScaleWorld.gdshaderinc new file mode 100644 index 0000000..fd48004 --- /dev/null +++ b/addons/ShaderLib/Input/NodeScaleWorld.gdshaderinc @@ -0,0 +1,11 @@ +vec3 node_scale_world(mat4 model_matrix){ + vec3 _axis_x = model_matrix[0].xyz; + vec3 _axis_y = model_matrix[1].xyz; + vec3 _axis_z = model_matrix[2].xyz; + + float _scale_x = length(_axis_x); + float _scale_y = length(_axis_y); + float _scale_z = length(_axis_z); + + return vec3(_scale_x, _scale_y, _scale_z); +} \ No newline at end of file