mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-01-07 01:43:35 +08:00
Hue node added
This commit is contained in:
parent
64df7fb100
commit
eaa074f68f
73
addons/ShaderLib/Artistic/Adjustment/HueNode.gd
Normal file
73
addons/ShaderLib/Artistic/Adjustment/HueNode.gd
Normal file
@ -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]
|
27
addons/ShaderLib/Artistic/Adjustment/HueNode.gdshaderinc
Normal file
27
addons/ShaderLib/Artistic/Adjustment/HueNode.gdshaderinc
Normal 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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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
|
||||
<h2>Artistic nodes</h2>
|
||||
|
||||
<h3> Adjustment</h3>
|
||||
|
||||
<h4><a href="/documentation/Nodes/Artistic/Adjustment/HueNode.md">  Hue node</a></h4>
|
||||
|
||||
<h2>Geometry nodes</h2>
|
||||
|
||||
<h4><a href="/documentation/Nodes/Geometry/Mesh.md"> Mesh node</a></h4>
|
||||
|
20
documentation/Nodes/Artistic/Adjustment/HueNode.md
Normal file
20
documentation/Nodes/Artistic/Adjustment/HueNode.md
Normal 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|
|
||||
___
|
Loading…
x
Reference in New Issue
Block a user