…could be applied to a shape with different materials assigned to each gray value, resulting in something neat like this:

However, to my chagrin, Blender doesn’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?

Many nodes have a ‘Fac’ value, which stands for ‘Factor.’ It’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:

…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,

…and of course a higher value mixes more of the second color:

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:

This is because the white squares are actually a value of <1, 1, 1> and the black squares are <0, 0, 0>, which is just like setting the MixRGB Fac to 1 or 0, and therefore full blue or full red. If you don’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:

You can probably see where we’re going with this. I did say above that you can use* any* black-and-white or grayscale image as the input. If we swap in the image from the beginning of the post, we get this:

Cool, it does exactly what we’d expect. The black parts are completely red, the white parts are completely blue, and the shades of gray are different shades of purple.

So what if we wanted that dot in the middle to be yellow? We only have two colors to work with. Hmmm…

Well, since this post is about Mixing, we can add another Mix node with yellow, but then that’s not what we want. We need to figure out what Fac should be:

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 “Less Than” and a value of 0.5, and connect that to Fac. “Less Than” returns either 0 or 1, with 0 = Greater Than, and 1 = Less Than. If the value is greater than 0.5, we’ll get 0, which uses the top Mix node color. Since we’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’s see:

Nice, the center dot is now yellow! However, the edges of the cube are also yellow, which we didn’t want. The edges were black, and black is less than 0.5 so it came out yellow. What we *really* want, then, is values that are less than 0.5, and greater than 0.

“Greater Than” works the same way as “Less Than,” 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’s Greater Than 0.0 *and* Less Than 0.5, we’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:

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 “Less Than” into “Less Than” 0.75, and add some more Mix and Math nodes:

Can you follow that?

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 < x < 0.75, x < 0.5 becomes yellow, and x >= 0.5 becomes green.

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.

Hope that isn’t too confusing. It can be complicated, but if you break it down step-by-step it will make sense. It is *critical* to know the color values in your image, otherwise it’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.

And now for the grand finale…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’s the same node layout as above but using shaders:

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’ll use this technique to make procedural granite. Until then, keep Blending!

]]>However, I’ve hit a bit of a motivational wall, as I’m still pretty far from where I envisioned even after a long stretch of work.

I did use my tool to design the logo for this site, so there’s that.

]]>Eleven years ago, I wanted to get out of the game industry and back into software. I’d been working with Python a little at work, and decided to write a meaty personal project to get better at it. I wanted something with a graphical user interface as well, and was not interested in trying to do anything substantial with Tkinter. I started using FLTK because that’s what I was using at work.

Initially it worked great, but I ran into some limitations of FLTK that were making it hard to progress, so I did some research and decided to port the application over to WxWidgets. That seemed to solve my problems, as I found it much more feature-rich (but also a lot heavier) than FLTK. Well, of course I ended up hitting a wall with WxWidgets, so I jumped again to Qt.

Needless to say, after three different UI frameworks, and learning Python along the way, the code was pretty messy. Earlier this year I decided if was going to finish this beast, I needed to do a major refactor. Since then I’ve been reorganizing code, running it through pylint, and trying to take more advantage of Qt instead of using my own solutions. It’s been fun and I’m actually in better shape with the project than I was before the refactor.

So I said all that without even saying what the project is. One of my interests has always been calligraphy and lettering, and I wanted to see if I could make a tool to do digital calligraphy. I know you can generate curves in vector drawing tools, but I wanted to make something purpose-built for calligraphy. It’s been a great challenge, but I’m getting there. Until next time, here’s a work-in-progress screenshot:

]]>There are several ways to cut a log, but basically since I have a nice cylindrical chunk of wood I should be able to make “boards” out of it by simply moving the texture coordinates around. So, if I can get a repeated pattern across a flat plane, and move the coordinates in that pattern by random amounts, that’s a wood floor. Simple!

Well, it has eluded me for some time now. This post isn’t a detailed tutorial on creating a wood floor, but it does explain some of the process I went through to get to a shader I was happy with.

