1
0
mirror of https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git synced 2025-09-20 12:25:59 +08:00

ShaderInc files refactored for the ease of future improvements

This commit is contained in:
Digvijaysinh Gohil
2024-07-21 16:39:45 +05:30
parent 0a8948118f
commit e33f70baa9
125 changed files with 706 additions and 733 deletions

View File

@ -1,3 +1,45 @@
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;
}
@ -97,3 +139,23 @@ vec3 vector_transform_tangent_to_screen(mat4 model_matrix, mat4 view_matrix, mat
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.;
}

View File

@ -45,8 +45,7 @@ func _get_output_port_type(port: int) -> PortType:
return PORT_TYPE_SCALAR
func _get_global_code(mode: Shader.Mode) -> String:
var code: String = preload("SmoothMax.gdshaderinc").code
return code
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var a: String = input_vars[0]

View File

@ -1,4 +0,0 @@
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);
}

View File

@ -45,8 +45,7 @@ func _get_output_port_type(port: int) -> PortType:
return PORT_TYPE_SCALAR
func _get_global_code(mode: Shader.Mode) -> String:
var code: String = preload("SmoothMin.gdshaderinc").code
return code
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var a: String = input_vars[0]

View File

@ -1,4 +0,0 @@
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);
}

View File

@ -1,4 +0,0 @@
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);
}

View File

@ -1,4 +0,0 @@
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);
}

View File

@ -66,14 +66,7 @@ func _get_property_options(index: int) -> PackedStringArray:
return ["Vector2", "Vector3"]
func _get_global_code(mode: Shader.Mode) -> String:
var code: String
var vector_index: int = get_option_index(0)
match vector_index:
0:
code = preload("Chebyshev2D.gdshaderinc").code
_:
code = preload("Chebyshev3D.gdshaderinc").code
return code
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var point_a: String

View File

@ -1,4 +0,0 @@
float manhattan_distance_2d(vec2 point1, vec2 point2) {
vec2 d = point1 - point2;
return abs(d.x) + abs(d.y);
}

View File

@ -1,4 +0,0 @@
float manhattan_distance_3d(vec3 point1, vec3 point2) {
vec3 d = point1 - point2;
return abs(d.x) + abs(d.y) + abs(d.z);
}

View File

@ -53,14 +53,7 @@ func _get_property_options(index: int) -> PackedStringArray:
return ["Vector2", "Vector3"]
func _get_global_code(mode: Shader.Mode) -> String:
var code: String
var vector_index: int = get_option_index(0)
match vector_index:
0:
code = preload("Manhattan2D.gdshaderinc").code
_:
code = preload("Manhattan3D.gdshaderinc").code
return code
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var point_a: String

View File

@ -63,8 +63,7 @@ func _get_property_options(index: int) -> PackedStringArray:
return ["Vector2", "Vector3"]
func _get_global_code(mode: Shader.Mode) -> String:
var code: String = preload("Project.gdshaderinc").code
return code
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
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]

View File

@ -1,7 +0,0 @@
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));
}

View File

@ -36,8 +36,7 @@ func _get_output_port_type(port: int) -> PortType:
return PORT_TYPE_VECTOR_3D
func _get_global_code(mode: Shader.Mode) -> String:
var code: String = preload("ProjectOnPlane.gdshaderinc").code
return code
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
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]

View File

@ -1,3 +0,0 @@
vec3 project_on_plane(vec3 vector, vec3 plane_normal) {
return vector - (plane_normal * (dot(vector, plane_normal) / dot(plane_normal, plane_normal)));
}

View File

@ -55,8 +55,7 @@ func _is_available(mode: Shader.Mode, type: VisualShader.Type) -> bool:
return mode == Shader.MODE_SPATIAL
func _get_global_code(mode: Shader.Mode) -> String:
var code: String = preload("VectorTransform.gdshaderinc").code
return code
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var code: String

View File

@ -87,8 +87,7 @@ func _get_property_options(index: int) -> PackedStringArray:
return ["Vector1", "Vector2", "Vector3", "Vector4"]
func _get_global_code(mode: Shader.Mode) -> String:
var code: String = preload("NoiseSineWave.gdshaderinc").code
return code
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var input: String

View File

@ -1,8 +0,0 @@
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);
}

View File

@ -71,8 +71,7 @@ func _get_property_options(index: int) -> PackedStringArray:
return ["Vector1", "Vector2", "Vector3", "Vector4"]
func _get_global_code(mode: Shader.Mode) -> String:
var code: String = preload("SawtoothWave.gdshaderinc").code
return code
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var input: String

View File

@ -1,3 +0,0 @@
vec4 sawtooth_wave(vec4 input) {
return 2. * (input - floor(.5 + input));
}

View File

@ -72,8 +72,7 @@ func _get_property_options(index: int) -> PackedStringArray:
return ["Vector1", "Vector2", "Vector3", "Vector4"]
func _get_global_code(mode: Shader.Mode) -> String:
var code: String = preload("SquareWave.gdshaderinc").code
return code
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var input: String

View File

@ -1,3 +0,0 @@
vec4 square_wave(vec4 input) {
return 1. - 2. * round(fract(input));
}

View File

@ -70,8 +70,7 @@ func _get_property_options(index: int) -> PackedStringArray:
return ["Vector1", "Vector2", "Vector3", "Vector4"]
func _get_global_code(mode: Shader.Mode) -> String:
var code: String = preload("TriangleWave.gdshaderinc").code
return code
return "#include \"res://addons/ShaderLib/Maths/Maths.gdshaderinc\""
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var input: String

View File

@ -1,3 +0,0 @@
vec4 triangle_wave(vec4 input) {
return 2. * abs(2. * (input - floor(.5 + input))) - 1.;
}