You are here: Home » Old ArtZone Wiki » Public » Software Guides » Carrara » Carrara 6 » Chapter 22: Using Formulas in Carrara

This page exists within the Old ArtZone Wiki section of this site. Read the information presented on the linked page to better understand the significance of this fact.

Carrara allows you to create mathematical formulas that in turn create custom features. Using formulas, you can define your own objects, deformers, tweeners, shaders, gels, backgrounds, and backdrops. The interface for creating formulas is common for all items. The valid input and output variables differ for each item you create. Formula editing becomes technical quickly. Higher math or programming experience is recommended.

This chapter describes the following:

- How to use a formula item
- The Formula Editor interface
- Supported functions, operators, constants, and parameters
- The valid input and output variable for each formula item.

The method for creating a formula item depends on the item you want to create. You can create the following items using formulas:

- Primitive objects
- Deformers
- Tweeners
- Shaders
- Gels
- Backgrounds and Backdrops

To create a Formula primitive:

- Drag the Formula Primitive icon into the scene, or choose
*Insert menu > Formula*. - Double-click the object to display the formula controls, or click the Model room button.

To create a Formula deformer:

- Click the
*Properties tray: Modifiers tab*. - Choose Formula from the pop-up. The formula controls appear in the Modifiers section.

To create Formula tweeners:

- Double-click the gap between key events on the time track. Carrara opens the Transition Options dialog.
- Choose Formula from the pop-up. The formula controls appear in the Transition Options dialog.

To create Formula shaders:

- Display the Shader Tree Editor by double-clicking a shader in the Browser.
- Select the shader tree component where you want to use a formula.
- Select
*Pattern Functions> Formula*from the list. The formula controls appear on the selected branch of the shader tree.

To create Formula gels:

- Select a light other than Distant light.
- Display the
*Properties tray: Effects tab: Gel pane***l.** - Choose Formula from the list. The formula controls appear in the dialog.

To create Formula backgrounds or backdrops:

- In the Properties tray, select the scene, then click the Effects tab.
- Select Background or Backdrop.
- From the (Background or Backdrop) pop-up, choose Formula. The formula controls appear in the Effects section in the Background or Backdrop controls.

The formula controls include a readout of the formula itself, sliders for adjusting parameters, a Parse button, and a More button.

Use the Formula Editor controls to enter formulas and set variables.

For a few items, the controls also include a preview of sorts. (For the tweener formula, the preview is a graph.)

The formula editor for tweeners displays a preview of the formula as a graph.

To create or edit a formula:

- In the formula controls, click More. Carrara opens the Formula Editor.

- You can type into the window to build your formula. Be careful, the editor is case-sensitive.
- Each statement must end with a semicolon.

- When you are finished in the Formula Editor, click OK.
- In the formula controls, click the Parse button. Parsing compiles the formula to run.
- If appropriate to this formula, you can adjust the parameter sliders.

sin(x) | sine of x |

cos(x) | cosine of x |

tan(x) | tangent of x |

asin(x) | arcsine of x |

acos(x) | arccosine of x |

atan(x) | arctangent of x |

atan2(y,x) | arctangent of y/x |

sinh(x) | hyperbolic sine of x |

cosh(x) | hyperbolic cosine of x |

tanh(x) | hyperbolic tangent of x |

sqrt(x) | square root of x |

pow(x,y) | x raised to the power of y |

exp(x) | exponential |

log(x) | logarithm |

log10(x) | base-10 logarithm |

floor(x) | floor of x (The largest integer that is less than or equal to x) |

ceil(x) | ceiling of x (The smallest integer that is greater than or equal to x) |

abs(x) | absolute value of x |

mod(x,y) | x modulus y |

< | less than |

⇐ | less than or equal to |

== | equal to |

!= | not equal to |

> | greater than |

>= | greater than or equal to |

&& | logical “and” |

|| | logical “or” |

variable=^{1)}

For example:

a=((b>1)?1:b);

The expression (b>1) is the comparison. If it's true, the formula returns a=1. If it's false, the formula returns a=b.

PI

E

p1, p2, p3, p4

These parameters can be set between -1 and +1.

The variables valid for a particular item depend on its type. Refer to the section below that describes the variables for the formula item you are creating. To define a variable, just use it. Its initial value will be 0.

value (output is a grey level) or red, green, blue (output is a color)

The expected output is between 0 (black) and 1 (white or color maximum intensity).

You can use any of these output variables, however, the program can't use `value' and any of `red', `green', and `blue' simultaneously. If the shader is used in a color based channel, then color output variables will have priority (meaning if `value' and `red' are defined, then only `red' will be used). The opposite applies when using the shader in a value based channel, like Shininess. (If `value' is defined, `value' will be used).

u and v | These are parametric mapping coordinates. |

x, y and z | These are the local space coordinates of the point being shaded. |

nx, ny and nz | These are the normal local coordinates (normalized vector). |

X, Y and Z | These are the global space coordinates of the point being shaded. |

NX, NY and NZ | These are the normal global coordinates (normalized vector). |

The Formula Deformer iterates on all the points of an object, deforming them one by one.

*dx*, *dy* and *dz* The local coordinates of the deformed point. The range is -1 to +1 (0 is the center.)

*x, y, z* The local coordinates of the point to be deformed.

value

*t, tmin, tmax t* is time. One t unit is 1/1800th of a second. t is between tmin and tmax.

value or red, green, blue

Note: See the Formula Shader.

u,v (u,v) defines a point on the backdrop. The range is between 0 and 1. (0,0) is the lower left corner, (1,1) the upper right.

value or red, green, blue

Refer to Formula Shader.

x,y,z (x,y,z) is the global coordinates of the direction vector, from the camera eye to the background. The vector (x,y,z) is normalized and each coordinate ranges between -1 and +1.

value or red, green, blue

Refer to Formula Shader.

*x,y,z *local coordinates of the point defined by (u,v).

*u,v *The parametric space coordinates. The range is between 0 and 1.

comparison)?(value if TRUE):(value if FALSE

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution 3.0 Unported