Anyway, I noticed that the Brick shader in Blender can give a nice random brick pattern with different colors in the bricks, so I thought, that’s just what I need! I can set the colors of the shader to black and white, and that will give me various shades of gray and I can use those as the offsets. Let’s see, a Brick node on a Plane:

Nailed it:

So if we just add those gray values to the mapping vector of our wood texture, we should be in business. Since those gray values are only in the range 0 to 1, we can probably multiply it by something like 10 to get a bigger range of movement for our wood. Let’s see what happens if we use the Add node to add the output of the brick node to the Vector coming out of the main Mapping node in our Red Oak shader:

Well, that didn’t work at all. It’s hard to even see, but it looks like it’s still one big piece of wood but with parts of it moved around a little.

It occurred to me that the shader we’ve been building uses the Object mapping mode, so the texture coordinates are based on the entire object as if it were solid. Since it’s not UV-mapped across the surface you can’t really warp it any way you want like you could with UVs.

Perhaps I needed a different mode. In Generated mode, the coordinates are mapped from 0 to 1 across the surface of an object, and you can move them around just like UV coordinates, so in theory, that should give me more flexibility.

Initial results are pretty similar to before. I think what is needed is to reset the coordinates to <0, 0, 0> for every brick, and THEN add the gray value for an offset. I tried many things but couldn’t figure out how to get the coordinates to map the way I wanted.

When you are stuck on something Blender-related, a great place to go for help is Blender StackExchange. I found some similar questions but none quite what I wanted, so I posted my own question:

How can I create a staggered repeating procedural pattern?

This is one of the images from the answer:

That looks perfect, if I can just swap out the wood for the colored Voronoi there.

To make a long story a bit shorter, I quickly realized that the problem with this solution was that the pattern repeats perfectly, so while it sort of worked, every single plank looked exactly the same. I spent a long time struggling with how to manipulate each plank so that it looked differently, when I suddenly hit on a solution: I needed to combine BOTH my original idea and this new solution. The brick pattern gave me the different values per plank, and the Blender StackExchange solution gave me the method to reset the coordinates for each plank.

So here’s the Blender StackExchange solution with a simple Voronoi pattern:

I tweaked the settings of a Brick Texture node so that it lined up perfectly with the pattern:

Then I add the values of the Brick Texture to the Z-vector of the StackExchange node:

…and it works!

Plugging in the Red Oak texture with some tweaks, and it’s actually doing the right thing:

I did a lot more tweaking of the numbers, and added a bunch of nodes so that I could use slight shader variations based on the values of the Brick Textures, and I got a result I liked:

Awesome! I won’t post the whole network as it’s a bit messy, but the full shader is available on BlendSwap here. Feel free to download it and dissect it to see this all in detail. I’ll explain how I did the variations of the planks in another post on another day, but in the meantime, here’s a room I used the shader in:

Happy Blending!

]]>We left off in the last post with the Maple shader looking pretty good, but it’s not quite there. As I have been known to do, I went to the local lumber store and checked out some real Maple boards in addition to my online research. The ring patterns on Maple are definitely different from Oak, so we should fix that.

We haven’t really talked about the Noise that we added to the Rings, aside from the fact that it makes them not-so-perfect circles, and adds interest to the ring patterns. Let’s take a moment to discuss the parameters and how they affect our wood:

There are three parameters: Scale, Detail, and Distortion. Let’s look at these with our black-and-white ring pattern to see the effects:

The first parameter, Scale, is obviously the scale of the Noise texture. But in this case, since it’s being combined with the pattern, the scale is more like how much the rings are disturbed by the Noise. With the current setting, 0.25, the rings are still pretty round, with a slight bit of waviness. Increasing it to 1.0 makes it a lot wavier:

And at 5.0, it’s getting pretty crazy:

Let’s take it back down to 0.25 since most wood is pretty round. The second parameter is Detail. As the name implies, it’s how much detail is in the Noise texture. For our Oak wood, we have it up to 10, because we want ragged rings. If we take it down to 1.0, it becomes very smooth, so the rings are just barely not perfectly round:

