I’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’ve gotten decent results. I’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.

So with that, let’s jump in! I hope you won’t get board. Get it? I figured starting with a joke or two wooden hurt!

Ok, no more terrible jokes, I promise.

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 “Sun” lamp and transform it to < 0, 0, 10 >, 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:

That will give you a nice view of the end grain, and you’ll also be able to see the grain along the sides.

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.

First, add a Texture Coordinate node (Add->Input->Texture Coordinate). Next, add a Mapping node (Add->Vector->Mapping) next to it. Connect the ‘Object’ output of the Texture Coordinate node to the ‘Vector’ input of the Mapping node. Then connect the ‘Vector’ output of the Mapping node to the ‘Color’ input of the Diffuse node. It should look like this:

Your wood plank look now looks like this:

Augh, that’s not even close to wood! Don’t worry…this is just the setup; we’ll wrangle it into shape in a moment.

Why did we do this anyway? Ok, the ‘Object’ 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’t want our wood to look like it’s just wrapped.

Secondly, the Mapping node will allow us to translate and rotate our wood so that we can get different variations.

Now move 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.

Let’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 ‘rings’ but if you had a perfectly straight tree, it’d really be cylinders inside each other. So that’s what we want, cylinders. How do we make a cylinder? Well, it’s just a circle with height. And what’s the equation of a circle? Criminy, no one told me this would involve math!! It’s not too hard; it’s just x^2 + y^2…but we don’t have any Xs or Ys yet.

Thankfully there are nodes to help out! Add a ‘Separate XYZ’ node, connected to the output of the Mapping node, like so (Add->Converter->Separate XYZ):

Then, add two Math nodes (Add->Converter->Math) and set them to ‘Multiply.’ Connect the ‘X’ output to both inputs of one Math node, and the ‘Z’ output to both inputs of the other Math node.

This gives us X^2 and Z^2. Hold on, I thought we wanted x^2 and y^2? Well, if you look at the axis indicator, you’ll see that we’re working in the X-Z plane for the end of the wood grain, so our circle will be x^2 + z^2. The Y-axis is actually along the length of the plank, so that’s the cylinder height.

The astute reader will note that our equation involves addition, and we don’t have any addition nodes. Let’s add one. Add another Math node and set it to Add. Connect the outputs of the two Multiply nodes, and then connect the ‘Value’ output of the Add node to the ‘Color’ input of the Diffuse BSDF node:

basic-wood-006

Et voila! X^2 + Z^2. Well, what do we have here in our viewport?

Looks like a cylinder that goes through the center of our plank! Now we’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’t look like wood…we need some rings. Again, the answer is math! If 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 ‘modulus’ 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:

 

basic-wood-008

Rendering…and we have a ring!

This works because Modulo is making the color value go from 0 to 1, then starting over at 0. One ring isn’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 < 2, 2, 2 >.

Say, that actually kind of looks like wood! It’s way too perfect, but in the next post, we’ll make it look even better!

TL;DR: here’s the complete node setup:

IMPORTANT: I discovered a problem with this ring equation! Please read my post here before continuing to Part 2!

Stay tuned for more! Next time we’ll add some color!