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

Merge branch 'godot-4.2'

This commit is contained in:
Digvijaysinh Gohil 2024-03-14 19:30:47 +05:30
commit 4844686953
34 changed files with 1228 additions and 73 deletions

View File

@ -0,0 +1,60 @@
@tool
class_name VisualShaderNodeAdjustmentContrast extends VisualShaderNodeCustom
func _get_name() -> String:
return "Contrast"
func _get_category() -> String:
return "Artistic/Adjustment"
func _get_description() -> String:
return "Adjusts the contrast of input in by the amount of input contrast."
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 "in"
_:
return "contrast"
func _get_input_port_type(port: int) -> PortType:
match port:
0:
return PORT_TYPE_VECTOR_3D
_:
return PORT_TYPE_SCALAR
func _get_input_port_default_value(port: int) -> Variant:
match port:
1:
return 1.0
_:
return Vector3(1.0, 1.0, 1.0)
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_global_code(mode: Shader.Mode) -> String:
var code: String = preload("Contrast.gdshaderinc").code
return code
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var input: String = "vec3(1.0)"
if input_vars[0]:
input = input_vars[0]
var contrast: String = input_vars[1]
return output_vars[0] + " = contrast(%s, %s);" % [input, contrast]

View File

@ -0,0 +1,4 @@
vec3 contrast(vec3 input, float contrast){
float midpoint = pow(0.5, 2.2);
return (input - midpoint) * contrast + midpoint;
}

View File

@ -0,0 +1,73 @@
@tool
class_name VisualShaderNodeAdjustmentHue extends VisualShaderNodeCustom
func _get_name() -> String:
return "Hue"
func _get_category() -> String:
return "Artistic/Adjustment"
func _get_description() -> String:
return "Offsets the hue of input in by the amount of input offset."
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 "in"
_:
return "offset"
func _get_input_port_type(port: int) -> PortType:
match port:
0:
return PORT_TYPE_VECTOR_3D
_:
return PORT_TYPE_SCALAR
func _get_input_port_default_value(port: int) -> Variant:
match port:
1:
return 0.0
_:
return Vector3(1.0, 1.0, 1.0)
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 1
func _get_property_default_index(index: int) -> int:
return 0
func _get_property_name(index: int) -> String:
return "Range"
func _get_property_options(index: int) -> PackedStringArray:
return ["Degrees", "Normalize"]
func _get_global_code(mode: Shader.Mode) -> String:
var code: String = preload("Hue.gdshaderinc").code
return code
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var range_index: int = get_option_index(0)
var input: String = "vec3(1.0)"
var offset: String = input_vars[1]
if input_vars[0]:
input = input_vars[0]
return output_vars[0] + " = hue(%s, %s, %s);" % [input, offset, range_index]

View File

