diff --git a/addons/ShaderLib/Artistic/Adjustment/HueNode.gd b/addons/ShaderLib/Artistic/Adjustment/HueNode.gd new file mode 100644 index 0000000..bbac993 --- /dev/null +++ b/addons/ShaderLib/Artistic/Adjustment/HueNode.gd @@ -0,0 +1,73 @@ +@tool +class_name VisualShaderNodeAdjustmentHueNode extends VisualShaderNodeCustom + +func _get_name() -> String: + return "HueNode" + +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 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) -> 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("HueNode.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] diff --git a/addons/ShaderLib/Artistic/Adjustment/HueNode.gdshaderinc b/addons/ShaderLib/Artistic/Adjustment/HueNode.gdshaderinc new file mode 100644 index 0000000..156d669 --- /dev/null +++ b/addons/ShaderLib/Artistic/Adjustment/HueNode.gdshaderinc @@ -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; +} \ No newline at end of file diff --git a/addons/ShaderLib/Procedural/Shapes/KochFractal.gdshaderinc b/addons/ShaderLib/Procedural/Shapes/KochFractal.gdshaderinc index a5ad2a7..b04485f 100644 --- a/addons/ShaderLib/Procedural/Shapes/KochFractal.gdshaderinc +++ b/addons/ShaderLib/Procedural/Shapes/KochFractal.gdshaderinc @@ -31,6 +31,6 @@ float koch_fractal(vec2 uv, float outline, int iteration, float shape_width, flo dist = length(center - vec2(clamp(center.x, -1.0, 1.0), 0)); dist += step(outline / 100.0, dist / scale); - koch_uv = center; + koch_uv = abs(center); return 1.0 - dist; } \ No newline at end of file diff --git a/documentation/Documentation.md b/documentation/Documentation.md index b147533..f61b3db 100644 --- a/documentation/Documentation.md +++ b/documentation/Documentation.md @@ -5,6 +5,12 @@ 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 +

Artistic nodes

+ +

 Adjustment

+ +

  Hue node

+

Geometry nodes

 Mesh node

diff --git a/documentation/Nodes/Artistic/Adjustment/HueNode.md b/documentation/Nodes/Artistic/Adjustment/HueNode.md new file mode 100644 index 0000000..12df42b --- /dev/null +++ b/documentation/Nodes/Artistic/Adjustment/HueNode.md @@ -0,0 +1,20 @@ +# Hue node +Offsets the hue of input in by the amount of input offset. The unit of the offset can be set with the parameter Range. Offset in Degrees is in the range -180 to 180. In Normalize it is -1 to 1. +
+ +**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| +___ \ No newline at end of file