{"id":6,"date":"2016-04-16T13:01:16","date_gmt":"2016-04-16T20:01:16","guid":{"rendered":"http:\/\/artifisizzler.com\/?p=6"},"modified":"2019-07-18T00:59:06","modified_gmt":"2019-07-18T00:59:06","slug":"procedural-wood-shaders-in-cycles-the-beginning","status":"publish","type":"post","link":"http:\/\/www.decscroll.com\/blog\/2016\/04\/16\/procedural-wood-shaders-in-cycles-the-beginning\/","title":{"rendered":"Procedural Wood Shaders in Cycles, the Beginning"},"content":{"rendered":"<p>I&#8217;ve been interested in procedural wood shaders for years, ever since I first saw how some simple ideas could make pretty convincing wood. A little while ago I decided to see if I could make it work with Blender and Cycles, and I&#8217;ve gotten decent results. I&#8217;ve posted several examples on BlendSwap, and I thought it might be fun to do a couple of tutorials on how I make them. I hope you can improve on my ideas and make some awesome shaders.<\/p>\n<p>So with that, let&#8217;s jump in! I hope you won&#8217;t get board. Get it? I figured starting with a joke or two wooden hurt!<\/p>\n<p>Ok, no more terrible jokes, I promise.<\/p>\n<p>Start with a cube in Blender, and stretch it along the Y-axis so it sort of looks like a plank of wood, say about a scale of 5 (10 units). Add a Cycles material to the cube. Next, create a &#8220;Sun&#8221; lamp and transform it to &lt; 0, 0, 10 &gt;, with an X Rotation of 45 degrees, and a Y rotation of 30 degrees. Rotate the view so you have a nice view of the end, so that it looks something like this, in Rendered mode:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-710 size-full\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-001.png?resize=551%2C459\" alt=\"\" width=\"551\" height=\"459\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-001.png?w=551 551w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-001.png?resize=300%2C250 300w\" sizes=\"auto, (max-width: 551px) 100vw, 551px\" \/><\/p>\n<p>That will give you a nice view of the end grain, and you&#8217;ll also be able to see the grain along the sides.<\/p>\n<p>Now, make sure the Cube is selected, and open the Node editor. The Material we applied earlier is just two nodes, the Diffuse BSDF, and the Material Output. We need to add a few nodes to give us some controls before we start seeing some results, so bear with me.<\/p>\n<p>First, add a Texture Coordinate node (Add-&gt;Input-&gt;Texture Coordinate). Next, add a Mapping node (Add-&gt;Vector-&gt;Mapping) next to it. Connect the &#8216;Object&#8217; output of the Texture Coordinate node to the &#8216;Vector&#8217; input of the Mapping node. Then connect the &#8216;Vector&#8217; output of the Mapping node to the &#8216;Color&#8217; input of the Diffuse node. It should look like this:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-712 size-full\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-002.png?resize=640%2C229\" alt=\"\" width=\"640\" height=\"229\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-002.png?w=934 934w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-002.png?resize=300%2C107 300w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-002.png?resize=768%2C275 768w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-002.png?resize=850%2C304 850w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>Your wood plank look now looks like this:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-711 size-full\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-003.png?resize=547%2C463\" alt=\"\" width=\"547\" height=\"463\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-003.png?w=547 547w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-003.png?resize=300%2C254 300w\" sizes=\"auto, (max-width: 547px) 100vw, 547px\" \/><\/p>\n<p>Augh, that&#8217;s not even close to wood! Don&#8217;t worry&#8230;this is just the setup; we&#8217;ll wrangle it into shape in a moment.<\/p>\n<p>Why did we do this anyway? Ok, the &#8216;Object&#8217; output of the Texture Coordinate node tells Cycles to make the coordinates depend on the entire object. Basically this will make our wood appear solid, as if the object is carved out of wood. Some of the other Texture Coordinate types make the coordinates relative to the outside surfaces only, as if your object was wrapped in a texture. We certainly don&#8217;t want our wood to look like it&#8217;s just wrapped.<\/p>\n<p>Secondly, the Mapping node will allow us to translate and rotate our wood so that we can get different variations.<\/p>\n<p>Now\u00a0move the Texture Coordinate and Mapping node far to the left so we have a lot of space to work with between it and the Diffuse BSDF node.<\/p>\n<p>Let&#8217;s stop and think about wood for a moment: Trees start out as little sticks, and get thicker and thicker as they grow. The growth pattern is called &#8216;rings&#8217; but if you had a perfectly straight tree, it&#8217;d really be cylinders inside each other. So that&#8217;s what we want, cylinders. How do we make a cylinder? Well, it&#8217;s just a circle with height. And what&#8217;s the equation of a circle? Criminy, no one told me this would involve math!! It&#8217;s not too hard; it&#8217;s just <img decoding=\"async\" src=\"http:\/\/s0.wp.com\/latex.php?latex=x%5E2+%2B+y%5E2&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"x^2 + y^2\" class=\"latex\" \/>&#8230;but we don&#8217;t have any Xs or Ys yet.<\/p>\n<p>Thankfully there are nodes to help out! Add a &#8216;Separate XYZ&#8217; node, connected to the output of the Mapping node, like so (Add-&gt;Converter-&gt;Separate XYZ):<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-713 size-full\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-004.png?resize=640%2C280\" alt=\"\" width=\"640\" height=\"280\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-004.png?w=728 728w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-004.png?resize=300%2C131 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>Then, add two Math nodes (Add-&gt;Converter-&gt;Math) and set them to &#8216;Multiply.&#8217; Connect the &#8216;X&#8217; output to both inputs of one Math node, and the &#8216;Z&#8217; output to both inputs of the other Math node.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-714 aligncenter\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-005.png?resize=640%2C306\" alt=\"\" width=\"640\" height=\"306\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-005.png?w=694 694w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-005.png?resize=300%2C144 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>This gives us <img decoding=\"async\" src=\"http:\/\/s0.wp.com\/latex.php?latex=X%5E2&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"X^2\" class=\"latex\" \/> and <img decoding=\"async\" src=\"http:\/\/s0.wp.com\/latex.php?latex=Z%5E2&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"Z^2\" class=\"latex\" \/>. Hold on, I thought we wanted <img decoding=\"async\" src=\"http:\/\/s0.wp.com\/latex.php?latex=x%5E2&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"x^2\" class=\"latex\" \/> and <img decoding=\"async\" src=\"http:\/\/s0.wp.com\/latex.php?latex=y%5E2&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"y^2\" class=\"latex\" \/>? Well, if you look at the axis indicator, you&#8217;ll see that we&#8217;re working in the X-Z plane for the end of the wood grain, so our circle will be <img decoding=\"async\" src=\"http:\/\/s0.wp.com\/latex.php?latex=x%5E2+%2B+z%5E2&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"x^2 + z^2\" class=\"latex\" \/>. The Y-axis is actually along the length of the plank, so that&#8217;s the cylinder height.<\/p>\n<p>The astute reader will note that our equation involves addition, and we don&#8217;t have any addition nodes. Let&#8217;s add one. Add another Math node and set it to Add. Connect the outputs of the two Multiply nodes, and then connect the &#8216;Value&#8217; output of the Add node to the &#8216;Color&#8217; input of the Diffuse BSDF node:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-715 aligncenter\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-006.png?resize=640%2C201\" alt=\"\" width=\"640\" height=\"201\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-006.png?resize=1024%2C322 1024w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-006.png?resize=300%2C94 300w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-006.png?resize=768%2C241 768w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-006.png?resize=850%2C267 850w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-006.png?w=1044 1044w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>Et voila! <img decoding=\"async\" src=\"http:\/\/s0.wp.com\/latex.php?latex=X%5E2+%2B+Z%5E2&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"X^2 + Z^2\" class=\"latex\" \/>.\u00a0Well, what do we have here in our viewport?<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-716 aligncenter\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-007.png?resize=550%2C451\" alt=\"\" width=\"550\" height=\"451\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-007.png?w=550 550w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-007.png?resize=300%2C246 300w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/p>\n<p>Looks like a cylinder that goes through the center of our plank! Now we&#8217;re getting somewhere! What we have now is our color blending smoothly from that black center and it smoothly fades to gray (well, white, actually, but the lighting makes it look gray). Of course, it still doesn&#8217;t look like wood&#8230;we need some rings. Again, the answer is math!\u00a0If you have done some programming, you might know the answer already, because there is a very common function that allows you to repeat a number range over and over. If you said &#8216;modulus&#8217; then you may stay after class and clean the erasers! So add one more Math node, set the operation to Modulo, set the value to 1.0, and connect it between the Add and the Diffuse BSFD nodes:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-717 aligncenter\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-008.png?resize=640%2C219\" alt=\"\" width=\"640\" height=\"219\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-008.png?w=971 971w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-008.png?resize=300%2C103 300w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-008.png?resize=768%2C263 768w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-008.png?resize=850%2C292 850w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>Rendering&#8230;and we have a ring!<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-718 aligncenter\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-009.png?resize=529%2C461\" alt=\"\" width=\"529\" height=\"461\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-009.png?w=529 529w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-009.png?resize=300%2C261 300w\" sizes=\"auto, (max-width: 529px) 100vw, 529px\" \/><\/p>\n<p>This works because Modulo is making the color value go from 0 to 1, then starting over at 0. One ring isn&#8217;t enough (unless you are trying to Rule Them All), so in the Mapping node, set the X rotation and Z rotation to 5, and the scale to &lt; 2, 2, 2 &gt;.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-719 aligncenter\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-010-1.png?resize=476%2C459\" alt=\"\" width=\"476\" height=\"459\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-010-1.png?w=476 476w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-010-1.png?resize=300%2C289 300w\" sizes=\"auto, (max-width: 476px) 100vw, 476px\" \/><\/p>\n<p>Say, that actually kind of looks like wood! It&#8217;s way too perfect, but in the next post, we&#8217;ll make it look even better!<\/p>\n<p>TL;DR: here&#8217;s the complete node setup:<a href=\"http:\/\/www.artifisizzler.com\/images\/basic-wood\/basic-wood-001.PNG\"><br \/>\n<\/a><\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-720\" src=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-011.png?resize=640%2C432\" alt=\"\" width=\"640\" height=\"432\" srcset=\"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-011.png?w=761 761w, https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-011.png?resize=300%2C203 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>IMPORTANT: I discovered a problem with this ring equation! Please read my post <a href=\"http:\/\/www.decscroll.com\/?p=223\">here <\/a> before continuing to <a href=\"http:\/\/www.decscroll.com\/?p=14\">Part 2<\/a>!<\/p>\n<p>Stay tuned for more! Next time we&#8217;ll add some color!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been interested in procedural wood shaders for years, ever since I first saw how some simple ideas could make pretty convincing wood. A little while ago I decided to see if I could make it work with Blender and Cycles, and I&#8217;ve gotten decent results. I&#8217;ve posted several examples on BlendSwap, and I thought&#8230;<\/p>\n","protected":false},"author":2,"featured_media":76,"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":true,"_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":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[3],"tags":[4,8,13,15,16],"class_list":["post-6","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-blender","tag-cycles","tag-shader","tag-tutorial","tag-wood"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.decscroll.com\/blog\/wp-content\/uploads\/2016\/04\/basic-wood-010-1-e1466979079262.png?fit=459%2C459","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paMavh-6","_links":{"self":[{"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/posts\/6","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=6"}],"version-history":[{"count":4,"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/posts\/6\/revisions"}],"predecessor-version":[{"id":721,"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/posts\/6\/revisions\/721"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/media\/76"}],"wp:attachment":[{"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/media?parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/categories?post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.decscroll.com\/blog\/wp-json\/wp\/v2\/tags?post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}