@ -0,0 +1,27 @@
vec3 hue(vec3 input, float offset, int range_index){
// RGB to HSV
vec4 k = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(input.bg, k.wz), vec4(input.gb, k.xy), step(input.b, input.g));
vec4 q = mix(vec4(p.xyw, input.r), vec4(input.r, p.yzx), step(p.x, input.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
vec3 hsv = vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
offset = (range_index == 0) ? offset / 360.0 : offset;
float hue = hsv.x + offset;
if(hue < 0.0){
hsv.x = hue + 1.;
}
else if(hue > 1.){
hsv.x = hue - 1.;
}
else{
hsv.x = hue;
}
// HSV to RGB
vec4 k2 = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p2 = abs(fract(hsv.xxx + k2.xyz) * 6.0 - k2.www);
vec3 rgb = hsv.z * mix(k2.xxx, clamp(p2 - k2.xxx, 0.0, 1.0), hsv.y);
return rgb;
}

View File

@ -0,0 +1,78 @@
@tool
class_name VisualShaderNodeAdjustmentReplaceColor extends VisualShaderNodeCustom
func _get_name() -> String:
return "ReplaceColor"
func _get_category() -> String:
return "Artistic/Adjustment"
func _get_description() -> String:
return "Replaces values in input \"in\" equal to input \"from\" to the value of input \"to\"."
func _get_return_icon_type() -> PortType:
return PORT_TYPE_VECTOR_3D
func _get_input_port_count() -> int:
return 5
func _get_input_port_name(port: int) -> String:
match port:
0:
return "in"
1:
return "from"
2:
return "to"
3:
return "range"
_:
return "fuzziness"
func _get_input_port_type(port: int) -> PortType:
match port:
0, 1, 2:
return PORT_TYPE_VECTOR_3D
_:
return PORT_TYPE_SCALAR
func _get_input_port_default_value(port: int) -> Variant:
match port:
1, 2:
return Vector3(0.0, 0.0, 0.0)
3, 4:
return 0.0
_:
return Vector3(1.0, 1.0, 1.0)
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_global_code(mode: Shader.Mode) -> String:
var code: String = preload("ReplaceColor.gdshaderinc").code
return code
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var input: String = "vec3(1.0)"
var from: String = "vec3(1.0)"
var to: String = "vec3(1.0)"
if input_vars[0]:
input = input_vars[0]
if input_vars[1]:
from = input_vars[1]
if input_vars[2]:
to = input_vars[2]
var range: String = input_vars[3]
var fuzziness: String = input_vars[4]
return output_vars[0] + " = replace_color(%s, %s, %s, %s, %s);" % [input, from, to, range, fuzziness]

View File

@ -0,0 +1,4 @@
vec3 replace_color(vec3 input, vec3 from, vec3 to, float range, float fuzziness){
float dist = distance(from, input);
return mix(to, input, clamp((dist - range) / max(fuzziness, 1.0e-5), 0.0, 1.0));
}

View File

@ -0,0 +1,61 @@
@tool
class_name VisualShaderNodeAdjustmentSaturation extends VisualShaderNodeCustom
func _get_name() -> String:
return "Saturation"
func _get_category() -> String:
return "Artistic/Adjustment"
func _get_description() -> String:
return "Adjusts the saturation of input \"in\" by the amount of input \"saturation\"."
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 "in"
_:
return "saturation"
func _get_input_port_type(port: int) -> PortType:
match port:
0:
return PORT_TYPE_VECTOR_3D
_:
return PORT_TYPE_SCALAR
func _get_input_port_default_value(port: int) -> Variant:
match port:
0:
return Vector3(1.0, 1.0, 1.0)
_:
return 1.0
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_global_code(mode: Shader.Mode) -> String:
var code: String = preload("Saturation.gdshaderinc").code
return code
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var input: String = "vec3(1.0)"
if input_vars[0]:
input = input_vars[0]
var saturation = input_vars[1]
return output_vars[0] + " = saturation(%s, %s);" % [input, saturation]

View File

@ -0,0 +1,4 @@
vec3 saturation(vec3 input, float saturation){
float luma = dot(input, vec3(0.2126729, 0.7151522, 0.0721750));
return luma + saturation * (input - vec3(luma));
}

View File

@ -0,0 +1,64 @@
@tool
class_name VisualShaderNodeWhiteBalance extends VisualShaderNodeCustom
func _get_name() -> String:
return "WhiteBalance"
func _get_category() -> String:
return "Artistic/Adjustment"
func _get_description() -> String:
return "Adjusts the temperature and tint of input \"in\" by the amount of inputs \"temperature\" and \"tint\" respectively."
func _get_return_icon_type() -> PortType:
return PORT_TYPE_VECTOR_3D
func _get_input_port_count() -> int:
return 3
func _get_input_port_name(port: int) -> String:
match port:
0:
return "in"
1:
return "temperature"
_:
return "tint"
func _get_input_port_type(port: int) -> PortType:
match port:
0:
return PORT_TYPE_VECTOR_3D
_:
return PORT_TYPE_SCALAR
func _get_input_port_default_value(port: int) -> Variant:
match port:
1, 2:
return 0.0
_:
return Vector3(1.0, 1.0, 1.0)
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_global_code(mode: Shader.Mode) -> String:
var code: String = preload("WhiteBalance.gdshaderinc").code
return code
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var input: String = "vec3(1.0)"
if input_vars[0]:
input = input_vars[0]
var temperature: String = input_vars[1]
var tint: String = input_vars[2]
return output_vars[0] + " = white_balance(%s, %s, %s);" % [input, temperature, tint]

View File

@ -0,0 +1,36 @@
vec3 white_balance(vec3 input, float temperature, float tint){
float t1 = temperature * 10.0 / 6.0;
float t2 = tint * 10.0 / 6.0;
float x = 0.31271 - t1 * (t1 < 0.0 ? 0.1 : 0.05);
float standard_illuminant_y = 2.87 * x - 3.0 * x * x - 0.27509507;
float y = standard_illuminant_y + t2 * 0.05;
vec3 w1 = vec3(0.949237, 1.03542, 1.08728);
float Y = 1.;
float X = Y * x / y;
float Z = Y * (1. - x - y) / y;
float L = 0.7328 * X + 0.4296 * Y - 0.1624 * Z;
float M = -0.7036 * X + 1.6975 * Y + 0.0061 * Z;
float S = 0.0030 * X + 0.0136 * Y + 0.9834 * Z;
vec3 w2 = vec3(L, M, S);
vec3 balance = vec3(w1.x / w2.x, w1.y / w2.y, w1.z / w2.z);
mat3 LIN_2_LMS_MAT = mat3(
vec3(3.90405e-1, 5.49941e-1, 8.92632e-3),
vec3(7.08416e-2, 9.63172e-1, 1.35775e-3),
vec3(2.31082e-2, 1.28021e-1, 9.36245e-1)
);
mat3 LMS_2_LIN_MAT = mat3(
vec3(2.85847, -1.62879, -2.48910),
vec3(-2.10182e-1, 1.15820e+0, 3.24281e-4),
vec3(-4.18120e-2, -1.18169e-1, 1.06867e+0)
);
vec3 lms = LIN_2_LMS_MAT * input;
lms *= balance;
return LMS_2_LIN_MAT * lms;
}

View File

@ -0,0 +1,69 @@
@tool
class_name VisualShaderNodeMaskColorMask extends VisualShaderNodeCustom
func _get_name() -> String:
return "ColorMask"
func _get_category() -> String:
return "Artistic/Mask"
func _get_description() -> String:
return "Creates a mask from values in input \"in\" equal to input \"mask color\"."
func _get_return_icon_type() -> PortType:
return PORT_TYPE_VECTOR_4D
func _get_input_port_count() -> int:
return 4
func _get_input_port_name(port: int) -> String:
match port:
0:
return "in"
1:
return "color mask"
2:
return "range"
_:
return "fuzziness"
func _get_input_port_type(port: int) -> PortType:
match port:
0, 1:
return PORT_TYPE_VECTOR_3D
_:
return PORT_TYPE_SCALAR
func _get_input_port_default_value(port: int) -> Variant:
match port:
0:
return Vector3(1.0, 1.0, 1.0)
1:
return Vector3(0.0, 0.0, 0.0)
_:
return 0.0
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_4D
func _get_global_code(mode: Shader.Mode) -> String:
var code: String = preload("ColorMask.gdshaderinc").code
return code
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var input: String = "vec3(0.0)"
if input_vars[0]:
input = input_vars[0]
var color_mask: String = input_vars[1]
var range: String = input_vars[2]
var fuzziness: String = input_vars[3]
return output_vars[0] + " = color_mask(%s, %s, %s, %s);" % [input, color_mask, range, fuzziness]

View File

@ -0,0 +1,4 @@
vec4 color_mask(vec3 input, vec3 mask_color, float range, float fuzziness){
float dist = distance(mask_color, input);
return vec4(clamp(1. - (dist - range) / max(fuzziness, 1e-5), 0., 1.));
}

View File

@ -0,0 +1,74 @@
@tool
class_name VisualShaderNodeVectorProject extends VisualShaderNodeCustom
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_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] + " = vec2(%s.xy) * (dot(%s.xy, %s.xy) / dot(%s.xy, %s.xy));" % [vector_b, vector_a, vector_b, vector_b, vector_b]
_:
return output_vars[0] + " = %s * (dot(%s, %s) / dot(%s, %s));" % [vector_b, vector_a, vector_b, vector_b, vector_b]

