mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-09-20 12:25:59 +08:00
Code refactored to incorporate #6
This commit is contained in:
161
addons/ShaderLib_v2_2_4/Maths/Maths.gdshaderinc
Normal file
161
addons/ShaderLib_v2_2_4/Maths/Maths.gdshaderinc
Normal file
@ -0,0 +1,161 @@
|
||||
float chebyshev_distance_2d(vec2 point1, vec2 point2, float power) {
|
||||
vec2 p = abs(point1 - point2);
|
||||
return pow(pow(p.x, power) + pow(p.y, power), 1. / power);
|
||||
}
|
||||
|
||||
float chebyshev_distance_3d(vec3 point1, vec3 point2, float power) {
|
||||
vec3 p = abs(point1 - point2);
|
||||
return pow(pow(p.x, power) + pow(p.y, power) + pow(p.z, power), 1. / power);
|
||||
}
|
||||
|
||||
float manhattan_distance_2d(vec2 point1, vec2 point2) {
|
||||
vec2 d = point1 - point2;
|
||||
return abs(d.x) + abs(d.y);
|
||||
}
|
||||
|
||||
float manhattan_distance_3d(vec3 point1, vec3 point2) {
|
||||
vec3 d = point1 - point2;
|
||||
return abs(d.x) + abs(d.y) + abs(d.z);
|
||||
}
|
||||
|
||||
vec2 project_2d(vec2 a, vec2 b) {
|
||||
return b * (dot(a, b) / dot(b, b));
|
||||
}
|
||||
|
||||
vec3 project_3d(vec3 a, vec3 b) {
|
||||
return b * (dot(a, b) / dot(b, b));
|
||||
}
|
||||
|
||||
vec3 project_on_plane(vec3 vector, vec3 plane_normal) {
|
||||
return vector - (plane_normal * (dot(vector, plane_normal) / dot(plane_normal, plane_normal)));
|
||||
}
|
||||
|
||||
float smoothmin(float a, float b, float t) {
|
||||
float h = clamp(.5 + .5 * (b - a) / t, 0, 1);
|
||||
return mix(b, a, h) - t * h * (1. - h);
|
||||
}
|
||||
|
||||
float smoothmax(float a, float b, float t) {
|
||||
float h = clamp(.5 + .5 * (b - a) / -t, 0, 1);
|
||||
return mix(b, a, h) + t * h * (1. - h);
|
||||
}
|
||||
|
||||
vec3 vector_transform_world_to_local(mat4 model_matrix, vec3 vector) {
|
||||
return (inverse(model_matrix) * vec4(vector, 1.0)).xyz;
|
||||
}
|
||||
|
||||
vec3 vector_transform_world_to_view(mat4 view_matrix, vec3 vector) {
|
||||
return (view_matrix * vec4(vector, 1.0)).xyz;
|
||||
}
|
||||
|
||||
vec3 vector_transform_world_to_screen(mat4 view_matrix, mat4 projection_matrix, vec3 vector) {
|
||||
vec3 vector_view = vector_transform_world_to_view(view_matrix, vector);
|
||||
return (projection_matrix * vec4(vector_view, 1.0)).xyz;
|
||||
}
|
||||
|
||||
vec3 vector_transform_world_to_tangent(mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
|
||||
mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal);
|
||||
vec3 vector_local = vector_transform_world_to_local(model_matrix, vector);
|
||||
return local_to_tangent_matrix * vector_local;
|
||||
}
|
||||
|
||||
vec3 vector_transform_local_to_world(mat4 model_matrix, vec3 vector) {
|
||||
return (model_matrix * vec4(vector, 1.0)).xyz;
|
||||
}
|
||||
|
||||
vec3 vector_transform_local_to_view(mat4 model_matrix, mat4 view_matrix, vec3 vector) {
|
||||
vec3 vector_world = vector_transform_local_to_world(model_matrix, vector);
|
||||
return (view_matrix * vec4(vector_world, 1.0)).xyz;
|
||||
}
|
||||
|
||||
vec3 vector_transform_local_to_screen(mat4 model_matrix, mat4 view_matrix, mat4 projection_matrix, vec3 vector) {
|
||||
vec3 vector_view = vector_transform_local_to_view(model_matrix, view_matrix, vector);
|
||||
return (projection_matrix * vec4(vector_view, 1.0)).xyz;
|
||||
}
|
||||
|
||||
vec3 vector_transform_local_to_tangent(vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
|
||||
mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal);
|
||||
return local_to_tangent_matrix * vector;
|
||||
}
|
||||
|
||||
vec3 vector_transform_view_to_world(mat4 inv_view_matrix, vec3 vector) {
|
||||
return (inv_view_matrix * vec4(vector, 1.0)).xyz;;
|
||||
}
|
||||
|
||||
vec3 vector_transform_view_to_local(mat4 inv_view_matrix, mat4 model_matrix, vec3 vector) {
|
||||
vec3 vector_world = vector_transform_view_to_world(inv_view_matrix, vector);
|
||||
return vector_transform_world_to_local(model_matrix, vector_world);
|
||||
}
|
||||
|
||||
vec3 vector_transform_view_to_screen(mat4 projection_matrix, vec3 vector) {
|
||||
return (projection_matrix * vec4(vector, 1.0)).xyz;
|
||||
}
|
||||
|
||||
vec3 vector_transform_view_to_tangent(mat4 inv_view_matrix, mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
|
||||
mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal);
|
||||
vec3 vector_local = vector_transform_view_to_local(inv_view_matrix, model_matrix, vector);
|
||||
return vector_transform_local_to_tangent(normal, binormal, tangent, vector_local);
|
||||
}
|
||||
|
||||
vec3 vector_transform_screen_to_view(mat4 inv_projection_matrix, vec3 vector) {
|
||||
return (inv_projection_matrix * vec4(vector, 1.0)).xyz;;
|
||||
}
|
||||
|
||||
vec3 vector_transform_screen_to_local(mat4 inv_projection_matrix, mat4 inv_view_matrix, mat4 model_matrix, vec3 vector) {
|
||||
vec3 vector_view = vector_transform_screen_to_view(inv_projection_matrix, vector);
|
||||
return vector_transform_view_to_local(inv_view_matrix, model_matrix, vector_view);
|
||||
}
|
||||
|
||||
vec3 vector_transform_screen_to_world(mat4 inv_projection_matrix, mat4 inv_view_matrix, vec3 vector) {
|
||||
vec3 vector_view = vector_transform_screen_to_view(inv_projection_matrix, vector);
|
||||
return vector_transform_view_to_world(inv_view_matrix, vector_view);
|
||||
}
|
||||
|
||||
vec3 vector_transform_screen_to_tangent(mat4 inv_projection_matrix, mat4 inv_view_matrix, mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
|
||||
mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal);
|
||||
vec3 vector_local = vector_transform_screen_to_local(inv_projection_matrix, inv_view_matrix, model_matrix, vector);
|
||||
return local_to_tangent_matrix * vector_local;
|
||||
}
|
||||
|
||||
vec3 vector_transform_tangent_to_local(vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
|
||||
mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal));
|
||||
return tangent_to_local_matrix * vector;
|
||||
}
|
||||
|
||||
vec3 vector_transform_tangent_to_world(mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
|
||||
mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal));
|
||||
vec3 vector_local = tangent_to_local_matrix * vector;
|
||||
return vector_transform_local_to_world(model_matrix, vector_local);
|
||||
}
|
||||
|
||||
vec3 vector_transform_tangent_to_view(mat4 model_matrix, mat4 view_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
|
||||
mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal));
|
||||
vec3 vector_local = tangent_to_local_matrix * vector;
|
||||
return vector_transform_local_to_view(model_matrix, view_matrix, vector_local);
|
||||
}
|
||||
|
||||
vec3 vector_transform_tangent_to_screen(mat4 model_matrix, mat4 view_matrix, mat4 projection_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
|
||||
mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal));
|
||||
vec3 vector_local = tangent_to_local_matrix * vector;
|
||||
return vector_transform_local_to_screen(model_matrix, view_matrix, projection_matrix, vector_local);
|
||||
}
|
||||
|
||||
vec4 noise_sine_wave(vec4 input, vec2 min_max) {
|
||||
vec4 sin_in = sin(input);
|
||||
vec4 sin_in_offset = sin(input + 1.0);
|
||||
vec4 random_number = fract(sin((sin_in - sin_in_offset) * (12.9898 + 78.233)) * 43758.5453);
|
||||
float noise = mix(min_max.x, min_max.y, random_number.x);
|
||||
return sin_in + vec4(noise);
|
||||
}
|
||||
|
||||
vec4 sawtooth_wave(vec4 input) {
|
||||
return 2. * (input - floor(.5 + input));
|
||||
}
|
||||
|
||||
vec4 square_wave(vec4 input) {
|
||||
return 1. - 2. * round(fract(input));
|
||||
}
|
||||
|
||||
vec4 triangle_wave(vec4 input) {
|
||||
return 2. * abs(2. * (input - floor(.5 + input))) - 1.;
|
||||
}
|
55
addons/ShaderLib_v2_2_4/Maths/Scalar/SmoothMax.gd
Normal file
55
addons/ShaderLib_v2_2_4/Maths/Scalar/SmoothMax.gd
Normal file
@ -0,0 +1,55 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeScalarSmoothMax extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "SmoothMax"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Maths/Scalar"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Returns the maximum value between A and B, but smooths out the intersections of A and B based on T."
|
||||
|
||||
func _get_return_icon_type() -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 3
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
match port:
|
||||
0:
|
||||
return "a"
|
||||
1:
|
||||
return "b"
|
||||
_:
|
||||
return "t"
|
||||
|
||||
func _get_input_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_input_port_default_value(port: int) -> Variant:
|
||||
match port:
|
||||
2:
|
||||
return 0.5
|
||||
_:
|
||||
return 0.0
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "op"
|
||||
|
||||
func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var a: String = input_vars[0]
|
||||
var b: String = input_vars[1]
|
||||
var t: String = input_vars[2]
|
||||
|
||||
return output_vars[0] + " = smoothmax(%s, %s, %s);" % [a, b, t]
|
55
addons/ShaderLib_v2_2_4/Maths/Scalar/SmoothMin.gd
Normal file
55
addons/ShaderLib_v2_2_4/Maths/Scalar/SmoothMin.gd
Normal file
@ -0,0 +1,55 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeScalarSmoothMin extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "SmoothMin"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Maths/Scalar"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Returns the minimum value between A and B, but smooths out the intersections of A and B based on T."
|
||||
|
||||
func _get_return_icon_type() -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 3
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
match port:
|
||||
0:
|
||||
return "a"
|
||||
1:
|
||||
return "b"
|
||||
_:
|
||||
return "t"
|
||||
|
||||
func _get_input_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_input_port_default_value(port: int) -> Variant:
|
||||
match port:
|
||||
2:
|
||||
return 0.5
|
||||
_:
|
||||
return 0.0
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "op"
|
||||
|
||||
func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var a: String = input_vars[0]
|
||||
var b: String = input_vars[1]
|
||||
var t: String = input_vars[2]
|
||||
|
||||
return output_vars[0] + " = smoothmin(%s, %s, %s);" % [a, b, t]
|
@ -0,0 +1,94 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeMathsChebyshevDistance extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "ChebyshevDistance"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Maths/Vector/Distance"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Returns the distance between two points using Chebyshev distance matrix."
|
||||
|
||||
func _get_return_icon_type() -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 3
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
match port:
|
||||
0:
|
||||
return "a"
|
||||
1:
|
||||
return "b"
|
||||
_:
|
||||
return "power"
|
||||
|
||||
func _get_input_port_type(port: int) -> PortType:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match port:
|
||||
2:
|
||||
return PORT_TYPE_SCALAR
|
||||
_:
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_input_port_default_value(port: int) -> Variant:
|
||||
match port:
|
||||
2:
|
||||
return 2.0
|
||||
_:
|
||||
return null
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "distance"
|
||||
|
||||
func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_property_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_property_name(index: int) -> String:
|
||||
return ""
|
||||
|
||||
func _get_property_default_index(index: int) -> int:
|
||||
return 0
|
||||
|
||||
func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Vector2", "Vector3"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var point_a: String
|
||||
var point_b: String
|
||||
var power: String = input_vars[2]
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
point_a = "vec2(0)"
|
||||
point_b = "vec2(0)"
|
||||
_:
|
||||
point_b = "vec3(0)"
|
||||
point_a = "vec3(0)"
|
||||
|
||||
if input_vars[0]:
|
||||
point_a = input_vars[0]
|
||||
|
||||
if input_vars[1]:
|
||||
point_b = input_vars[1]
|
||||
|
||||
match vector_index:
|
||||
0:
|
||||
return output_vars[0] + " = chebyshev_distance_2d(%s, %s, %s);" % [point_a, point_b, power]
|
||||
_:
|
||||
return output_vars[0] + " = chebyshev_distance_3d(%s, %s, %s);" % [point_a, point_b, power]
|
@ -0,0 +1,80 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeMathsManhattanDistance extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "ManhattanDistance"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Maths/Vector/Distance"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Returns the distance between two points using Manhattan distance matrix."
|
||||
|
||||
func _get_return_icon_type() -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 2
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
match port:
|
||||
0:
|
||||
return "a"
|
||||
_:
|
||||
return "b"
|
||||
|
||||
func _get_input_port_type(port: int) -> PortType:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "distance"
|
||||
|
||||
func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_property_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_property_name(index: int) -> String:
|
||||
return ""
|
||||
|
||||
func _get_property_default_index(index: int) -> int:
|
||||
return 0
|
||||
|
||||
func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Vector2", "Vector3"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var point_a: String
|
||||
var point_b: String
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
point_a = "vec2(0)"
|
||||
point_b = "vec2(0)"
|
||||
_:
|
||||
point_b = "vec3(0)"
|
||||
point_a = "vec3(0)"
|
||||
|
||||
if input_vars[0]:
|
||||
point_a = input_vars[0]
|
||||
|
||||
if input_vars[1]:
|
||||
point_b = input_vars[1]
|
||||
|
||||
match vector_index:
|
||||
0:
|
||||
return output_vars[0] + " = manhattan_distance_2d(%s, %s);" % [point_a, point_b]
|
||||
_:
|
||||
return output_vars[0] + " = manhattan_distance_3d(%s, %s);" % [point_a, point_b]
|
77
addons/ShaderLib_v2_2_4/Maths/Vector/Project.gd
Normal file
77
addons/ShaderLib_v2_2_4/Maths/Vector/Project.gd
Normal file
@ -0,0 +1,77 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeVectorProject extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "Project"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Maths/Vector"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Projects vector A onto vector B."
|
||||
|
||||
func _get_return_icon_type() -> PortType:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 2
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
match port:
|
||||
0:
|
||||
return "vector A"
|
||||
_:
|
||||
return "vector B"
|
||||
|
||||
func _get_input_port_type(port: int) -> PortType:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "vector"
|
||||
|
||||
func _get_output_port_type(port: int) -> PortType:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_property_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_property_default_index(index: int) -> int:
|
||||
return 0
|
||||
|
||||
func _get_property_name(index: int) -> String:
|
||||
return ""
|
||||
|
||||
func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Vector2", "Vector3"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var vector_a: String = input_vars[0]
|
||||
var vector_b: String = input_vars[1]
|
||||
var vector_index: int = get_option_index(0)
|
||||
|
||||
match vector_index:
|
||||
0:
|
||||
return output_vars[0] + " = project_2d(%s, %s);" % [vector_a, vector_b]
|
||||
_:
|
||||
return output_vars[0] + " = project_3d(%s, %s);" % [vector_a, vector_b]
|
44
addons/ShaderLib_v2_2_4/Maths/Vector/ProjectOnPlane.gd
Normal file
44
addons/ShaderLib_v2_2_4/Maths/Vector/ProjectOnPlane.gd
Normal file
@ -0,0 +1,44 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeVectorProjectOnPlane extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "ProjectOnPlane"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Maths/Vector"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Projects a vector onto a plane defined by a normal orthogonal to the plane."
|
||||
|
||||
func _get_return_icon_type() -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 2
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
match port:
|
||||
0:
|
||||
return "vector"
|
||||
_:
|
||||
return "plane normal"
|
||||
|
||||
func _get_input_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "vector"
|
||||
|
||||
func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var vector_a: String = input_vars[0]
|
||||
var plane_normal: String = input_vars[1]
|
||||
return output_vars[0] + " = project_on_plane(%s, %s);" % [vector_a, plane_normal]
|
128
addons/ShaderLib_v2_2_4/Maths/Vector/VectorTransform.gd
Normal file
128
addons/ShaderLib_v2_2_4/Maths/Vector/VectorTransform.gd
Normal file
@ -0,0 +1,128 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeVectorTransform extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "VectorTransform"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Maths/Vector"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Returns the transformed vector of the input value from one coordinate space to another."
|
||||
|
||||
func _get_return_icon_type() -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
return "in"
|
||||
|
||||
func _get_input_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "out"
|
||||
|
||||
func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_property_count() -> int:
|
||||
return 2
|
||||
|
||||
func _get_property_default_index(index: int) -> int:
|
||||
match index:
|
||||
0:
|
||||
return 0
|
||||
_:
|
||||
return 1
|
||||
|
||||
func _get_property_name(index: int) -> String:
|
||||
match index:
|
||||
0:
|
||||
return "From"
|
||||
_:
|
||||
return "To"
|
||||
|
||||
func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Local", "World", "View", "Screen", "Tangent"]
|
||||
|
||||
func _is_available(mode: Shader.Mode, type: VisualShader.Type) -> bool:
|
||||
return mode == Shader.MODE_SPATIAL
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var code: String
|
||||
var from_coord_space_index: int = get_option_index(0)
|
||||
var to_coord_space_index: int = get_option_index(1)
|
||||
var input_vector: String = input_vars[0] if input_vars[0] else "vec3(0.0, 0.0, 0.0)"
|
||||
|
||||
match from_coord_space_index:
|
||||
0:
|
||||
match to_coord_space_index:
|
||||
0:
|
||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||
1:
|
||||
code = "%s = vector_transform_local_to_world(MODEL_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
2:
|
||||
code = "%s = vector_transform_local_to_view(MODEL_MATRIX, VIEW_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
3:
|
||||
code = "%s = vector_transform_local_to_screen(MODEL_MATRIX, VIEW_MATRIX, PROJECTION_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
4:
|
||||
code = "%s = vector_transform_local_to_tangent(NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
||||
1:
|
||||
match to_coord_space_index:
|
||||
0:
|
||||
code = "%s = vector_transform_world_to_local(MODEL_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
1:
|
||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||
2:
|
||||
code = "%s = vector_transform_world_to_view(VIEW_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
3:
|
||||
code = "%s = vector_transform_world_to_screen(VIEW_MATRIX, PROJECTION_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
4:
|
||||
code = "%s = vector_transform_world_to_tangent(MODEL_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
||||
2:
|
||||
match to_coord_space_index:
|
||||
0:
|
||||
code = "%s = vector_transform_view_to_local(INV_VIEW_MATRIX, MODEL_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
1:
|
||||
code = "%s = vector_transform_view_to_world(INV_VIEW_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
2:
|
||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||
3:
|
||||
code = "%s = vector_transform_view_to_screen(PROJECTION_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
4:
|
||||
code = "%s = vector_transform_view_to_tangent(INV_VIEW_MATRIX, MODEL_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
||||
3:
|
||||
match to_coord_space_index:
|
||||
0:
|
||||
code = "%s = vector_transform_screen_to_local(INV_PROJECTION_MATRIX, INV_VIEW_MATRIX, MODEL_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
1:
|
||||
code = "%s = vector_transform_screen_to_world(INV_PROJECTION_MATRIX, INV_VIEW_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
2:
|
||||
code = "%s = vector_transform_screen_to_view(INV_PROJECTION_MATRIX, %s);" % [output_vars[0], input_vector]
|
||||
3:
|
||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||
4:
|
||||
code = "%s = vector_transform_screen_to_tangent(INV_PROJECTION_MATRIX, INV_VIEW_MATRIX, MODEL_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
||||
4:
|
||||
match to_coord_space_index:
|
||||
0:
|
||||
code = "%s = vector_transform_tangent_to_local(NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
||||
1:
|
||||
code = "%s = vector_transform_tangent_to_world(MODEL_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
||||
2:
|
||||
code = "%s = vector_transform_tangent_to_view(MODEL_MATRIX, VIEW_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
||||
3:
|
||||
code = "%s = vector_transform_tangent_to_screen(MODEL_MATRIX, VIEW_MATRIX, PROJECTION_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
||||
4:
|
||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||
|
||||
return code
|
118
addons/ShaderLib_v2_2_4/Maths/Wave/NoiseSineWave.gd
Normal file
118
addons/ShaderLib_v2_2_4/Maths/Wave/NoiseSineWave.gd
Normal file
@ -0,0 +1,118 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeMathsNoiseSineWave extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "NoiseSineWave"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Maths/Wave"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Returns the sine of the value of input in. For variance, psuedo-random noise is added to the amplitude of the sine wave, within a range determined by input min max."
|
||||
|
||||
func _get_return_icon_type() -> VisualShaderNode.PortType:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_SCALAR
|
||||
1:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
2:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_4D
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 2
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
match port:
|
||||
0:
|
||||
return "in"
|
||||
1, _:
|
||||
return "min max"
|
||||
|
||||
func _get_input_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
match port:
|
||||
0:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_SCALAR
|
||||
1:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
2:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_4D
|
||||
1:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_input_port_default_value(port: int) -> Variant:
|
||||
match port:
|
||||
1:
|
||||
return Vector2(0.0, 1.0)
|
||||
_:
|
||||
return null
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "out"
|
||||
|
||||
func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_SCALAR
|
||||
1:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
2:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_4D
|
||||
|
||||
func _get_property_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_property_default_index(index: int) -> int:
|
||||
return 0
|
||||
|
||||
func _get_property_name(index: int) -> String:
|
||||
return ""
|
||||
|
||||
func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Vector1", "Vector2", "Vector3", "Vector4"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var input: String
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
input = "0.0"
|
||||
1:
|
||||
input = "vec2(0.0)"
|
||||
2:
|
||||
input = "vec3(0.0)"
|
||||
_:
|
||||
input = "vec4(0.0)"
|
||||
|
||||
if input_vars[0]:
|
||||
input = input_vars[0]
|
||||
|
||||
var min_max: String = input_vars[1]
|
||||
|
||||
match vector_index:
|
||||
0:
|
||||
return output_vars[0] + " = noise_sine_wave(vec4(%s), %s).x;" % [input, min_max]
|
||||
1:
|
||||
return output_vars[0] + " = noise_sine_wave(vec4(%s, 0.0, 0.0), %s).xy;" % [input, min_max]
|
||||
2:
|
||||
return output_vars[0] + " = noise_sine_wave(vec4(%s, 0.0), %s).xyz;" % [input, min_max]
|
||||
_:
|
||||
return output_vars[0] + " = noise_sine_wave(%s, %s);" % [input, min_max]
|
100
addons/ShaderLib_v2_2_4/Maths/Wave/SawtoothWave.gd
Normal file
100
addons/ShaderLib_v2_2_4/Maths/Wave/SawtoothWave.gd
Normal file
@ -0,0 +1,100 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeMathsSawtoothWave extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "SawtoothWave"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Maths/Wave"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Returns a sawtooth wave from the value of input in. Resulting output values will be between -1 and 1."
|
||||
|
||||
func _get_return_icon_type() -> VisualShaderNode.PortType:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_SCALAR
|
||||
1:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
2:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_4D
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
return "in"
|
||||
|
||||
func _get_input_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_SCALAR
|
||||
1:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
2:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_4D
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "out"
|
||||
|
||||
func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_SCALAR
|
||||
1:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
2:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_4D
|
||||
|
||||
func _get_property_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_property_default_index(index: int) -> int:
|
||||
return 0
|
||||
|
||||
func _get_property_name(index: int) -> String:
|
||||
return ""
|
||||
|
||||
func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Vector1", "Vector2", "Vector3", "Vector4"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var input: String
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
input = "0.0"
|
||||
1:
|
||||
input = "vec2(0.0)"
|
||||
2:
|
||||
input = "vec3(0.0)"
|
||||
_:
|
||||
input = "vec4(0.0)"
|
||||
|
||||
if input_vars[0]:
|
||||
input = input_vars[0]
|
||||
|
||||
match vector_index:
|
||||
0:
|
||||
return output_vars[0] + " = sawtooth_wave(vec4(%s)).x;" % [input]
|
||||
1:
|
||||
return output_vars[0] + " = sawtooth_wave(vec4(%s, 0.0, 0.0)).xy;" % [input]
|
||||
2:
|
||||
return output_vars[0] + " = sawtooth_wave(vec4(%s, 0.0)).xyz;" % [input]
|
||||
_:
|
||||
return output_vars[0] + " = sawtooth_wave(%s);" % [input]
|
101
addons/ShaderLib_v2_2_4/Maths/Wave/SquareWave.gd
Normal file
101
addons/ShaderLib_v2_2_4/Maths/Wave/SquareWave.gd
Normal file
@ -0,0 +1,101 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeMathsSquareWave extends ShaderLib
|
||||
|
||||
|
||||
func _get_name() -> String:
|
||||
return "SquareWave"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Maths/Wave"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Returns a square wave from the value of input in. Resulting output values will be between -1 and 1."
|
||||
|
||||
func _get_return_icon_type() -> VisualShaderNode.PortType:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_SCALAR
|
||||
1:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
2:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_4D
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
return "input"
|
||||
|
||||
func _get_input_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_SCALAR
|
||||
1:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
2:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_4D
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "out"
|
||||
|
||||
func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_SCALAR
|
||||
1:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
2:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_4D
|
||||
|
||||
func _get_property_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_property_default_index(index: int) -> int:
|
||||
return 0
|
||||
|
||||
func _get_property_name(index: int) -> String:
|
||||
return ""
|
||||
|
||||
func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Vector1", "Vector2", "Vector3", "Vector4"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var input: String
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
input = "0.0"
|
||||
1:
|
||||
input = "vec2(0.0)"
|
||||
2:
|
||||
input = "vec3(0.0)"
|
||||
_:
|
||||
input = "vec4(0.0)"
|
||||
|
||||
if input_vars[0]:
|
||||
input = input_vars[0]
|
||||
|
||||
match vector_index:
|
||||
0:
|
||||
return output_vars[0] + " = square_wave(vec4(%s)).x;" % [input]
|
||||
1:
|
||||
return output_vars[0] + " = square_wave(vec4(%s, 0.0, 0.0)).xy;" % [input]
|
||||
2:
|
||||
return output_vars[0] + " = square_wave(vec4(%s, 0.0)).xyz;" % [input]
|
||||
_:
|
||||
return output_vars[0] + " = square_wave(%s);" % [input]
|
99
addons/ShaderLib_v2_2_4/Maths/Wave/TriangleWave.gd
Normal file
99
addons/ShaderLib_v2_2_4/Maths/Wave/TriangleWave.gd
Normal file
@ -0,0 +1,99 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeMathsTriangleWave extends ShaderLib
|
||||
|
||||
func _get_name() -> String:
|
||||
return "TriangleWave"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Maths/Wave"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Returns a triangle wave from the value of input in. Resulting output values will be between -1 and 1."
|
||||
|
||||
func _get_return_icon_type() -> VisualShaderNode.PortType:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_SCALAR
|
||||
1:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
2:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_4D
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
return "in"
|
||||
func _get_input_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_SCALAR
|
||||
1:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
2:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_4D
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "out"
|
||||
|
||||
func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_SCALAR
|
||||
1:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
2:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_4D
|
||||
|
||||
func _get_property_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_property_default_index(index: int) -> int:
|
||||
return 0
|
||||
|
||||
func _get_property_name(index: int) -> String:
|
||||
return ""
|
||||
|
||||
func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Vector1", "Vector2", "Vector3", "Vector4"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var input: String
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
input = "0.0"
|
||||
1:
|
||||
input = "vec2(0.0)"
|
||||
2:
|
||||
input = "vec3(0.0)"
|
||||
_:
|
||||
input = "vec4(0.0)"
|
||||
|
||||
if input_vars[0]:
|
||||
input = input_vars[0]
|
||||
|
||||
match vector_index:
|
||||
0:
|
||||
return output_vars[0] + " = triangle_wave(vec4(%s)).x;" % [input]
|
||||
1:
|
||||
return output_vars[0] + " = triangle_wave(vec4(%s, 0.0, 0.0)).xy;" % [input]
|
||||
2:
|
||||
return output_vars[0] + " = triangle_wave(vec4(%s, 0.0)).xyz;" % [input]
|
||||
_:
|
||||
return output_vars[0] + " = triangle_wave(%s);" % [input]
|
Reference in New Issue
Block a user