Jump to: Board index » General » Fusion

Syntax of expressions

Learn about 3D compositing, animation, broadcast design and VFX workflows.
  • Author
  • Message
Offline

d3zd3z

  • Posts: 47
  • Joined: Wed Jan 24, 2018 6:45 pm
  • Real Name: David Brown

Syntax of expressions

PostWed Feb 06, 2019 12:46 am

I would like to animate the r, g, and b values of the color of a background node with an expression based on time.

I selected "modify with", and chose "expression", and got a large block under the Modifiers tab. I can put simple expressions in the "Number Out" field "sin(time*20)/2+.5", but I haven't been able to figure out what language these expressions are supposed to be in.

One part of the manual suggests I should be able to use "iff(expr, a, b)" for a conditional, another suggests "if(expr, a, b)", and my experience is that neither of these works. If anything is wrong, I just get 0 out of the expression, and a very uninteresting black.

The words "and" and "or" cause this error behavior, and I was able to get "&&" and "||" to work for and and or, but I wasn't able to get an if/else type conditional to work with this.

Is there somewhere I'm missing where these are documented.

What I'm trying to do is have a pulsing pattern during some frame ranges, and during others have it held to a constant. I'd rather do this with an expression so that the parameters can easily be changed (pulse rate, how long it is on for, etc).

Thanks,
David
MacOS/Linux, Divinci Resolve 16, Fusion 16.
Offline

Okke Verbart

  • Posts: 290
  • Joined: Tue Jan 17, 2017 8:40 pm

Re: Syntax of expressions

PostWed Feb 06, 2019 6:12 am

Hi David - the syntax of the expressions is pretty much LUA based, but as you've noticed there are some weird things. Indeed, in most nodes "iif" works, whereas for others (like in the pCustom, in for instance the particles tab) "if" is required. Also, I noticed that in some places things like if(a=b,c,d) work, whereas you would expect this to error (i.e. you would expect "==").

In your case, if you put a modify with expression on say the red channel, doesn't the expression below work?

Code: Select all
if(time>10 && time<20,1,0)


For me this works, so the background turns red between frames 10 & 20.

Example composition:

Code: Select all
{
   Tools = ordered() {
      Background1 = Background {
         CtrlWZoom = false,
         Inputs = {
            Width = Input { Value = 1920, },
            Height = Input { Value = 1080, },
            ["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
            TopLeftRed = Input {
               SourceOp = "Expression1",
               Source = "NumberResult",
            },
         },
         ViewInfo = OperatorInfo { Pos = { 165, 181.5 } },
      },
      Expression1 = Expression {
         CtrlWZoom = false,
         Inputs = {
            NumberExpression = Input { Value = "if(time>10 && time<20,1,0)", },
         },
      }
   },
   ActiveTool = "Background1"
}
www.ablackbirdcalledsue.com
Offline

Okke Verbart

  • Posts: 290
  • Joined: Tue Jan 17, 2017 8:40 pm

Re: Syntax of expressions

PostWed Feb 06, 2019 6:14 am

or for some pulsing between frames 10 & 80:

Code: Select all
if(time>10 && time<80,sin(time*20),0)
www.ablackbirdcalledsue.com
Offline

Cesar Tejada

  • Posts: 135
  • Joined: Wed Mar 04, 2020 1:13 pm
  • Real Name: Cesar Augusto Tejada

Re: Syntax of expressions

PostMon Aug 29, 2022 7:22 pm

Okke Verbart wrote:Hi David - the syntax of the expressions is pretty much LUA based, but as you've noticed there are some weird things. Indeed, in most nodes "iif" works, whereas for others (like in the pCustom, in for instance the particles tab) "if" is required. Also, I noticed that in some places things like if(a=b,c,d) work, whereas you would expect this to error (i.e. you would expect "==").


This kind of thing is very confusing for new users trying to learn expressions.

I was using an Expression Modifier using this Syntax: iif(n1==0,0,1) and I expend like an Hour trying to know why isn't working like the expression field for each control.
Microsoft Windows 10 Pro

Processor: Intel i7-13700K 16 Cores
GPU: NVIDIA GeForce RTX 4070
Memory: Corsair DDR5 64GB
MB: ASUS TUF GAMING Z790-PLUS WIFI
Offline

theyaoster

  • Posts: 8
  • Joined: Mon Apr 20, 2020 12:07 am
  • Real Name: Brian Yao

Re: Syntax of expressions

PostMon Sep 19, 2022 4:50 am

whereas for others (like in the pCustom, in for instance the particles tab) "if" is required

Wow thank you for noting this - I couldn't find this documented anywhere in the reference manual (though, the SimpleExpression documentation in the manual is barebones to the max). No wonder my pCustom expressions were doing nothing. :)

But I'm curious now, is this a bug, or is there some other known reason the syntax is different for certain nodes?
Offline

UserNoah

  • Posts: 458
  • Joined: Fri Oct 04, 2019 3:32 pm
  • Location: Germany
  • Real Name: Noah Hähnel

Re: Syntax of expressions

PostMon Sep 19, 2022 8:27 am

The reason why iif() exists is because if() doesn't return a value.

I wrote about this some time ago https://noahhaehnel.com/blog/fusion-sim ... iif_not_if

But I also had to learn it the hard way lol

Return to Fusion

Who is online

Users browsing this forum: No registered users and 34 guests