Merge pull request #653 from williamchange/new-blend-modes

Add Hue, Saturation, Color and Value blend modes
This commit is contained in:
Rodz Labs 2024-04-30 20:59:45 +02:00 committed by GitHub
commit 4d956c260e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 98 additions and 2 deletions

View File

@ -61,10 +61,73 @@
"", "",
"vec3 blend_exclusion(vec2 uv, vec3 c1, vec3 c2, float opacity) {", "vec3 blend_exclusion(vec2 uv, vec3 c1, vec3 c2, float opacity) {",
"\treturn opacity*vec3(blend_exclusion_f(c1.x, c2.x), blend_exclusion_f(c1.y, c2.y), blend_exclusion_f(c1.z, c2.z)) + (1.0-opacity)*c2;", "\treturn opacity*vec3(blend_exclusion_f(c1.x, c2.x), blend_exclusion_f(c1.y, c2.y), blend_exclusion_f(c1.z, c2.z)) + (1.0-opacity)*c2;",
"}",
"",
"vec3 blend_hue(vec2 uv, vec3 c1, vec3 c2, float opacity) {",
"\tvec3 outcol = c2;",
"",
"\tvec3 hsv, hsv2, tmp;",
"\thsv2 = rgb_to_hsv(c1);",
"",
"\tif (hsv2.y != 0.0) {",
"\t\thsv = rgb_to_hsv(outcol);",
"\t\thsv.x = hsv2.x;",
"\t\ttmp = hsv_to_rgb(hsv);",
"\t\toutcol = mix(outcol, tmp, opacity);",
"\t}",
"\treturn outcol;",
"}",
"",
"vec3 blend_saturation(vec2 uv, vec3 c1, vec3 c2, float opacity) {",
"\tfloat facm = 1.0 - opacity;",
"",
"\tvec3 outcol = c2;",
"\tvec3 hsv, hsv2;",
"",
"\thsv = rgb_to_hsv(outcol);",
"",
"\tif (hsv.y != 0.0) {",
"\t\thsv2 = rgb_to_hsv(c1);",
"",
"\t\thsv.y = facm * hsv.y + opacity * hsv2.y;",
"\t\toutcol = hsv_to_rgb(hsv);",
"\t}",
"\treturn outcol;",
"}",
"",
"vec3 blend_color(vec2 uv, vec3 c1, vec3 c2, float opacity) {",
"\tfloat facm = 1.0 - opacity;",
"",
"\tvec3 outcol = c2;",
"",
"\tvec3 hsv, hsv2, tmp;",
"\thsv2 = rgb_to_hsv(c1);",
"",
"\tif (hsv2.y != 0.0) {",
"\t\thsv = rgb_to_hsv(outcol);",
"\t\thsv.x = hsv2.x;",
"\t\thsv.y = hsv2.y;",
"\t\ttmp = hsv_to_rgb(hsv);",
"",
"\t\toutcol = mix(outcol, tmp, opacity);",
"\t}",
"\treturn outcol;",
"}",
"",
"vec3 blend_value(vec2 uv, vec3 c1, vec3 c2, float opacity) {",
"\tfloat facm = 1.0 - opacity;",
"",
"\tvec3 hsv, hsv2;",
"\thsv = rgb_to_hsv(c2);",
"\thsv2 = rgb_to_hsv(c1);",
"",
"\thsv.z = facm * hsv.z + opacity * hsv2.z;",
"\treturn hsv_to_rgb(hsv);",
"}" "}"
], ],
"includes": [ "includes": [
"blend" "blend",
"adjust_hsv"
], ],
"inputs": [ "inputs": [
{ {
@ -187,6 +250,22 @@
{ {
"name": "Exclusion", "name": "Exclusion",
"value": "exclusion" "value": "exclusion"
},
{
"name": "Hue",
"value": "hue"
},
{
"name": "Saturation",
"value": "saturation"
},
{
"name": "Color",
"value": "color"
},
{
"name": "Value",
"value": "value"
} }
] ]
}, },

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@ -34,7 +34,8 @@ The **Blend** node has two or more parameters:
* The *blend mode*, that can be one of the following: *Normal*, *Dissolve*, *Multiply*, *Screen*, * The *blend mode*, that can be one of the following: *Normal*, *Dissolve*, *Multiply*, *Screen*,
*Overlay*, *Hard Light*, *Soft Light*, *Linear Light*, *Vivid Light*, *Pin Light*, *Burn*, *Dodge*, *Overlay*, *Hard Light*, *Soft Light*, *Linear Light*, *Vivid Light*, *Pin Light*, *Burn*, *Dodge*,
*Lighten*, *Darken*, *Difference*, *Additive*, *AddSub*, *Hard Mix*, *Exclusion*. *Lighten*, *Darken*, *Difference*, *Additive*, *AddSub*, *Hard Mix*, *Exclusion*, *Hue*, *Saturation*,
*Color*, *Value*.
* The *opacity* is used when mixing the result of the blend operation with the background input * The *opacity* is used when mixing the result of the blend operation with the background input
when the corresponding input is not connected. When connected, the opacity channel is when the corresponding input is not connected. When connected, the opacity channel is
@ -83,6 +84,14 @@ Blending modes
.. |blend_exclusion| image:: images/blend_exclusion.png .. |blend_exclusion| image:: images/blend_exclusion.png
.. |blend_hue| image:: images/blend_hue.png
.. |blend_saturation| image:: images/blend_saturation.png
.. |blend_color| image:: images/blend_color.png
.. |blend_value| image:: images/blend_value.png
+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------------------------------+ +-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------------------------------+
| Blend mode  | Example    | Description     | | Blend mode  | Example    | Description     |
+=======================+===============================+===============================================================================================================================+ +=======================+===============================+===============================================================================================================================+
@ -124,6 +133,14 @@ Blending modes
+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------------------------------+ +-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------------------------------+
| Exclusion | |blend_exclusion|  | This blend mode is similar to Difference, but it is less intense  | | Exclusion | |blend_exclusion|  | This blend mode is similar to Difference, but it is less intense  |
+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------------------------------+ +-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------------------------------+
| Hue | |blend_hue|  | This blend mode takes the hue of the top layer and combines them with the saturation and value of the bottom layer  |
+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------------------------------+
| Saturation | |blend_saturation|  | This blend mode takes the saturation of the top layer and combines them with the hue and value of the bottom layer  |
+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------------------------------+
| Color | |blend_color|  | This blend mode takes the hue and saturation of the top layer and combines them with the value of the bottom layer  |
+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------------------------------+
| Value | |blend_value|  | This blend mode takes the value of the top layer and combines them with the hue and saturation of the bottom layer  |
+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------------------------------+
Notes Notes
+++++ +++++