Function Graphs 101

I've heard this since the pre-alpha days, "I make a function graph to drive my terrain and all I get is a flat planet!"

There are some wonderfully complex things that can be done with function graphs that just can't be done any other way. In order to get started, here's a series of steps to build a simple terrain that results in something other than a flat planet. It also introduces the Blend node, one of the most useful and powerful nodes in the Pro UI.

1. Use File->New to start a new planet.

2. Click the Terrain Editor hot button.

3. Change the Mountain Height parameter from a widget to a function. This will cause the circle-t Terrain texture hot button to open the Pro-UI from now on for this planet unless the Mountain Height parameter is changed back to a widget or changed to a texture. In either case, the function will not be used.

4. A Pro-UI window will open with a single Mountain Height node in it. This node is colored brown. All function graphs have a single brown node in them which is known as the "root node". This node is the bottom-most point of the graph, the node into which all data flows.

5. If you'd taken a default texture leaf and turned it into a function graph, the node immediatly above the root node would be labelled "Texture Color Control" and to be even more confusing, if that texture was a heightfield texture (which it would be for textures driving the terrain), it wouldn't actually be a "Texture Color Control" node, it would in fact be a "Curve" node.

Well, back in the good ol' days before there was anything to MojoWorld except for an RTR window and the Pro UI, we didn't have Texture Color Control nodes or Curve nodes. So, I'm not going to have you make either one. Instead, I'm going to introduce you to one of the most powerful nodes in the Pro UI toolkit, the Blend node.

Use the menu item "Create New Node" to open up the new node dialog. The Blend node is found in the Utilities category.

6. Connect the output of the Blend node to the input of the Mountain Height node. If you've never been in the Pro UI before, that's done by dragging on the point sticking out the bottom of the Blend node to the point sticking out the top of the Mountain Height node. When the drag is started, a black line will appear between the bottom point of the Blend node and your mouse cursor. When the mouse cursor touches the input of another node, the line will turn yellow. Release the mouse while the line is yellow and the connection will be formed.

7. Take a look at the parameters of the Blend node. Their names may seem confusing at first, but once it clicks, this node will be a dear friend.

  • Blend Low Value - the output of the Blend node when the Blend Value parameter is smaller than the Blend Range Low parameter.
  • Blend High Value - the output of the Blend node when the Blend Value parameter is larger than the Blend Range High parameter.
  • Blend Range Low - the value that defines the lower end of the blend range.
  • Blend Range High - the value that defines the upper end of the blend range.
  • Blend Value - the value to compare against the two range endpoint values.

If your Blend node only has three parameters instead of five, you haven't hooked up its output yet. Because a Blend node can blend data of different types, the first two parameters aren't defined until the output is connected and the node then knows what data type to use for those parameters. In this case, the data is used for a heightfield, so there's just one field, the height. Blend nodes can also blend colors (and would then have three fields, one each for Red, Green and Blue) or other multi-fielded data (such as a position field, which will have as many fields as there are dimensions in the position being used).

8. To make our Blend node do something interesting, like create a not-flat planet, the first thing to do is to drive the Blend Value parameter with the output of something interesting - such as a Fractal. Use the "Create New Node" menu item and create a new fractal node. I'm partial to the Mountain Fractal, but you can use any fractal out of the Fractal category you like.

9. CRITICALLY IMPORTANT - When the fractal nodes are first created in the Pro-UI, they have a basis function of "None". No matter what you do to the parameters of this fractal node, its output will always be zero, which means it's always "flat planet time". The first thing to do with a newly-created fractal is to specify a basis function other than "None"! I used Value/Gradient Perlin, which is the default basis function out in the Generator UI.

10. After picking a basis function, the other important parameter to specify is the Largest Feature Size. Here's another place you'll notice the difference between the Generator interface and the Pro UI - in the Generator, there's only one parameter for the Largest Feature Size and in the Pro UI, there are three parameters. This lets you have your mountains longer along one axis than they are along the other two. For now, set the three values here to something in the range of 50,000 to 100,000.

11. Head on back to the "Create New Node" dialog and create a World Position node to provide input to the fractal. The World Position node is found in the Leaf Node category. A leaf node is one that takes no input; it only provides basic data about the world. Connect the World Position node to the Position parameter of the fractal node (the left-most parameter).

12. Don't worry about the fractal's Result Scale, leave that at 1, and here's why - we'll get all the result we need out of the Blend node. Connect the output of the fractal to the Blend Value parameter of the Blend node (the right-most parameter).

13. Go back to the Blend node. There's now a function driving the Blend Value. Output from the fractal will depend on the basis function chosen, but for most basis functions, the output will either be -1 to 1, or it'll be 0 to 1. Some experimentation with the other parameters of the Blend node will give you an idea of what sort of range the fractal is producing.

Try setting up the parameters of the Blend node as follows:

  • Blend Low Value: -10,000
  • Blend High Value: 50,000
  • Blend Range Low: -2
  • Blend Range High: 2

And of course, the Blend Value is being specified by the fractal. Stow the Graph editor and take a look at your planet. It will _hopefully_ not look flat, but just in case it does, get a little altitude by typing the 'b' key.

With the parameters specified above, the terrain will be at -10,000 meters when the output of the fractal is -2 or less. The terrain will be at 50,000 meters when the output of the fractal is 2 or larger. Because of these fixed endpoints, it's possible that the terrain will have some very flat spots in it - plateaus at 50,000 where the fractal outputs 2 or more.

In a lot of ways, a Blend node is exactly like a Curve node, except that it always clamps on both ends and the only "curve" you can have with a Blend node is a straight 45 degree angle. But unlike a Curve node, the parameters of a Blend node can all be driven with functions. (Gunther, I can hear you say, "Ah-ha" from here!)

Back to Generator Tutorials

Home