View File

@ -0,0 +1,73 @@
@tool
class_name VisualShaderNodeVectorProjectOnPlane extends VisualShaderNodeCustom
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:
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"
_:
return "plane normal"
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_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]
var vector_index: int = get_option_index(0)
match vector_index:
0:
return output_vars[0] + " = %s.xy - (%s.xy * (dot(%s.xy, %s.xy) / dot(%s.xy, %s.xy)));" % [vector_a, plane_normal, vector_a, plane_normal, plane_normal, plane_normal]
_:
return output_vars[0] + " = %s - (%s * (dot(%s, %s) / dot(%s, %s)));" % [vector_a, plane_normal, vector_a, plane_normal, plane_normal, plane_normal]

View File

@ -11,7 +11,16 @@ 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:
return PORT_TYPE_VECTOR_4D
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
@ -26,7 +35,16 @@ func _get_input_port_name(port: int) -> String:
func _get_input_port_type(port: int) -> VisualShaderNode.PortType:
match port:
0:
return PORT_TYPE_VECTOR_4D
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
@ -45,16 +63,57 @@ func _get_output_port_name(port: int) -> String:
return "out"
func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
return PORT_TYPE_VECTOR_4D
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:
var code: String = preload("NoiseSineWave.gdshaderinc").code
return code
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var input: String = "vec4(0.0)"
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]
return output_vars[0] + " = noise_sine_wave(%s, %s);" % [input, min_max]
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]

