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