Skip to content

Commit

Permalink
Add Hue, Saturation, Color and Value blend modes
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchange committed Dec 18, 2023
1 parent 13255b7 commit b343122
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 2 deletions.
83 changes: 81 additions & 2 deletions addons/material_maker/nodes/blend2.mmg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"y": 0
},
"parameters": {
"amount1": 0.5,
"amount1": 1,
"blend_type1": 0
},
"seed_int": 0,
Expand Down 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.
16 changes: 16 additions & 0 deletions material_maker/doc/node_filter_blend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,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 +132,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 bottom layer and combines them with the saturation and value of the top layer  |
+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------------------------------+
| Saturation | |blend_saturation|  | This blend mode takes the saturation of the bottom layer and combines them with the hue and value of the top layer  |
+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------------------------------+
| Color | |blend_color|  | This blend mode takes the hue and saturation of the bottom layer and combines them with the value of the top layer  |
+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------------------------------+
| Value | |blend_value|  | This blend mode takes the value of the bottom layer and combines them with the hue and saturation of the top layer  |
+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------------------------------+

Notes
+++++
Expand Down

0 comments on commit b343122

Please sign in to comment.