View File

@ -11,7 +11,16 @@ 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:
return PORT_TYPE_VECTOR_4D
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
@ -20,7 +29,16 @@ func _get_input_port_name(port: int) -> String:
return "in"
func _get_input_port_type(port: int) -> VisualShaderNode.PortType:
return PORT_TYPE_VECTOR_4D
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
@ -29,10 +47,43 @@ func _get_output_port_name(port: int) -> String:
return "out"
func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
return PORT_TYPE_VECTOR_4D
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_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var input: String = "vec4(0.0)"
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]
return output_vars[0] + " = 2.0 * (%s - floor(0.5 + %s));" % [input, input]

View File

@ -12,7 +12,16 @@ 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:
return PORT_TYPE_VECTOR_4D
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
@ -21,7 +30,16 @@ func _get_input_port_name(port: int) -> String:
return "input"
func _get_input_port_type(port: int) -> VisualShaderNode.PortType:
return PORT_TYPE_VECTOR_4D
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
@ -30,10 +48,43 @@ func _get_output_port_name(port: int) -> String:
return "out"
func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
return PORT_TYPE_VECTOR_4D
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_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var input: String = "vec4(0.0)"
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]
return output_vars[0] + " = 1.0 - 2.0 * round(fract(%s));" % [input]

View File

@ -11,7 +11,16 @@ 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:
return PORT_TYPE_VECTOR_4D
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
@ -19,7 +28,16 @@ func _get_input_port_count() -> int:
func _get_input_port_name(port: int) -> String:
return "in"
func _get_input_port_type(port: int) -> VisualShaderNode.PortType:
return PORT_TYPE_VECTOR_4D
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
@ -28,10 +46,43 @@ func _get_output_port_name(port: int) -> String:
return "out"
func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
return PORT_TYPE_VECTOR_4D
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_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var input: String = "vec4(0.0)"
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]
return output_vars[0] + " = 2.0 * abs(2.0 * (%s - floor(0.5 + %s))) - 1.0;" % [input, input]

View File

@ -0,0 +1,86 @@
@tool
class_name VisualShaderNodeProceduralKochFractal extends VisualShaderNodeCustom
func _init() -> void:
output_port_for_preview = 0
func _get_name() -> String:
return "KochFractal"
func _get_category() -> String:
return "Procedural/Fractals"
func _get_description() -> String:
return "Generates an koch curve similar to ice fractal shape based on input UV at the size specified by inputs width and height."
func _get_return_icon_type() -> PortType:
return PORT_TYPE_SCALAR
func _get_input_port_count() -> int:
return 5
func _get_input_port_name(port: int) -> String:
match port:
0:
return "uv"
1:
return "thickness"
2:
return "iterations"
3:
return "widht"
_:
return "height"
func _get_input_port_type(port: int) -> PortType:
match port:
0:
return PORT_TYPE_VECTOR_2D
2:
return PORT_TYPE_SCALAR_INT
_:
return PORT_TYPE_SCALAR
func _get_input_port_default_value(port: int) -> Variant:
match port:
1, 3, 4:
return 1.0
2:
return 3
_:
return null
func _get_output_port_count() -> int:
return 2
func _get_output_port_name(port: int) -> String:
match port:
0:
return "out"
_:
return "uv"
func _get_output_port_type(port: int) -> PortType:
match port:
1:
return PORT_TYPE_VECTOR_2D
_:
return PORT_TYPE_SCALAR
func _get_global_code(mode: Shader.Mode) -> String:
var code: String = preload("KochFractal.gdshaderinc").code
return code
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var uv: String = "UV"
if input_vars[0]:
uv = input_vars[0]
var thickness: String = input_vars[1]
var iterations: String = input_vars[2]
var width: String = input_vars[3]
var height: String = input_vars[4]
return output_vars[0] + " = koch_fractal(%s, %s, %s, %s, %s, %s);" % [uv, thickness, iterations, width, height, output_vars[1]]

