mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-01-07 01:43:35 +08:00
Replace color node added
This commit is contained in:
parent
151e40d0fb
commit
6b62f15a7d
@ -1,8 +1,8 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeAdjustmentContrastNode extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeAdjustmentContrast extends VisualShaderNodeCustom
|
||||
|
||||
func _get_name() -> String:
|
||||
return "ContrastNode"
|
||||
return "Contrast"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Artistic/Adjustment"
|
||||
@ -47,7 +47,7 @@ func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
var code: String = preload("ContrastNode.gdshaderinc").code
|
||||
var code: String = preload("Contrast.gdshaderinc").code
|
||||
return code
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
@ -1,5 +1,4 @@
|
||||
vec3 contrast(vec3 input, float contrast)
|
||||
{
|
||||
vec3 contrast(vec3 input, float contrast){
|
||||
float midpoint = pow(0.5, 2.2);
|
||||
return (input - midpoint) * contrast + midpoint;
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeAdjustmentHueNode extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeAdjustmentHue extends VisualShaderNodeCustom
|
||||
|
||||
func _get_name() -> String:
|
||||
return "HueNode"
|
||||
return "Hue"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Artistic/Adjustment"
|
||||
@ -59,7 +59,7 @@ 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
|
||||
var code: String = preload("Hue.gdshaderinc").code
|
||||
return code
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
76
addons/ShaderLib/Artistic/Adjustment/ReplaceColor.gd
Normal file
76
addons/ShaderLib/Artistic/Adjustment/ReplaceColor.gd
Normal file
@ -0,0 +1,76 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeAdjustmentReplaceColor extends VisualShaderNodeCustom
|
||||
|
||||
func _get_name() -> String:
|
||||
return "ReplaceColor"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Artistic/Adjustment"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Replaces values in input \"in\" equal to input \"from\" to the value of input \"to\"."
|
||||
|
||||
func _get_return_icon_type() -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 5
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
match port:
|
||||
0:
|
||||
return "in"
|
||||
1:
|
||||
return "from"
|
||||
2:
|
||||
return "to"
|
||||
3:
|
||||
return "range"
|
||||
_:
|
||||
return "fuzziness"
|
||||
|
||||
func _get_input_port_type(port: int) -> PortType:
|
||||
match port:
|
||||
0, 1, 2:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
_:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_input_port_default_value(port: int) -> Variant:
|
||||
match port:
|
||||
3, 4:
|
||||
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_global_code(mode: Shader.Mode) -> String:
|
||||
var code: String = preload("ReplaceColor.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(1.0)"
|
||||
var from: String = "vec3(1.0)"
|
||||
var to: String = "vec3(1.0)"
|
||||
|
||||
if input_vars[0]:
|
||||
input = input_vars[0]
|
||||
|
||||
if input_vars[1]:
|
||||
from = input_vars[1]
|
||||
|
||||
if input_vars[2]:
|
||||
to = input_vars[2]
|
||||
|
||||
var range: String = input_vars[3]
|
||||
var fuzziness: String = input_vars[4]
|
||||
|
||||
return output_vars[0] + " = replace_color(%s, %s, %s, %s, %s);" % [input, from, to, range, fuzziness]
|
@ -0,0 +1,4 @@
|
||||
vec3 replace_color(vec3 input, vec3 from, vec3 to, float range, float fuzziness){
|
||||
float dist = distance(from, input);
|
||||
return mix(to, input, clamp((dist - range) / max(fuzziness, 1.0e-5), 0.0, 1.0));
|
||||
}
|
@ -9,8 +9,9 @@ Delete the contents of **_addons/ShaderLib_** folder from your project. Make sur
|
||||
|
||||
<h3> Adjustment</h3>
|
||||
|
||||
<h4><a href="/documentation/Nodes/Artistic/Adjustment/HueNode.md">  Hue node</a></h4>
|
||||
<h4><a href="/documentation/Nodes/Artistic/Adjustment/ContrastNode.md">  Contrast node</a></h4>
|
||||
<h4><a href="/documentation/Nodes/Artistic/Adjustment/HueNode.md">  Hue node</a></h4>
|
||||
<h4><a href="/documentation/Nodes/Artistic/Adjustment/ReplaceColorNode.md">  Replace Color node</a></h4>
|
||||
|
||||
<h2>Geometry nodes</h2>
|
||||
|
||||
|
18
documentation/Nodes/Artistic/Adjustment/ReplaceColorNode.md
Normal file
18
documentation/Nodes/Artistic/Adjustment/ReplaceColorNode.md
Normal file
@ -0,0 +1,18 @@
|
||||
# Replace Color node
|
||||
Replaces values in input <b><i>in</i></b> equal to input <b><i>from</i></b> to the value of input <b><i>to</i></b>. Input <b><i>range</i></b> can be used to define a wider range of values around input <b><i>from</i></b> to replace. 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|
|
||||
|from|vec3|none|Color to replace|
|
||||
|to|vec3|none|Color to replace with|
|
||||
|range|float|none|Replace colors within this range from input <b><i>from</i></b>|
|
||||
|fuzziness|float|none|Soften edges around selection|
|
||||
|
||||
**Outputs**
|
||||
|Name|Type|Binding|Description|
|
||||
|---|---|---|---|
|
||||
|out|vec3|None|Output value|
|
||||
___
|
Loading…
x
Reference in New Issue
Block a user