When I did my self portrait character (the one I’ve been using for my profile pic around the web and is in the banner on my site) back in August of last year, I was thinking about what I should do for his shirt.  A couple of my favorite shirts from my closet had stripes on them, and I thought one of them would be fun to try to do.  I remember searching for a tutorial on how to do stripes in Cycles, but couldn’t find anything that explained how to do it.

Stripe patterns occur a lot in textiles (particularly modern textiles) and can be found on shirts, suits, pants, socks, ties, blankets, sheets — the more I looked around, the more I saw stripes everywhere.  Yet looking through artwork on Blender Artists, Deviant Arts, and a number of other sites around the web, striping patterns rarely seemed to show up in artwork.  As I searched the web, I discovered that stripes could be found on more than just textiles (including cloth used to cover furniture). Plates, bowls, cups, and even toys are just some of the other objects that stripes could be found on. And that’s not even getting into candies like candy canes and mints.

One method that seems pretty obvious would be to use a tileable pattern that was created in an image editing program like Photoshop, Gimp, or Krita.  The problem with this is that creating the pattern in one of these programs takes quite a bit of time and it’s not easy to change the pattern if you decide you want to do something different.  So I wondered if there was a way to do it procedurally.

My First Character - A self Portrait

My First Character – A self Portrait

The method I wound up using on my first shirt did work (and a variation on it), but turns out to be fairly cumbersome. While it might work for a simple stripe, the more complicated you want to make the pattern, the harder it becomes to manage.  But in looking for a better way when thinking of doing a tutorial on it, I found a way that is incredibly simple and easy to use and extremely flexible and powerful on the range of patterns it can create.  I’ll show you all three.  

The last can provide the same results as the first two, but I want to you all 3 for 2 reasons.  First, as I said, in simple situations, they just might be more than enough to do what you want it to do.  Second, I want to show the thinking behind how I came up with the third method in hopes that in showing how I combined ideas from tutorials I had done in the past might spark some ideas in someone else that leads to some interesting results.

Basic Setup

Before jumping into the tutorial, I want to explain a few things that I have set up in the beginning.  I’m going to show the striping on a shirt that I have modeled, but the object that you do the striping on isn’t really important. It’s just the object that I am using in this case.  If you’re wondering how to model and sculpt a shirt like the one I’m using, I got the basic idea for the technique from Jonathan Williamson’s Intro to Character Modeling course in the courses section of CG Cookie.

For some objects, like clothing such as shirts and pants, you’ll want to set up UV seams.  The best place to put seams on an article of clothing is where seams would occur naturally anyway.  With a shirt, for instance, you would place seams to separate the sleeves from the rest of the shirt, along the shoulders, and from the underside of the sleeves to where it separates from the shirt and continuing down to the bottom of the shirt. You might also place one to separate the collar from the shirt.  If you’re not sure where to place the seams, look at an example of the object that you might have access to.

In the materials area, you may also note some other nodes besides the ones I’m specifically pointing out.  Again, these aren’t really important to understand the striping. One group is setting up a mix of Diffuse, Glossy, and Velvet nodes using Fresnel to control the mix.  The other group of nodes is to give the bump texture for the shirt.  For these two groups, use whatever makes sense for the object that you are trying to create.

With all that out of the way, let’s get started. The important part, for this tutorial, is what to plug into the diffuse coloring for the stripes.  And that’s what we’re going to work on now.

Easy Striping

When I first considered the idea of striping, the first thing that came to mind was the Wave texture with the wave type set to bands.  The gradient automatically forms a nice little banding pattern that could easily give the idea of the stripes.  The first thing to notice, though, is that the stripes don’t really look like they belong on a shirt.   That’s because it’s using the default of the generated texture coordinates.  

It turns out that Object, Normal, Window, and Camera also give unsatisfactory results in this instance.  If I were doing an object like a torus or a sphere or some other object where I wouldn’t expect seams, then one of these would work, but for something like a shirt, the best one to use is UV.  With the UV coordinates, now you can see a “break” in the pattern like you would on a real shirt, at the seams.

The next thing to notice is that the stripes are going diagonally. For something like a tie, that might be exactly what you want, but for a shirt, we want them to go either vertically (up and down) or horizontally (left to right).  Adding a Mapping node will let us do this.

If you’re using one of the other coordinate systems on a non-UV object, you might have to play around a bit with this setting to get the correct positioning of the stripes.  For UV coordinates, adjusting the X rotation to -45 degrees (with the others at 0) will give you vertical stripes and adjusting the Y rotation to +45 degrees (with the others at 0) will give you the horizontal stripes.  Out of curiosity, I tried varying things to see if I could get a diagonal stripe in the opposite direction, but without adjusting the size in the mapping node or the scale of the islands in the UV unwrap, I was unable to find a satisfactory result.

With the stripes now angled the correct way, you might notice one island that might be off a little. You can scale, rotate, or grab (move) any of the UV islands in the UV edit mode to adjust the positioning so that you can line up a stripe, match the front the back, or adjust the positioning of the stripes.