View File

@ -0,0 +1,36 @@
vec2 koch_fractal_direction(float angle){
return vec2(sin(angle), cos(angle));
}
float koch_fractal(vec2 uv, float outline, int iteration, float shape_width, float shape_height, out vec2 koch_uv) {
float tiling = 3.0;
vec2 center = uv - vec2(.5);
shape_width = .85 * (shape_width / 1.);
shape_height = .85 * (shape_height / 1.);
center.x /= shape_width;
center.y /= shape_height;
center.x = abs(center.x);
center.y += tan(.833 * PI) * .5;
vec2 dir = koch_fractal_direction(.833 * PI);
float dist = dot(center - vec2(tiling / (2. * tiling), 0), dir);
center -= dir * max(0, dist) * 2.0;
dir = koch_fractal_direction(.6667 * PI);
float scale = 1.0;
center.x += .5;
for(int i = 0; i < iteration; i++){
center *= tiling;
scale *= tiling;
center.x -= .5 * tiling;
center.x = abs(center.x);
center.x -= .5;
center -= dir * min(0.0, dot(center, dir)) * 2.0;
}
dist = length(center - vec2(clamp(center.x, -1.0, 1.0), 0));
dist += step(outline / 100.0, dist / scale);
koch_uv = abs(center);
return 1.0 - dist;
}

View File

