diff --git a/addons/ShaderLib/Artistic/Mask/ColorMask.gd b/addons/ShaderLib/Artistic/Mask/ColorMask.gd new file mode 100644 index 0000000..7117d2e --- /dev/null +++ b/addons/ShaderLib/Artistic/Mask/ColorMask.gd @@ -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: + 1: + return Vector3(0.0, 0.0, 0.0) + 2, 3: + 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_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] diff --git a/addons/ShaderLib/Artistic/Mask/ColorMask.gdshaderinc b/addons/ShaderLib/Artistic/Mask/ColorMask.gdshaderinc new file mode 100644 index 0000000..f304e05 --- /dev/null +++ b/addons/ShaderLib/Artistic/Mask/ColorMask.gdshaderinc @@ -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.)); +} \ No newline at end of file diff --git a/documentation/Documentation.md b/documentation/Documentation.md index c19cae4..79cdab8 100644 --- a/documentation/Documentation.md +++ b/documentation/Documentation.md @@ -15,6 +15,10 @@ Delete the contents of **_addons/ShaderLib_** folder from your project. Make sur

  Saturation node

  White Balance node

+

 Mask

+ +

  Color Mask node

+

Geometry nodes

 Mesh node

diff --git a/documentation/Nodes/Artistic/Mask/ColorMaskNode.md b/documentation/Nodes/Artistic/Mask/ColorMaskNode.md new file mode 100644 index 0000000..9a9d30f --- /dev/null +++ b/documentation/Nodes/Artistic/Mask/ColorMaskNode.md @@ -0,0 +1,17 @@ +# Color Mask node +Creates a mask from values in input in equal to input mask color. Input range can be used to define a wider range of values around input mask color to create the mask. Colors within this range will return 1, otherwise the node will return 0. Input fuzziness can be used to soften the edges around the selection similar to anti-aliasing. +
+ +**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 mask color| +|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| +___ \ No newline at end of file