If we leave the Detail at 1.0 and move the Scale back up to 5.0, you can see it’s just as wavy as before, but very smooth and not ragged like above when the Detail was set to 10.0:

So you can think of Detail as the roughness or raggedness of the ring pattern. Again, for Oak we wanted the rings to not be smooth, but Maple has smoother rings. We’ll get back to that in a moment.

Last but not least is Distortion. This is basically how much the overall pattern gets warped. With a low scale of 0.25, a Distortion of 1.0 doesn’t do much, as in the images above. If we set Scale, Detail, and Distortion all to 1, we get this:

Setting Distortion to 2.0 you can see the rings starting to warp:

…and at Distortion of 5.0, things are really wobbly:

But again, Distortion is affected by the Scale, so if we take the Scale down to 0.25, a Distortion of 5.0 isn’t all that crazy, really:

So, for Oak, we had a scale of 0.5, a Detail of 10 to make it ragged, and a Distortion of 1.0, because we wanted relatively straight, unwarped rings.

Maple, however, is not as ragged, but it’s much wavier. We already set the scale down to 0.25, but let’s also set the Detail down to 5.0, but move the Distortion up to 5.0:

And fully rendered:

That’s much more like this Maple board photo I took at the store:

I encourage you to play around with the three Noise parameters to get different effects. Remember that there are two of them, one affecting horizontal and one vertical, so try giving them different values to see what happens!

Ok, one last thing we didn’t really talk about was the Displacement/Bump mapping. Oak has the ring pattern made from the tubes running through it, so it often has noticeable lines even when sanded and finished. Maple, on the other hand, is very smooth. If you really want to, I’d add the Displacement from the output of the Rays, but multiply it by a very small value, such as .0001, to make it really subtle.

That’s it! Our Maple is now complete! I hope you found it interesting to see how much of the Oak we were able to reuse, and how some simple tweaks gives a completely unique shader. Until next time, happy Blending!

]]>Speaking of the Rays, Maple is different than Red Oak. Let’s adjust them to the look we want. This is what we had for the Oak:

First, change the value of the Multiply node to .025.

This adjusts the length of the Ray flecks along the sides of the wood:

Also, there are more Rays in Maple than Oak, so let’s kick up the Scale of the Voronoi texture, which will make them thinner and more prevalent:

Also, shift the Color Ramp right value over to the right more, say .218, which makes more Rays visible (because we’re increasing the range of Colors from the Voronoi pattern that show up):

The Rays are way too dark for Maple, though, so swing over to the Ray Color node and let’s change it to F2C8BC:

The base wood color is now looking pretty good, but the rings are way too dark, and still Oak-like:

To fix the color, find the Summerwood Mix node, and change the color to BD8E7B:

Then, in the Rings group, change the Scale of both of the Noise Textures to 0.25:

Lastly, the Rings are still too thick. In our reference they are very thin, so go to the Color Ramp in the Rings group, and slide the Left (black) slider over to .864:

That’s looking good, but we’re not done. The rings are too uniform in color for my taste. Let’s add a quick tweak to mix things up a bit. Add a MixRGB node between the ColorRamp and the Summerwood Mix node, but Connect the output of the new MixRGB node to the Fac of the Summerwood Mix node:

Then, go back to where the Power node feeds into the Modulo node and add a Voronoi node. Remember that the Modulo node is what made the Rings repeat over and over. Well, we don’t really want repetition, we just want the Voronoi pattern to follow the circular equation we wrote way back in the beginning…so pipe the output of the Power node into the Vector of the Voronoi. Also set the Scale of the Voronoi to 0.5:

If we rendered just that, you get this funky ring pattern in shades of gray.

So, we can mix that with our existing Rings to get some random color variation. Connect the output of the Voronoi node to the second input of the MixRGB we just created above:

…and now you have nice, variable ring colors:

EDIT: There’s a bit more to do to complete this, so we’ll handle that in the next post!

]]>First of all, let’s see what we’re dealing with. Remember the Red Oak end grain looks like this close up:

