A reusable apple material in Blender 2.79b

Introduction

The Facebook group Blender Procedural Textures holds biweekly contest to construct procedural textures. A recent challenge was

You will try to come as close as possible to an apple, BUT I would like the nodes to be structured, grouped and user friendly, so that you can dynamically change your apple to green or red, mix colors or decide how many lines and spots the peel should have. In short… a perfect “apple peel material” that you can set in the hand of a non node expert user and they should be able to use it .

My entry renders as

apples

A render of two apples created with the same apple node group.

This is a brief discussion of how I created the materials. I created this with Blender 2.79b.  It should work for any version of Blender that has the node groups I used. It can be improved in later versions of Blender by using microdisplacement.

Preliminaries

What color is an apple?

The first rule of creating objects or materials for 3D rendering is to look at examples. The US Apple Association has a nice collection of large images of apple types and a Google search will turn up many images as well, although it will also turn up a lot of copies of Apple’s logo.

It appears to me that an apple peel may have

  • A basic color
  • Variations on that color
  • Vertical blemishes
  • small dots

There are other aspects as well, but providing these four things will produce a pretty good apple (material).

Modeling an apple.

I am taking Stephen Wood’s Complete 3D Artist course on Udemy. In one lesson, he creates an apple.  Using that technique, I created an apple for the contest. It’s simply a modified sphere, sculpted to have the form of an apple, with a stem extending from the top.

apple

apple

You can search YouTube and discover Apple How-To Tutorials

Lighting

Changing the lighting in a scene will change the way materials in scene will appear. Gleb Alexandrov has a nice series of lighting tutorials on YouTube.  You can also look for tutorials on photographic lighting, as the principles are the same.

That said, I decided to be lazy and use an existing lighting set up. I grabbed the Modified_b.m.p.s.ByRobinMarin.blend file and stripped it down to its basic lighting.

Building the material

The contest instructions suggest that the nodes to be structured, grouped and user friendly. I decided to make an apple node group that generated the apple color, but did not include the shader to be used. Here are two examples of using the node group to create a red and green (really yellow) apple material.

A limitation of using a node group like this is that there is no way to control the handles of a color ramp that is embedded in a node group, unless you want to change every material that uses that group. This greatly influences the design of the node group.

Basic skin color

The skin of an apple isn’t a single color, but rather runs a gamut of shades of the same color. An easy way to produce this effect is to use a Musgrave texture to control a mix factor.

Commonly, a color ramp is used to tune the pattern provided by the Musgrave texture. But color ramps won’t work within a node group, so a MixRGB node is used instead.  This provides an acceptable approximation of the basic color.

Dots

A Voronoi texture can be used to produce random dots. A Voronoi texture creates cells. Each cell has an intensity that varies from one at the center to 0 at the edges in a circular pattern. We can use the Voronoi to control the mix.

A simple Voronoi mix

A less than node creates circles from the Voronoi  This works well if you want precise circular dots, but the dots on the apple aren’t that precise.  A workaround is to use a color ramp rather than the less than node.

But we want to control the size of the dots as a parameter of the node group, so a color ramp won’t work. I have a node group that will do this.  It is described in Faking a color ramp in Blender 2.79.

Stripes

There are a few ways to go about adding random stripes. Since these stripes tend to run in a vertical direction, it makes sense to use a noise texture scaled in X and Y as the factor for a mix RGB node.

Putting it all together.

So far I’ve shown each aspect separately.  It’s easy to put them together with mixRGB nodes.

Bumps

Two factors contribute to the bump map.  The skin has an overall bumpiness.  This is easy enough to represent with a noise texture.The dots also contribute additional bumpiness. We need to balance these out, so we multiply the noise texture by a factor before adding it to the bump data from the dots.

The multiply balances the relative strength of the bumps from overall bumpiness and the bumps from the dots. The strength parameter of the bump map controls the overall strength of the bumps.

Making the node group

There are no color ramps in the material, but it does use a vector mapping node.  Vector mapping is another node that doesn’t fit well into node groups, so we perform our own equivalent.  In this case, we only need to scale the vectors, not translate or rotate them. Scaling a vector is accomplished by separating the X, Y, and Z values, multiplying each by its scale factor and recombining them to make a new vector
This is useful enough to make into its own node group

The finished material

Converting to a node group

I like to create a node group in stages.  First I determine a parameters I want to expose. Next I add an input node to hold the value of that parameter. Then I give the input node a label that represents what I think will be a good name for the parameter in the node group. I repeat this until I have all of the parameters.  Then I select the nodes that will make up the node group and make the node group.

There are twenty nine input sockets in the finished material. It would be possible to expose all of them, but the node group would become unintuitive and unwieldy. Here are the choices I made

  • Base colorIn an fBM Musgrave, offset and gain have no value. Because the basic shape using the default detail, dimension and lacunarity are sufficient, controlling only the scale seems sufficient.  Of course, the two colors used by the mix RGB node have to be parameters.
  • Dots the X0, Y0, and Y1 values of the linear equation are specified by the problem design.  Likewise the clamping parameters are specified.  This leaves only the dot size, which is the position of the White pos in the equivalent color ramp, and the scale, which sets the density.
  • StripesThere is no advantage to changing the Z scale, nor is there any real value in setting the X and Y scales to different values. The noise texture default detail and distortion are sufficient, so the only parameter for it is the scale.
  • Bumps The default detail and distortion serve well enough. The multiplier value was explained above.
  • Now we’ve set the input parameters, we choose the output parameters, in this case the final color mix and the height map.  If we leave out all of the input parameters, the bump map, shader, and material output nodes, we can create a node group

Cleaning up the node group

Creating the node group has a couple of problems.

Externally, the parameters don’t have good names or default values. This is resolved by the tedious task of editing each parameter interface slot, setting its name and giving it reasonable defaults. Eventually you end up with a node group with its own name, and with (hopefully) meaningful names for its parameters

Internally,routing can make a spaghetti mess of the node group layout

Everyone has their own way of organizing node groups so that they are readable.  I like to use frames to group functionality, to use reroutes to clarify routing and to use reroute labels to help tracing the routing.

The entire node group

Leave a Reply