@ -5,59 +5,69 @@ If you don't immediatly see new nodes under **_Addons_** category, simply reload
# Uninstallation
Delete the contents of **_addons/ShaderLib_** folder from your project. Make sure to delete it using the Godot editor instead of your default file system program.
# Available Nodes
<details>
<summary><h2>Geometry nodes</h2></summary>
<hr>
<h4><a href="/documentation/Nodes/Geometry/Mesh.md">Mesh node</a></h4>
<hr>
</details>
<details>
<summary><h2>Maths nodes</h2></summary>
<hr>
<details>
<summary><h3>Vector</h3></summary>
<h4><a href="/documentation/Nodes/Maths/Vector/VectorTransform.md">Vector Transform node</a></h4>
</details>
<details>
<summary><h3>Wave</h3></summary>
<h4><a href="/documentation/Nodes/Maths/Wave/NoiseSineWave.md">Noise Sine Wave node</a></h4>
<h4><a href="/documentation/Nodes/Maths/Wave/SawtoothWave.md">Sawtooth Wave node</a></h4>
<h4><a href="/documentation/Nodes/Maths/Wave/SquareWave.md">Square Wave node</a></h4>
<h4><a href="/documentation/Nodes/Maths/Wave/TriangleWave.md">Triangle Wave node</a></h4>
</details>
<hr>
</details>
<details>
<summary><h2>Procedural nodes</h2></summary>
<hr>
<h4><a href="/documentation/Nodes/Procedural/CheckerBoard.md">Checker Board node</a></h4>
<details>
<summary><h3>Noise</h3></summary>
<h4><a href="/documentation/Nodes/Procedural/Noise/GradientNoise.md">Gradient Noise node</a></h4>
<h4><a href="/documentation/Nodes/Procedural/Noise/PseudoRandomNoise.md">Pseudo Random Noise node</a></h4>
<h4><a href="/documentation/Nodes/Procedural/Noise/SimpleNoise.md">Simple Noise node</a></h4>
<h4><a href="/documentation/Nodes/Procedural/Noise/Voronoi.md">Voronoi node</a></h4>
</details>
<details>
<summary><h3>Shapes</h3></summary>
<h4><a href="/documentation/Nodes/Procedural/Shapes/Ellipse.md">Ellipse node</a></h4>
<h4><a href="/documentation/Nodes/Procedural/Shapes/Polygon.md">Polygon node</a></h4>
<h4><a href="/documentation/Nodes/Procedural/Shapes/Rectangle.md">Rectangle node</a></h4>
<h4><a href="/documentation/Nodes/Procedural/Shapes/RoundedPolygon.md">Rounded Polygon node</a></h4>
<h4><a href="/documentation/Nodes/Procedural/Shapes/RoundedRectangle.md">Rounded Rectangle node</a></h4>
</details>
<hr>
</details>
<details>
<summary><h2>UV nodes</h2></summary>
<hr>
<h4><a href="/documentation/Nodes/UV/Flipbook.md">Flipbook node</a></h4>
<h4><a href="/documentation/Nodes/UV/ParallaxMapping.md">Parallax Mapping node</a></h4>
<h4><a href="/documentation/Nodes/UV/RadialShear.md">Radial Shear node</a></h4>
<h4><a href="/documentation/Nodes/UV/Rotate.md">Rotate node</a></h4>
<h4><a href="/documentation/Nodes/UV/Spherize.md">Spherize node</a></h4>
<h4><a href="/documentation/Nodes/UV/Swirl.md">Swirl node</a></h4>
<h4><a href="/documentation/Nodes/UV/TilingAndOffset.md">Tiling and Offset node</a></h4>
<h4><a href="/documentation/Nodes/UV/Twirl.md">Twirl node</a></h4>
<hr>
</details>
<h2>Artistic nodes</h2>
<h3>&emsp;Adjustment</h3>
<h4><a href="/documentation/Nodes/Artistic/Adjustment/ContrastNode.md">&emsp;&emsp;Contrast node</a></h4>
<h4><a href="/documentation/Nodes/Artistic/Adjustment/HueNode.md">&emsp;&emsp;Hue node</a></h4>
<h4><a href="/documentation/Nodes/Artistic/Adjustment/ReplaceColorNode.md">&emsp;&emsp;Replace Color node</a></h4>
<h4><a href="/documentation/Nodes/Artistic/Adjustment/SaturationNode.md">&emsp;&emsp;Saturation node</a></h4>
<h4><a href="/documentation/Nodes/Artistic/Adjustment/WhiteBalanceNode.md">&emsp;&emsp;White Balance node</a></h4>
<h3>&emsp;Mask</h3>
<h4><a href="/documentation/Nodes/Artistic/Mask/ColorMaskNode.md">&emsp;&emsp;Color Mask node</a></h4>
<h2>Geometry nodes</h2>
<h4><a href="/documentation/Nodes/Geometry/Mesh.md">&emsp;Mesh node</a></h4>
<h2>Maths nodes</h2>
<h3>&emsp;Vector</h3>
<h4><a href="/documentation/Nodes/Maths/Vector/Project.md">&emsp;&emsp;Project node</a></h4>
<h4><a href="/documentation/Nodes/Maths/Vector/ProjectOnPlane.md">&emsp;&emsp;Project On Plane node</a></h4>
<h4><a href="/documentation/Nodes/Maths/Vector/VectorTransform.md">&emsp;&emsp;Vector Transform node</a></h4>
<h3>&emsp;Wave</h3>
<h4><a href="/documentation/Nodes/Maths/Wave/NoiseSineWave.md">&emsp;&emsp;Noise Sine Wave node</a></h4>
<h4><a href="/documentation/Nodes/Maths/Wave/SawtoothWave.md">&emsp;&emsp;Sawtooth Wave node</a></h4>
<h4><a href="/documentation/Nodes/Maths/Wave/SquareWave.md">&emsp;&emsp;Square Wave node</a></h4>
<h4><a href="/documentation/Nodes/Maths/Wave/TriangleWave.md">&emsp;&emsp;Triangle Wave node</a></h4>
<h2>Procedural nodes</h2>
<h4><a href="/documentation/Nodes/Procedural/CheckerBoard.md">&emsp;Checker Board node</a></h4>
<h3>&emsp;Fractals</h3>
<h4><a href="/documentation/Nodes/Procedural/Shapes/KochFractal.md">&emsp;&emsp;Koch Fractal node</a></h4>
<h3>&emsp;Noise</h3>
<h4><a href="/documentation/Nodes/Procedural/Noise/GradientNoise.md">&emsp;&emsp;Gradient Noise node</a></h4>
<h4><a href="/documentation/Nodes/Procedural/Noise/PseudoRandomNoise.md">&emsp;&emsp;Pseudo Random Noise node</a></h4>
<h4><a href="/documentation/Nodes/Procedural/Noise/SimpleNoise.md">&emsp;&emsp;Simple Noise node</a></h4>
<h4><a href="/documentation/Nodes/Procedural/Noise/Voronoi.md">&emsp;&emsp;Voronoi node</a></h4>
<h3>&emsp;Shapes</h3>
<h4><a href="/documentation/Nodes/Procedural/Shapes/Ellipse.md">&emsp;&emsp;Ellipse node</a></h4>
<h4><a href="/documentation/Nodes/Procedural/Shapes/Polygon.md">&emsp;&emsp;Polygon node</a></h4>
<h4><a href="/documentation/Nodes/Procedural/Shapes/Rectangle.md">&emsp;&emsp;Rectangle node</a></h4>
<h4><a href="/documentation/Nodes/Procedural/Shapes/RoundedPolygon.md">&emsp;&emsp;Rounded Polygon node</a></h4>
<h4><a href="/documentation/Nodes/Procedural/Shapes/RoundedRectangle.md">&emsp;&emsp;Rounded Rectangle node</a></h4>
<h2>UV nodes</h2>
<h4><a href="/documentation/Nodes/UV/Flipbook.md">&emsp;Flipbook node</a></h4>
<h4><a href="/documentation/Nodes/UV/ParallaxMapping.md">&emsp;Parallax Mapping node</a></h4>
<h4><a href="/documentation/Nodes/UV/RadialShear.md">&emsp;Radial Shear node</a></h4>
<h4><a href="/documentation/Nodes/UV/Rotate.md">&emsp;Rotate node</a></h4>
<h4><a href="/documentation/Nodes/UV/Spherize.md">&emsp;Spherize node</a></h4>
<h4><a href="/documentation/Nodes/UV/Swirl.md">&emsp;Swirl node</a></h4>
<h4><a href="/documentation/Nodes/UV/TilingAndOffset.md">&emsp;Tiling and Offset node</a></h4>
<h4><a href="/documentation/Nodes/UV/Twirl.md">&emsp;Twirl node</a></h4>

