1
0
mirror of https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git synced 2025-01-07 01:43:35 +08:00

NodeScaleWorld node added

This commit is contained in:
Digvijaysinh Gohil 2023-10-20 19:02:16 +05:30
parent 6213ca89c3
commit 7b16ab0b8f
2 changed files with 47 additions and 0 deletions

View File

@ -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);"

View File

@ -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);
}