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

Color mask node added

This commit is contained in:
Digvijaysinh Gohil 2024-03-12 17:47:32 +05:30
parent 506b4c9563
commit 8b3f23fbea
4 changed files with 94 additions and 0 deletions

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:
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]

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

@ -15,6 +15,10 @@ Delete the contents of **_addons/ShaderLib_** folder from your project. Make sur
<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>

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|
___