Skip to content
VIDEOMONTAZHERDAVINCI RESOLVE · VIDEO · AI

FUSION · Expressions

Syntax and types: Lua without confusion

Numbers, operators, functions, points and text. How Simple Expression differs from JavaScript and Expression Modifier.

Fusion / DaVinci Resolve 20–21

After this lesson

  • Distinguish a number, Point and text.
  • Understand operator precedence and Lua conditions.
  • Clamp the result to the parameter range.

Before you start

Composition
A separate Fusion Composition. 1920×1080, square pixels, 25 fps.
Parameter
Merge1 → Blend
Range
Start at comp.RenderStart. Reference frames are local unless stated otherwise.

Simple Expressions use Lua syntax with Fusion extensions. This is neither JavaScript nor the After Effects expression language. The built-in Expression modifier is another, separate mechanism with its own inputs and rules.

Numbers and operators

Use a decimal point: 0.25. Multiplication is *, division is /, exponentiation is ^ and remainder is %. Parentheses make the evaluation order explicit. 1/2*4 returns 2, while 1/(2*4) returns 0.125.

Comparisons are ==, ~=, <, <=, > and >=. A single = is not a comparison. Concatenate strings with .. rather than +. Names are case-sensitive.

One input, one expected type

Return a number for Size. Use Point(x,y) for Center. Return text for Styled Text, for example Text(string.format("%03d", 12)). A point object cannot simply be added to an ordinary number without conversion.

math.sin, math.cos, math.abs, math.floor, math.min and math.max make the intended functions explicit. math.sin and math.cos take radians. Do not automatically carry units over from another expression system.

Clamping a range

Combining min and max clamps a value to an interval. This is useful for opacity, progress and parameters where negative values make no sense.

SIMPLE EXPRESSION · FUSION
math.min(1, math.max(0, (time - comp.RenderStart) / 30))

Predictable precedence and conditions

Parentheses define the order explicitly; exponentiation precedes unary minus. Therefore −2^2 gives −4, while (−2)^2 gives 4. Use a decimal point, not a comma: 0.25 is a number, while commas separate function arguments. Equality uses ==, not =; inequality uses ~=.

Lua treats false and nil as false, but not zero. Therefore iif(0, 3, 9) does not mean that zero is off: it selects 3. Compare numeric switches explicitly, for example n > 0. This matters when bringing habits from JavaScript or Python.

NotationResult / meaningCommon mistake
2^38This is exponentiation, not bitwise exclusive OR.
-3 % 21Lua remainder uses a quotient rounded down.
time == 10Logical conditionA single = does not test equality.
math.sin(math.pi/2)1The argument to math.sin is in radians.

One input, one contract

A number suits Size or Blend, but Center expects a coordinate pair. Point(0.5, 0.5) creates a point at the center of the frame; two comma-separated numbers without Point do not replace it. Styled Text needs a text result. Wrap a counter calculation in Text, and check formatting separately from the mathematics.

Use the input names generated by Pick Whip. The displayed label and internal identifier can differ. The laboratory supports only a safe numeric subset: success there does not prove that a node exists or a string function is available in your composition.

Parameters and ranges

ParameterWhat it changesExample / check
math.min(1, …)Upper limit.Prevents Blend from exceeding 1.
math.max(0, …)Lower limit.The result stays at zero before the transition starts.
30The linear rise duration in frames.The value at local frame 15 is 0.5.
Point(x,y)A two-component position result.Point(0.5,0.5) is the center.

USE IN A COMPOSITION

Build it in Fusion

Merge1 → Blend

FUSION / FLOWNodes and parameter control
100%
ImageControl in the InspectorScroll or drag the graph. Choose “Fit” to see all of it.
Solid lines are node connections in the Flow. A dashed line is a parameter dependency configured in the Inspector. A solid arrow's color matches its destination input. Modifiers are shown separately from the Flow.Background1.Output → Merge1.BackgroundMerge1.Output → MediaOut1.InputText1.Output → Merge1.Foregroundcontrol.Value → Merge1.BlendText1 · Image node · FlowT+Text1Text+Background1 · Image node · Flow▧Background1BackgroundMerge1 · Image node · Flow⊕Merge1MergeBlendBlend · an Inspector parameter, not an image portMediaOut1 · Image node · Flow↗MediaOut1MediaOutExpression · Expression · InspectorEXPRESSIONExpressionSimple Expression
BackgroundImageForegroundParameter · Inspector
Select a node or a colored arrow

Solid lines are node connections in the Flow. A dashed line is a parameter dependency configured in the Inspector.

Connections by port and parameter4

Color is determined by the destination input. Dashed connections are configured in the Inspector; they do not add an RGBA wire to the Flow.

Assembly steps

  1. Create Background1, Text1 (Text+) and Merge1. Connect Background1 to the yellow Background input and Text1 to the green Foreground input; connect Merge1 to MediaOut1.
  2. Enable Expression on Blend.
  3. Paste the clamped linear ramp.
  4. Check local frames 0, 15, 30 and 60.
SIMPLE EXPRESSION · FUSION
math.min(1, math.max(0, (time - comp.RenderStart) / 30))

Expected result. Blend reads 0, 0.5, 1 and 1: the title stays visible after appearing.

Checkpoints

When / what to checkExpectedWhy check it
0Blend=0The title is hidden.
15Blend=0.5Halfway through the linear transition.
30 and 60Blend=1The ramp holds after completion.

INTERACTIVE EXAMPLE

Change a parameter. Compare the result.

EXPRESSION · INTERACTIVE EXAMPLE

A number in the formula becomes opacity in the frame

CONTROLLED PARAMETERMerge1 → Blend
0 f← → one frame at a time25 fps
VALUE GRAPH
Blend
-0.120.51.120 f30 f60 f
Select a point on the graph to go to that frame. Values are checked throughout the range.

The linear ramp is clamped to 0…1. Move the playhead beyond the final transition frame: the title remains visible.

OUTPUT VALUE0.5
CHECK THE ORIGINAL EXAMPLE

With duration 30, frames 0, 15, 30 and 60 give Blend values 0, 0.5, 1 and 1.

Formula for the current settings +
Merge1 → Blend
math.min(1, math.max(0, (time - comp.RenderStart) / 30))

The article's numeric formula is evaluated. The ramp controls foreground Blend; the background stays unchanged.

Errors and troubleshooting

Error near a decimal number

Replace the decimal comma with a point.

A formula from another tutorial is rejected

Check the environment: Simple Expression, Expression Modifier, Custom Tool and scripts are not interchangeable.

Independent exercise

Clamp an arbitrary number v to the range 0.2–0.8.

Show the solution and explanation

math.min(0.8, math.max(0.2, v)). In a real expression, replace v with a number, formula or existing input.

Continue learning

Official sources

Blackmagic Design · Fusion Reference ManualThe chapter “Using Modifiers, Expressions, and Custom Controls”. Page numbers depend on the PDF edition.
Lua 5.1 Reference ManualSyntax, mathematical functions and strings. Fusion adds its own objects and functions; the full scripting environment is not available.

An original educational walkthrough. The browser model explains the principle but does not run Fusion. Control placement depends on the version; save the original composition before replacing a parameter's control source.