What we have now with the stripes is a gradient that goes from white to black to white in a repeating, even flowing pattern.  For stripes, though, we want the pattern to be a little tighter.  Adding in a Color Ramp will allow us to do this easily.  While you can use any interpolation mode you wish, I find it simplest to use the Constant interpolation because it requires the fewest markers to achieve the correct result.

To adjust the size of the stripe, just move the marker to whatever position you desire.  In my example, I used a setting of 0.1 for a fairly narrow stripe.  If you want more stripes, increasing the scale will give you more.  Here, I’ve set it to 10.

Here, I initially made a mistake in my method because I forgot that the color ramp could easily be used to get the color for the stripe simply by changing the color of the marker.  I did realize, though, that the output that I had would be perfect for using as a factor of an Color MixRGB node, so that’s what I did.  The lower socket of the mix node become the base color of the shirt (the white portion of the color band result) and the top node becomes the color for the stripe (the black portion).

The shirt I was basing the pattern on had two, evenly spaced stripes.  So I selected the Mapping, Wave, Color Ramp, and MixRGB nodes and duplicated them with CTRL-SHIFT-D to maintain the connection to the UV coordinates.  Placing the result of the original Mix RGB node into the lower socket of the duplicated MixRGB node and changing the color of the upper socket to the color for the second stripe gave me a new stripe once I plugged this result into the DIffuse color socket..

A problem suddenly appears, though, because now the other stripe disappeared.  What happened?  It’s simple, really. The two stripes are now occupying the same coordinates.  By adjusting the positioning of the new stripe in the duplicated Mapping node, you can find that both stripes really are there.

This is where the awkwardness of this method really begins to show.  While this is a completely workable method, depending on  how you want the stripes positioned (evenly space, stacked, close but with a little space between them, etc) figuring out just how much to adjust the values is really tricky.  For the settings I used on this example, using 0.01 (or 1 cm) will give stacked stripes and  0.03 (or 3 cm) will give evenly spaced stripes.  Adjust the scale or the size of the bands, and this value could easily change.  You’ll just have to keep trying until you see what works for the pattern you’re trying to achieve.

DualStripes

Simple Stripes set up — 2 color stripes

As you can see, this method works for a simple one or two stripes, but the more stripes you have, the more cumbersome this becomes and it’s not easy to adjust at all.

Easy Stripes — Variation

After several months of thinking about doing a tutorial on how I created the stripes for my shirt, I sat down one day to look at what I had done.  Thinking back on the various tutorials that I had done through the years, I almost instinctively knew that there had to be a better way of controlling the color and size of the stripes.  After all, it’s easy to see just how cumbersome it would be if I wanted to add a 3rd or 4th stripe into the mix, much less trying to get bands of differing widths.  If there was a way to control what colors showed up along the different parts of the gradient.  

I finally remembered that the color ramp could be used to control the color directly, eliminating the need for duplicated and mixRGB nodes — or so I thought.  

To test this idea, I deleted the duplicated nodes and the mixRGB node.  I fed the result of the color ramp directly into the diffuse color socket.  And I changed the color of the black marker to blue.  So far, so good.  So I added two more markers.  I thought that if I placed the markers evenly space, that I would get the same result as before.  So I placed one of the new markers at 0.5, giving it a red color, and the other at 0.6, giving it the base shirt color of white.  

Wait… What happened?  This wasn’t what I expected at all!  Now, I had two really thin red lines on either side of a blue line.  Trial and error showed me that I had to make the red markers 4 times as far apart to get the same width as the blue markers, and I couldn’t understand why.  Until I thought about the gradient that was being generated by the wave texture.

Remember what I said about it?  The wave texture produces a gradient that goes from white to black along a gradient and from black to white along a gradient, evenly repeating the pattern.  In essence, what was going on was that with the way I had the markers positioned on the color ramp was it was passing through the red markers to the blue then kept going from the blue back through the red. Essentially, the blue space was twice as much as the red space — and the red space was being halved on either side of the blue.  This results in a repeating ABCBA pattern that is “reflective”.

ColorRampColor-Reflective.blend

Reflective Stripe Pattern

In other words, to achieve the exact same pattern I had before, I should have put them with the same size at either end of the color band.

I show this because it can lead to some interesting patterns that might be useful in some situations, but still isn’t ideal for full control of what is happening.

The Powerful Stripe Setup

As I thought about the “reflective” nature of the bands gradient, I realized that what I needed was a gradient that went from white to black but when it got to black, instead of going on a gradient back to white, it jumped immediately to white.  And with a little thinking, I realized just where I had seen such a thing.

About a year or two ago, Bartek Skorupa did a Shader Forge tutorial for CG Cookie showing how to do a wood texture procedurally in Blender.  That particular tutorial stands out in my mind because it took me 4 or 5 times through that tutorial, step by step, before I finally figure it out and another 4 or 5 times before I understood it enough that I could (almost) replicate it without having to use the tutorial to guide me.  And for those of you who have seen that tutorial, the Modulate node group is exactly what we need.

