1
0
mirror of https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git synced 2025-09-20 20:35:57 +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

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

View File

@ -1,4 +0,0 @@
float ellipse_shape(vec2 uv, float width, float height){
float _distance = length((uv * 2.0 - 1.0) / vec2(width, height));
return clamp((1.0 - _distance) / fwidth(_distance), 0.0, 1.0);
}

View File

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

View File

@ -1,10 +0,0 @@
float polygon_shape(vec2 uv, int sides, float width, float height){
float _a_width = width * cos(PI / float(sides));
float _a_height = height * cos(PI / float(sides));
uv = (uv * 2.0 - 1.0) / vec2(_a_width, _a_height);
uv.y *= -1.0;
float _polar_coords = atan(uv.x, uv.y);
float _radius = 2.0 * PI / float(sides);
float _distance = cos(floor(0.5 + _polar_coords / _radius) * _radius - _polar_coords) * length(uv);
return clamp((1.0 - _distance) / fwidth(_distance), 0.0, 1.0);
}

View File

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

View File

@ -1,5 +0,0 @@
float rectangle_shape(vec2 uv, float width, float height){
vec2 _distance = abs(uv * 2.0 - 1.0) - vec2(width, height);
_distance = 1.0 - _distance / fwidth(_distance);
return clamp(min(_distance.x, _distance.y), 0.0, 1.0);
}

View File

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

View File

@ -1,34 +0,0 @@
float rounded_polygon_shape(vec2 uv, float width, float height, float sides, float roundness){
uv = uv * 2.0 + vec2(-1.0);
roundness /= 10.0;
float _epsilon = 1e-6;
uv.x = uv.x / ( width + ((width>-_epsilon && width<_epsilon) ? 1.0 : 0.0 * _epsilon));
uv.y = uv.y / ( height + ((height>-_epsilon && height<_epsilon) ? 1.0 : 0.0 * _epsilon));
roundness = clamp(roundness, 1e-6, 1.0);
float _i_sides = floor( abs( sides ) );
float _full_angle = 2.0 * PI / _i_sides;
float _half_angle = _full_angle / 2.;
float _diagonal = 1.0 / cos( _half_angle );
float _chamfer_angle = roundness * _half_angle;
float _remaining_angle = _half_angle - _chamfer_angle;
float _ratio = tan(_remaining_angle) / tan(_half_angle);
vec2 _chamfer_center = vec2(cos(_half_angle) , sin(_half_angle))* _ratio * _diagonal;
float _dist_a = length(_chamfer_center);
float _dist_b = 1.0 - _chamfer_center.x;
float _uv_scale = _diagonal;
uv *= _uv_scale;
vec2 _polar_uv = vec2(atan(uv.y, uv.x), length(uv));
_polar_uv.x += PI / 2.0 + TAU;
_polar_uv.x = mod(_polar_uv.x + _half_angle, _full_angle );
_polar_uv.x = abs(_polar_uv.x - _half_angle);
uv = vec2(cos(_polar_uv.x), sin(_polar_uv.x)) * _polar_uv.y;
float _angle_ratio = 1.0 - (_polar_uv.x-_remaining_angle) / _chamfer_angle;
float _dist_c = sqrt(_dist_a * _dist_a + _dist_b * _dist_b - 2.0 * _dist_a *_dist_b * cos(PI - _half_angle * _angle_ratio));
float output = uv.x;
float _chamfer_zone = (_half_angle - _polar_uv.x) < _chamfer_angle ? 1.0 : 0.0;
output = mix(uv.x, _polar_uv.y / _dist_c, _chamfer_zone);
output = clamp((1.0 - output) / fwidth(output), 0.0, 1.0);
return output;
}

View File

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

View File

@ -1,7 +0,0 @@
float rounded_rectangle_shape(vec2 uv, float width, float height, float radius){
radius /= 10.0;
radius = max(min(min(abs(radius * 2.0), abs(width)), abs(height)), 1e-5);
uv = abs(uv * 2.0 - 1.0) - vec2(width, height) + radius;
float _distance = length(max(vec2(0.0), uv)) / radius;
return clamp((1.0 - _distance) / fwidth(_distance), 0.0, 1.0);
}