{"id":679,"date":"2019-05-27T05:10:17","date_gmt":"2019-05-27T05:10:17","guid":{"rendered":"http:\/\/www.decscroll.com\/blog\/?p=679"},"modified":"2019-05-27T05:15:14","modified_gmt":"2019-05-27T05:15:14","slug":"mixing-things-up","status":"publish","type":"post","link":"http:\/\/www.decscroll.com\/blog\/2019\/05\/27\/mixing-things-up\/","title":{"rendered":"Mixing things up"},"content":{"rendered":"\n<p>When I first started using Blender procedural materials, I wondered how to get more than one material onto an object.  In other systems I&#8217;d used, there was the idea of a &#8220;material map,&#8221; which was a grayscale image that defined where to put different colors or materials.  For example, an image like this:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mat_map2.png?resize=252%2C251\" alt=\"\" class=\"wp-image-682\" width=\"252\" height=\"251\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mat_map2.png?w=512 512w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mat_map2.png?resize=150%2C150 150w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mat_map2.png?resize=300%2C300 300w\" sizes=\"auto, (max-width: 252px) 100vw, 252px\" \/><\/figure><\/div>\n\n\n\n<p>&#8230;could be applied to a shape with different materials assigned to each gray value, resulting in something neat like this:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"616\" height=\"559\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mat_map_ex-1.png?resize=616%2C559\" alt=\"\" class=\"wp-image-683\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mat_map_ex-1.png?w=616 616w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mat_map_ex-1.png?resize=300%2C272 300w\" sizes=\"auto, (max-width: 616px) 100vw, 616px\" \/><\/figure><\/div>\n\n\n\n<p>However, to my chagrin, Blender doesn&#8217;t seem to have anything like this, at least not an obvious node type.  Well, good news, and SPOILER ALERT: I created this image using Blender and the above map.  But how?<\/p>\n\n\n\n<p>Many nodes have a &#8216;Fac&#8217; value, which stands for &#8216;Factor.&#8217;  It&#8217;s a value from 0 to 1 that allows you to control the output of the node.  For example, the MixRGB node lets you mix colors:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix.png?resize=549%2C509\" alt=\"\" class=\"wp-image-684\" width=\"549\" height=\"509\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix.png?resize=300%2C279 300w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix.png?resize=768%2C714 768w\" sizes=\"auto, (max-width: 549px) 100vw, 549px\" \/><\/figure><\/div>\n\n\n\n<p>&#8230;where a Fac of 0.5 is exactly a half-and-half mix of the two colors. A smaller value (like 0.25) mixes more of the first color,<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix25.png?resize=551%2C660\" alt=\"\" class=\"wp-image-685\" width=\"551\" height=\"660\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix25.png?w=644 644w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix25.png?resize=251%2C300 251w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix25.png?resize=300%2C359 300w\" sizes=\"auto, (max-width: 551px) 100vw, 551px\" \/><\/figure><\/div>\n\n\n\n<p>&#8230;and of course a higher value mixes more of the second color:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix75.png?resize=551%2C768\" alt=\"\" class=\"wp-image-686\" width=\"551\" height=\"768\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix75.png?resize=215%2C300 215w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix75.png?resize=300%2C419 300w\" sizes=\"auto, (max-width: 551px) 100vw, 551px\" \/><\/figure><\/div>\n\n\n\n<p>This is pretty basic, of course.  The part where it becomes powerful is that you can put any sort of value from 0 to 1 into that input.  Any black and white image will send through a value from 0 to 1, where 0 is black and 1 is white.  So if we put a black-and-white checkerboard into that Fac, we actually get a red and blue checkerboard:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"560\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-check.png?resize=640%2C560\" alt=\"\" class=\"wp-image-687\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-check.png?w=939 939w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-check.png?resize=300%2C262 300w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-check.png?resize=768%2C671 768w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-check.png?resize=850%2C743 850w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure><\/div>\n\n\n\n<p>This is because the white squares are actually a value of &lt;1, 1, 1&gt; and the black squares are &lt;0, 0, 0&gt;, which is just like setting the MixRGB Fac to 1 or 0, and therefore full blue or full red.  If you don&#8217;t use white and black you can get also get any mix of the two colors, like if we use the .25 and .75 from above:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"643\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-check2.png?resize=640%2C643\" alt=\"\" class=\"wp-image-688\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-check2.png?w=830 830w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-check2.png?resize=150%2C150 150w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-check2.png?resize=300%2C301 300w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-check2.png?resize=768%2C772 768w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure><\/div>\n\n\n\n<p>You can probably see where we&#8217;re going with this.  I did say above that you can use<em> any<\/em> black-and-white or grayscale image as the input.  If we swap in the image from the beginning of the post, we get this:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"775\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map.png?resize=640%2C775\" alt=\"\" class=\"wp-image-689\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map.png?w=726 726w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map.png?resize=248%2C300 248w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map.png?resize=300%2C363 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure><\/div>\n\n\n\n<p>Cool, it does exactly what we&#8217;d expect.  The black parts are completely red, the white parts are completely blue, and the shades of gray are different shades of purple.  <\/p>\n\n\n\n<p>So what if we wanted that dot in the middle to be yellow?  We only have two colors to work with.  Hmmm&#8230;<\/p>\n\n\n\n<p>Well, since this post is about Mixing, we can add another Mix node with yellow, but then that&#8217;s not what we want.  We need to figure out what Fac should be:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"818\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map2.png?resize=640%2C818\" alt=\"\" class=\"wp-image-692\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map2.png?w=699 699w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map2.png?resize=235%2C300 235w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map2.png?resize=300%2C383 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure><\/div>\n\n\n\n<p>Math is usually the answer.  In this case, I know that the center circle has a value of 0.5, so we could use that information.  Add a math node and set it to &#8220;Less Than&#8221; and a value of 0.5, and connect that to Fac.   &#8220;Less Than&#8221; returns either 0 or 1, with 0 = Greater Than, and 1 = Less Than.  If the value is greater than 0.5, we&#8217;ll get 0, which uses the top Mix node color.  Since we&#8217;re piping the red\/blue mix into that color, we should see the red\/blue mix for everything with a lightness greater than 0.5.  Let&#8217;s see:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"630\" height=\"904\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map3.png?resize=630%2C904\" alt=\"\" class=\"wp-image-693\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map3.png?w=630 630w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map3.png?resize=209%2C300 209w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map3.png?resize=300%2C430 300w\" sizes=\"auto, (max-width: 630px) 100vw, 630px\" \/><\/figure><\/div>\n\n\n\n<p>Nice, the center dot is now yellow!  However, the edges of the cube are also yellow, which we didn&#8217;t want.  The edges were black, and black is less than 0.5 so it came out yellow.  What we <em>really<\/em> want, then, is values that are less than 0.5, and greater than 0.  <\/p>\n\n\n\n<p>&#8220;Greater Than&#8221; works the same way as &#8220;Less Than,&#8221; returning a value of 0 or 1 for True or False.  To combine these we can simply multiply them.  If both are True, that is 1 x 1 = 1,  and any other combination of True and False gives 0.  Therefore if it&#8217;s Greater Than 0.0 <em>and<\/em> Less Than 0.5, we&#8217;ll always get a Fac value of 1, so it will use the bottom color, which is the yellow we want.  And here it is:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"586\" height=\"907\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map4.png?resize=586%2C907\" alt=\"\" class=\"wp-image-694\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map4.png?w=586 586w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map4.png?resize=194%2C300 194w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map4.png?resize=300%2C464 300w\" sizes=\"auto, (max-width: 586px) 100vw, 586px\" \/><\/figure><\/div>\n\n\n\n<p>Perfect!  You can extend this to even more complexity if you like.  For example, if we wanted to turn the inner square green, we could do change the top &#8220;Less Than&#8221; into &#8220;Less Than&#8221; 0.75, and add some more Mix and Math nodes:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"868\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map5.png?resize=640%2C868\" alt=\"\" class=\"wp-image-695\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map5.png?w=675 675w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map5.png?resize=221%2C300 221w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map5.png?resize=300%2C407 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure><\/div>\n\n\n\n<p>Can you follow that?  <\/p>\n\n\n\n<p>If the value is greater than 0 and less than .75, choose the bottom color.  The bottom color is a mix of yellow and green, and that color is determined by whether the value is less than 0.5.  Given x, where 0 &lt; x &lt; 0.75, x &lt; 0.5 becomes yellow, and x &gt;= 0.5 becomes green.  <\/p>\n\n\n\n<p>However, if the value is equal to 0, or greater than .75, choose the top color.  The top color is still a mix of red and blue, and in our particular image, the only colors outside that range are pure black and pure white.  Pure white then maps to blue, and pure black maps to red.<\/p>\n\n\n\n<p>Hope that isn&#8217;t too confusing.   It can be complicated, but if you break it down step-by-step it will make sense.  It is <em>critical<\/em> to know the color values in your image, otherwise it&#8217;ll be really difficult to know which values to put in your nodes.  Since I made that image, I purposely chose the values I wanted.<\/p>\n\n\n\n<p>And now for the grand finale&#8230;colors are great, but how about that cool glowy cube at the beginning?   Well, all you have to do is replace all those MixRGB nodes with Mix Shader nodes, and replace the colors with shaders.  Here&#8217;s the same node layout as above but using shaders:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"730\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map-final.png?resize=640%2C730\" alt=\"\" class=\"wp-image-697\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map-final.png?w=789 789w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map-final.png?resize=263%2C300 263w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map-final.png?resize=768%2C876 768w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mix-map-final.png?resize=300%2C342 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure><\/div>\n\n\n\n<p>Thanks for sticking it out to the end.  I hope you learned something, and this gave you some new ideas about how to creatively bend the nodes to your will to get cool effects.  Next time, I think I&#8217;ll use this technique to make procedural granite.  Until then, keep Blending!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I first started using Blender procedural materials, I wondered how to get more than one material onto an object. In other systems I&#8217;d used, there was the idea of a &#8220;material map,&#8221; which was a grayscale image that defined where to put different colors or materials. For example, an image like this: &#8230;could be&#8230;<\/p>\n","protected":false},"author":2,"featured_media":683,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[1],"tags":[4,8,13,15],"class_list":["post-679","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-blender","tag-cycles","tag-shader","tag-tutorial"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2019\/05\/mat_map_ex-1.png?fit=616%2C559","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paMavh-aX","_links":{"self":[{"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/posts\/679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/comments?post=679"}],"version-history":[{"count":6,"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/posts\/679\/revisions"}],"predecessor-version":[{"id":700,"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/posts\/679\/revisions\/700"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/media\/683"}],"wp:attachment":[{"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/media?parent=679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/categories?post=679"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/tags?post=679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}