View File

@ -0,0 +1,15 @@
# Contrast node
Adjusts the contrast of input <b><i>in</i></b> by the amount of input <b><i>contrast</i></b>. A contrast value of 1 will return the input unaltered. A contrast value of 0 will return the midpoint of the input.
<hr>
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|in|vec3|none|Input value|
|contrast|float|none|Contrast value|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|out|vec3|None|Output value|
___

View File

@ -0,0 +1,20 @@
# Hue node
Offsets the hue of input <b><i>in</i></b> by the amount of input <b><i>offset</i></b>. The unit of the offset can be set with the parameter <b><i>Range</i></b>. Offset in <b><i>Degrees</i></b> is in the range -180 to 180. In <b><i>Normalize</b></i> it is -1 to 1.
<hr>
**Controls**
|Name|Options|Description|
|---|---|---|
|Range|Degrees, Normalize|The unit used for the input offset|
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|in|vec3|none|Input value|
|offset|float|none|Amount to offset hue|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|out|vec3|None|Output value|
___

View File

@ -0,0 +1,18 @@
# Replace Color node
Replaces values in input <b><i>in</i></b> equal to input <b><i>from</i></b> to the value of input <b><i>to</i></b>. Input <b><i>range</i></b> can be used to define a wider range of values around input <b><i>from</i></b> to replace. Input <b><i>fuzziness</i></b> can be used to soften the edges around the selection similar to anti-aliasing.
<hr>
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|in|vec3|none|Input value|
|from|vec3|none|Color to replace|
|to|vec3|none|Color to replace with|
|range|float|none|Replace colors within this range from input <b><i>from</i></b>|
|fuzziness|float|none|Soften edges around selection|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|out|vec3|None|Output value|
___

View File

@ -0,0 +1,15 @@
# Saturation node
Adjusts the saturation of input <b><i>in</i></b> by the amount of input <b><i>saturation</i></b>. A Saturation value of 1 will return the input unaltered. A Saturation value of 0 will return the input completely desaturated.
<hr>
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|in|vec3|none|Input value|
|saturation|float|none|Saturation value|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|out|vec3|None|Output value|
___

View File

