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,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

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