Advanced Tweak Structures - Here we will introduce a number of methods for setting up tweak controls so they are user friendly. This will be useful to anyone who is designing well rigged procedural materials.

1. Range Control and Composite.

When setting up tweaks, you will often find that you want a tweak to apply to a smaller range of parameters values.  For example if you export a ``dirty up the surface" tweak using the Darken component, it probably doesn't make sense to allow the surface to darken all the way to solid black. As a result, you will want to restrict the tweak values that apply to Darken to a value range like 40% to 100%. Composite is the best component for doing this.
Composite makes the perfect tweak range control. To use it, link the parameter you are tweaking to a Composite control. Set Composite's Percent A control to the minimum value you want to apply and Percent B to the maximum. Then tweak Composite's Mask parameter and give it the tweak name you want.  This will re-map the tweak's 0% - 100% range to the new range you specified in Composite.

Depending on the name of the tweak, you may want to invert how the tweak applies. For example, if you had a tweak named Dirty, you would want 100% to be maximum dirt.  If you named it Clean instead, you would want 100% to be the cleanest setting.  All you need to to is select Composite's Invert control to make this switch.

You can also use Composite to manage multiple controls of different ranges linked to the same tweak. The two composites in the image are both used to control reflectivity through a single tweak.  In this example, the edge increases in reflectivity more than the front facing geometry.  The edge has a range from 0% to 90% while the facing range is 0% to 20%.

Note: Composite is also good for bounding Bump ranges.

2.  Rate of change with Composite.

Another issue can be the rate at which a tweak control changes.  Most parameters in DarkTree are designed to change the texture at a pretty even rate as you change their value. You may not want that behavior, especially if you are controlling multiple parameters with the same tweak.  You may want the tweak to ease in more gradually or kick in fast and fade.

To do this, use Composite (as described in step 1) and link its Blend Function to a Generator. The example shot shows Composite's Blend Function linked to a Bias.  Bias is good for starting slow and accelerating (as in the example image) or starting fast and slowing.  Gain and S-Curve are good for ease-in / ease-out rates.  If you want to model a behavior exactly, use the Spline Generator.

3.  Randomized Color Control.

For patterns that allow for a range of random colors, there are two good methods for setting up tweak controls.  You could simply use a Color Randomizer and tweak all of its controls.  This works but it requires six tweak controls and can be difficult to use.

Alternatively, you can use a Color Composite to blend between two tweak colors.  To do this, tweak Composite's Color A and Color B for the color range and link the Mask parameter to a Percent Randomizer. In the image below, the color range was set to red and teal.  As you can see, the bricks vary between these two colors.
Another component you can use is HSV Attract.  In this case, you will want to tweak HSV Attractor's Background and Target as the color ranges and link Hue Amount, Sat Amount and Val Amount to a Randomizer. The example above shows this method with the color range set to red and teal. Note that this method is much more colorful than the Composite method. This is because HSV Attractor goes from one color to the next through HSV space instead of Composite's linear RGB space. In the above example, there are yellow, orange, and green hues between the teal and red colors.

Another good method that goes along with randomized color control is biasing the color range toward one end of the color range.  To do this simply link Composite's Blend Function to a Bias Generator. Then edit the Bias until you get the look you want.  The example below shows the color range heavily biased toward teal.  If you want to bias the HSV Attractor method, you will need to add a Percent Composite between the HSV Attractor and Randomizer while linking Composite's Blend Function to a Bias Generator.

4. Specific Color Ranges.

Another tweak control structure you might want to have is a percent control that generates a specific range of colors. A good example might be if you wanted an infrared heat camera shader. You could export a control called Temperature. As Temperature increases, you want the surface to go through a specific range of colors representing different temperatures.  The Mask Gradient component can serve this task.
To use Mask Gradient, set the Mask parameter as your tweak (temperature for example).  Then use Shell Position to indicate where a color is active and set Shell Value to the color you want. For each Mask Gradient, you can have five different specific colors. If you need more color ranges than that, you can combine multiple Mask Gradients together to give you an unlimited range of colors. Between the Shell Positions, the color is blended in a gradient. If you want discreet colors (no gradient), link a Square Wave Generator to Mask Gradient's Blend Function.

5. Blending Generators.

Another feature you might want to be able to tweak is a blend between Generator function curves. In the example below, we are blending between a Linear function and a Sine Wave.  Again, the solution here is to use the Composite component. To do this, simply link Composite's Percent A and Percent B parameters to the Generators that you want to blend between. Then tweak Composite's Mask parameter as your blend amount. Note: In the example shot below, the Add component is not a necessary part of the tree. It is just there to show what the blended Generators look like.
Using Composite in this case is not obvious since the Percent A and Percent B parameters are not Functional, but as the DarkTree 2 manual explains, Functional control will pass through all non-Functional parameter from higher up in the texture tree.

6. Animation Speed.

A final tweak control structure we will go over is an animation speed control. If you are working on a complex animated shader, you may have several sub-animations going on at once.  If this is the case, it can be useful to allow the shader user to independently tweak the sub-animation rates.

To do this, you will need a Linear Generator and a Composite component in addition to the Time component like in the picture below. First, link Linear's Input parameter to Time.  This turns the Linear component into a time based function. Next, link Linear's Amplitude and Shift parameters to Composite. Next, edit Composite.  Set Percent A to 50% and Percent B to 0%. Then tweak Mask as your animation rate control. The Amplitude control flattens Linear which slow the animation while Shift will keeps Linear glued to the bottom of the plot so the animation always starts at the beginning.
This concludes this tutorial page's list of control structures.  With these and other derived tweak structures, you will be able to rig procedural shaders that behave in an intelligent and predictable way.

Darkling Simulations © 1997-2003          Any questions? Mail me! skyler@darksim.com