@ -0,0 +1,16 @@
# White Balance node
Adjusts the temperature and tint of input <b><i>in</i></b> by the amount of inputs <b><i>temperature</i></b> and <b><i>tint</i></b> respectively. Temperature has the effect of shifting the values towards yellow or blue. Tint has the effect of shifting towards pink or green.
<hr>
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|in|vec3|none|Input value|
|temperature|float|none|Temperature offset value|
|tint|float|none|Tint offset value|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|out|vec3|None|Output value|
___

View File

@ -0,0 +1,17 @@
# Color Mask node
Creates a mask from values in input <b><i>in</i></b> equal to input <b><i>mask color</i></b>. Input <b><i>range</i></b> can be used to define a wider range of values around input <b><i>mask color</i></b> to create the mask. Colors within this range will return 1, otherwise the node will return 0. Input <b><i>fuzziness</i></b> can be used to soften the edges around the selection similar to anti-aliasing.
<hr>
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|in|vec3|none|Input value|
|color mask|vec3|none|Color to use for mask|
|range|float|none|Select colors within this range from input <b><i>mask color</i></b>|
|fuzziness|float|none|Feather edges around selection. Higher values result in a softer selection mask.|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|out|vec3|None|Output mask value|
___

View File

@ -0,0 +1,20 @@
# Project node
Projects <i><b>vector A</b></i> onto <i><b>vector B</b></i>.
<hr>
**Controls**
|Options|Description|
|---|---|
|Vector2, Vector3|Vector type to use for calculation|
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|vector A|Dynamic vector|none|Vector to project|
|vector B|Dynamic vector|none|Vector on which vector A will be projected|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|vector|vector3|None|Output vector|
___

View File

@ -0,0 +1,20 @@
# Project On Plane node
Projects a vector onto a plane defined by a normal orthogonal to the plane.
<hr>
**Controls**
|Options|Description|
|---|---|
|Vector2, Vector3|Vector type to use for calculation|
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|vector|Dynamic vector|none|Vector to project|
|plane normal|Dynamic vector|none|Normal orthogonal of the plane|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|vector|vector3|None|Output vector|
___

View File

@ -2,6 +2,11 @@
Returns the sine of the value of input <b><i>in</i></b>. For variance, psuedo-random noise is added to the amplitude of the sine wave, within a range determined by input <b><i>min max</i></b>.
<hr>
**Controls**
|Options|Description|
|---|---|
|Vector1, Vector2, Vector3, Vector4|Vector type to use for calculation|
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|

View File

@ -2,6 +2,11 @@
Returns a sawtooth wave from the value of input <b><i>in</i></b>. Resulting output values will be between -1 and 1.
<hr>
**Controls**
|Options|Description|
|---|---|
|Vector1, Vector2, Vector3, Vector4|Vector type to use for calculation|
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|

View File

@ -2,6 +2,11 @@
Returns a square wave from the value of input <b><i>in</i></b>. Resulting output values will be between -1 and 1.
<hr>
**Controls**
|Options|Description|
|---|---|
|Vector1, Vector2, Vector3, Vector4|Vector type to use for calculation|
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|

View File

@ -2,6 +2,11 @@
Returns a triangle wave from the value of input <b><i>in</i></b>. Resulting output values will be between -1 and 1.
<hr>
**Controls**
|Options|Description|
|---|---|
|Vector1, Vector2, Vector3, Vector4|Vector type to use for calculation|
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|

View File

@ -0,0 +1,19 @@
# Koch Fractal node
Generates an koch curve similar to ice fractal shape based on input UV at the size specified by inputs <b><i>width</i></b> and <b><i>height</i></b>. The generated shape can be offset or tiled by connecting a <b><i>[TilingAndOffset](/documentation/Nodes/UV/TilingAndOffset.md)</i></b> node. Note that in order to preserve the ability to offset the shape within the UV space the shape will not automatically repeat if tiled. To achieve a repeating effect first connect your <b><i>TilingAndOffset</i></b> output through a <b><i>Fract</i></b> node.
<hr>
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|uv|vec2|UV|Input UV value|
|thickness|float|none|Shape outline thickness|
|iterations|int|none|Number of steps to repeat the fractal shape|
|width|float|none|Fractal width|
|height|float|none|Fractal height|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|out|float|None|Output fractal value|
|uv|vec2|None|Output UV value|
___