In case you haven’t seen that tutorial, here’s what you need.  Start with a Converter Math node and set the operation to Modulo.  Feed the vector from the mapping node into the top socket of the Modulo math node.  Take the second value and make it really small, like 0.05.  Feed the result into the diffuse color socket, and you’ll see that we have a gradient that almost does what we want, but it only ranges from a mid grey to black.

Duplicate the Modulo Math node and drop it on the line to connect the duplicate between the diffuse shader and the original modulo node.  Change the operation to divide, and now the gradient should go from white to black just as we want.   As long as the values of the lower sockets of the Modulo and the Math node are the same, we will get the gradient from white to black.

But this set up has one flaw.  If we want more stripes, we have to make the two lower values smaller and smaller.  It would be more intuitive if we could adjust this to larger and larger numbers instead.   This can easily be achieved by duplicating the Divide node.  Change the top value to 1 and the bottom value to, say, 20. Plug the result of this new Divide node into the lower sockets of both the Modulo and the original Divide nodes.  

To make this easier to use, we can group these three nodes together with CTRL-G.  The group input node should link to both the modulo and the new divide node and the output for the group should be connected to the first divide node.  On the group input, change the name of the one that goes to the divide node to “Cuts” (you can think of this as how many times it’s cutting the gradient) and set the lower limit to 0 since we don’t really need negative values.  Pressing tab will take you out of the group where you can change the name of the group to Modulate.  Now, adjusting the number of cuts will adjust how often the pattern repeats.

ModulateGroup

Modulate Group

All that remains now is to bring the Color Ramp back into the mix.  And instantly, we have our stripes back to the way they were in the original with fewer nodes.

Best of all, this set up has way more flexibility than before.  The original way would be tricky to add more bands, but with this set up here, you can have as many bands, as many colors as you want. You’re literally now only limited by your imagination of the stripe patterns you can come up with.  I’ve done shirts with evenly spaced/width stripes, varying widths/spacing, pinstriping like you might find on a dress shirt or a suit… I even have one that had about 20 different colors.  This set up is really flexible and super simple to use, just by adjusting the color and placement of the markers and how many cuts to make the pattern repeat.

PowerfulStripesSetup

Powerful Stripe Setup With Two Stripes

One last trick!

Everything I’ve shown up to this point has been stripes going the same way.  After I had figured out how to do these striping patterns (and some of the ones I’ve already mentioned are either some I have in my closet or have seen either on other people or in the stores), I looked again in my closet and realized that I had some shirts with crossing stripe patterns and also plaids — varying widths and colors on both the horizontal and vertical stripes.  Could these be done with this setup with a relatively minor modification?

The answer is YES!  It can!  Duplicate the three nodes, the mapping node, the modulate group, and the color ramp (remembering to use CTRL-SHIFT-D to maintain the connection to the UV coordinates).  Add a Color MixRGB node.  Connect the result of the new group to the top color socket of the Mix node and the result of the original group of nodes to the lower socket.  Depending on if you’re going for a plaid or just a basic crossing stripe pattern, you might try either Mix with a factor of, or a little off of, 0.5) or Multiply with a factor of 1.

CrossingStripes

Crossing Stripes

Summary

Even without the crossing stripe patterns, this setup is really flexible and useful.  Add in the crossing stripes, and a whole new world emerges.  Funny thing is that since coming up with this method, I’ve seen variations of the patterns that I had originally come up with in real life.  And I’ve seen the patterns on more and more objects from purses, to scarves, and beyond.  Stripes are a part of every day life, and now that you know how easy it is to make them, they can easily add interest to your renders.

One pattern I haven’t figured out yet that I feel is some variation of what I’ve done modifiying it somehow similarly to the way Bartek Skorupa used it in the Shader Forge Wood tutorial is a ripple, or zig zag, pattern.  If you could add that variation, that adds even more flexibility to this already easy setup.  And if you figure it out, I’d love to see it!  Ripples can be used almost as widely as stripes, particularly in blankets.

ShirtsAll

Several examples of shirts created using the methods in this tutorial.

 In this image above are 10 examples of shirts created with methods shown in the tutorial.  The first 2 are shown with the simple stripes method.  The third shirt is based on the variation.  The rest are all done just by using variations of the powerful stripes solution.  They show just some of the range of capabilities of using, and even a little mixing, of the stripes patterns.

I hope you enjoyed this tutorial!

(I’m going to go ahead and release this as soon as I finish typing.  I do have some images to support this article, and I will get them posted, but I really want to get this out there! I may even rerecord the video tutorial, focusing on this last bit, and see if I can get that to render without crashing my computer!)

Like my art?

Coloredcubes-xxsm

Want to be updated when new pieces or formats are available? Sign up to my newsletter!

Powered by ConvertKit