Maple, on the other hand, looks like THIS close up:

Notice that the rings aren’t made up of big holes, but are rather thin lines with some darkness around them. There are still rays all over it (the vertical lines) but they are a lot closer together. Also note that the entire surface is covered with tiny holes, and the overall pattern isn’t as complex, so we can remove some of the complexity of the Oak shader.

So let’s do it. Switch the connection of “Vessel Color” from the bottom connection of the Mix node to the top:

Then, connect the output of the Rings Color Ramp to the Fac of the Mix Node:

This cuts the Summerwood part out:

Our rings are still made of the holes, and if you recall from the Oak shader, we did some fancy stuff with the Grain section to get those. We won’t need that, so let’s delete it. Go to the Grain section, and delete the Divide, Mix, and Subtract nodes:

Now connect the Voronoi output directly to the Power node, and the output of the Power node to the Vessel Color input:

This is looking more like the reference already, but we have a little way to go.

Note that the light colored holes are really tightly bunched together. This is because the Color Ramp is covering the whole range of the Voronoi output, and also if you remember, the Power node controls how dense the grain is. To get something more like the Maple pattern, let’s crank that right-hand value of the Color Ramp way down, like 0.55, which has the effect of reducing the size of the holes:

Also change the gradient type of the Color Ramp to Constant, which makes theholes have hard edges instead of soft. So now it looks like this, which is much more like the reference:

The colors are terrible, however, so let’s make at least this part a bit more like Maple. Change the left color of the ramp to FFE2CA, and the right color to E6C4AC:

The colors seem subtle, but they’re enough to make the holes stand out a little:

You can go ahead and delete the entire Summerwood section now because we won’t need it:

Ok, another thing you may have noticed in the references above is that Maple has tighter rings. Go back to the main Mapping node, and change the scale to <180, 1, 180>:

Scaling it larger makes more rings fit into the same space. At this point, your wood should look like this:

We still have to work on the rays and the rings, so let’s stop here for now and next time we’ll finish it out! See you soon!

]]>If you started in the first post (Procedural Wood Shaders in Cycles, The Beginning), or read my post about a couple of other ways to make rings, you might remember that I described the rings with the equation of a circle. I stated it as , which means I left out a very important part! The *full* equation of a circle is , where r is the radius of the circle. I thought I could ignore the radius because we’re not really rendering just a circle, but rather a solid cylindrical shading where the radius goes from 0 to 1 (repeated over and over via the Modulo operator). However the fact that r is *squared* is quite important. If you recall from algebra, the equation looks like this:

I drew some blue lines on to indicate what might be the rings, and you can see that the rings get gradually closer and closer together:

So if we want the rings to be evenly-spaced, we need to get rid of that squared value, and we do that by taking the square root. There’s no “Square Root” Math function in Blender, but fortunately a square root is the same as raising a number to the power. There *is* a “Power” Math function that we can use. So, we need to change our into . This was the node network we ended up with at the end of part 1:

We need to insert the Power node before the Modulo node, like this:

And rendering we get this:

However, you can see that it messed up the scale. This is actually a good problem. Because our radius was exponential, the Scale of the overall shader was ramping up at a greater rate, and things like noise needed to be applied sparingly or they would quickly get out of control. Now that we’ve got uniformly-spaced rings, everything should behave better. If you bump the Scale in the Mapping node up to 5.0 instead of 2.0, you should get a similar look to what we had before.

If you’ve followed through to the end of the shader, you can insert the Power node right before the Modulo node in the Rings section:

So, yes, this was a pretty egregious mistake, but it was an awesome opportunity for me to learn and understand more. Thanks again to Ethos for pointing this out and helping to make our Red Oak shader even better!! Please, if you have comments or questions, reach out to me via the Contact form on the About page.

Another idea of Ethos’ that I hope to explore in a future post is the fact that trees get narrower towards the top, so the rings will get closer together (uniformly of course) down the length of a long board. Hopefully I’ll work on that soon so there’s not such a long time between posts. Thanks for reading!

]]>