Skip to content

Commit

Permalink
Merge pull request #653 from williamchange/new-blend-modes
Browse files Browse the repository at this point in the history
Add Hue, Saturation, Color and Value blend modes
  • Loading branch information
RodZill4 authored Apr 30, 2024
2 parents f292863 + 277a5e4 commit 4d956c2
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 2 deletions.
81 changes: 80 additions & 1 deletion addons/material_maker/nodes/blend2.mmg
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,73 @@
"",
"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;",
"}",
"",
"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": [
"blend"
"blend",
"adjust_hsv"
],
"inputs": [
{
Expand Down Expand Up @@ -187,6 +250,22 @@
{
"name": "Exclusion",
"value": "exclusion"
},
{
"name": "Hue",
"value": "hue"
},
{
"name": "Saturation",
"value": "saturation"
},
{
"name": "Color",
"value": "color"
},
{
"name": "Value",
"value": "value"
}
]
},
Expand Down
Binary file added material_maker/doc/images/blend_color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material_maker/doc/images/blend_hue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material_maker/doc/images/blend_saturation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material_maker/doc/images/blend_value.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 18 additions & 1 deletion material_maker/doc/node_filter_blend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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*,
*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
when the corresponding input is not connected. When connected, the opacity channel is
Expand Down Expand Up @@ -83,6 +84,14 @@ Blending modes

.. |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     |
+=======================+===============================+===============================================================================================================================+
Expand Down Expand Up @@ -124,6 +133,14 @@ Blending modes
+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------------------------------+
| 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
+++++
Expand Down

0 comments on commit 4d956c2

Please sign in to comment.