Jump to: Board index » General » Fusion

"Expressions" in Davinci Resolve

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

sridharar

  • Posts: 123
  • Joined: Thu Aug 13, 2020 2:56 am
  • Location: Nashua, New Hampshire
  • Real Name: Sri Raghavan

"Expressions" in Davinci Resolve

PostTue Aug 18, 2020 1:14 pm

Let me know the right place to post this - as I think it is not just related to Fusion.

Question: Is there a way to use the supported scripting language LUA or Python, for writing Expressions? with more streamlined syntax and full power?

Any pointers? I have searched quite a bit so far and not found any pointers to this topic.

See more elaboration below...

Thanks Sri.


Expressions are great mechanism to "specify/express" values for parameters algorithmically where ever possible -- the central crux of programming and automation. KeyFrames - are simpler mechanisms that are needed where things are discrete and not amenable to algorithmic expressions.

Whatever I have seen so far, expressions allow a small text entry field and expects a single line "Expression" - which becomes more and more dense, unreadable, error prone and editable.

Ideally we should be able to write a function in LUA or Python or Javascript that returns a value that becomes the value of the parameter.

For example, say for the zoom parameter of a Node,

a nice way to write would be:

{
# comments go here
#

x = time* 3
z= sin(x)

# time, sin are available built-in functions
# various contextual information, like objects and properties can also be accessed and used

return x

}

instead of

=sin(time*3)

which get quickly out of hand as the expression becomes complicated, dense and limiting in what can be expressed.

You get the idea.
https://www.youtube.com/channel/UCeXBbc4qNkdbNPywhopu1iA
Offline
User avatar

TheBloke

  • Posts: 1905
  • Joined: Sat Nov 02, 2019 11:49 pm
  • Location: UK
  • Real Name: Tom Jobbins

Re: "Expressions" in Davinci Resolve

PostTue Aug 18, 2020 1:20 pm

In Fusion expression fields you can prefix the line with a colon : and then write Lua. The code you enter is executed as a function, and so the value you want to return to the control should be returned with a return statement.

For example:
Code: Select all
: x = math.random(0,100) ; return x
You can also write standalone scripts with optional user interfaces, and Fuses which are user-created tools and modifiers. Fuses and expressions support Lua only. Scripts support both Lua and Python.

Also, all Fusion nodes, and the entire Fusion composition, are created from Lua code. Copy any node in Fusion and paste it into text editor and you will see it is created entirely out of Lua code. This allows hand-editing of individual nodes or entire compositions. This is especially useful for editing advanced macros.

For some documentation, Google for the Fusion 8 Scripting Guide (yes, they've not updated it since then), and for "VFXPedia". Also the We Suck Less forum will have many examples, and is the best place to ask and discuss more advanced Fusion concepts. We Suck Less also hosts Reactor, the Fusion and Resolve package manager, which includes many great community-created scripts, macros, Fuses, compositions and more.

Standalone scripting also applies to Resolve, where scripts can be written in Lua and Python. However there's no expressions in Resolve (except in the Text+ effect, but that's actually a Fusion effect just made available direct on the Edit page)
Resolve Studio 17.4.3 and Fusion Studio 17.4.3 on macOS 11.6.1

Hackintosh:: X299, Intel i9-10980XE, 128GB DDR4, AMD 6900XT 16GB
Monitors: 1 x 3840x2160 & 3 x 1920x1200
Disk: 2TB NVMe + 4TB RAID0 NVMe; NAS: 36TB RAID6
BMD Speed Editor
Offline

sridharar

  • Posts: 123
  • Joined: Thu Aug 13, 2020 2:56 am
  • Location: Nashua, New Hampshire
  • Real Name: Sri Raghavan

Re: "Expressions" in Davinci Resolve

PostTue Aug 18, 2020 1:28 pm

Tom

my wholehearted thanks for the quick reply with this very exciting detail.

Is Python also supported for this?

Syntactically is it possible to open a notepad kind of editor - rather than the peephole style data entry field?

br Sri.
https://www.youtube.com/channel/UCeXBbc4qNkdbNPywhopu1iA
Offline
User avatar

iddos-l

  • Posts: 799
  • Joined: Sat Mar 30, 2019 7:55 pm
  • Real Name: iddo lahman

Re: "Expressions" in Davinci Resolve

PostTue Aug 18, 2020 2:01 pm

sridharar wrote:Tom

my wholehearted thanks for the quick reply with this very exciting detail.

Is Python also supported for this?

Syntactically is it possible to open a notepad kind of editor - rather than the peephole style data entry field?

br Sri.

As far as I know, only lua works with expression.
I usually write it on my editor and copy paste it in.


Sent from my iPhone using Tapatalk
Offline

sridharar

  • Posts: 123
  • Joined: Thu Aug 13, 2020 2:56 am
  • Location: Nashua, New Hampshire
  • Real Name: Sri Raghavan

Re: "Expressions" in Davinci Resolve

PostTue Aug 18, 2020 2:07 pm

Tom I just read your fill response more carefully about LUA being at the root of Fusion. I will be totally new to LUA -- yet another language, not an issue. Just as I was on the verge of keeping my working set to Python and Visual/C#!!

I was also thinking about Python. Given that it is indentation obsessed, may pose more issues for peephole entry of expressions.

Anyway look forward to your insightful shares.

br Sri.
https://www.youtube.com/channel/UCeXBbc4qNkdbNPywhopu1iA
Offline
User avatar

TheBloke

  • Posts: 1905
  • Joined: Sat Nov 02, 2019 11:49 pm
  • Location: UK
  • Real Name: Tom Jobbins

Re: "Expressions" in Davinci Resolve

PostTue Aug 18, 2020 2:41 pm

sridharar wrote:Syntactically is it possible to open a notepad kind of editor - rather than the peephole style data entry field?
In addition to the standard Expression field, there's one other option: Right-click on the control and choose Modify With.. Expression.

This adds a new Modifier, which includes some number and point controls which can be referenced in the expression, which can be useful for setting expression parameters. It also provides a slightly larger expression field - three lines instead of one:
Image

However for some reason this is not capable of doing Lua expressions. A colon at the start of the line does not work in an Expression modifier.

There's quite a lot of inconsistencies like that in Fusion. It's a shame, because not only does the Expression Modifier provide the number controls and a larger text input field, that text field also has some colour syntax highlighting.
Resolve Studio 17.4.3 and Fusion Studio 17.4.3 on macOS 11.6.1

Hackintosh:: X299, Intel i9-10980XE, 128GB DDR4, AMD 6900XT 16GB
Monitors: 1 x 3840x2160 & 3 x 1920x1200
Disk: 2TB NVMe + 4TB RAID0 NVMe; NAS: 36TB RAID6
BMD Speed Editor
Offline

sridharar

  • Posts: 123
  • Joined: Thu Aug 13, 2020 2:56 am
  • Location: Nashua, New Hampshire
  • Real Name: Sri Raghavan

Re: "Expressions" in Davinci Resolve

PostTue Aug 18, 2020 3:10 pm

Iddos-1 thanks for confirming that Python cannot be used in Expressions. Hopefully developers are reading these and include these enhancements in their plans.

Tom: Thanks for the additional pathways for algorithmic expressions. Also happy to read your observations about inconsistencies and blind spots in the system. I had the same hunch, rooted in my career heritage, but I am just ramping and still quite ignorant about the product features and exercising them.

Often developers and companies focus on High Buzz Features and neglect the simple disciplined things that can greatly enhance User productivity, delight and creativity, without everything becoming formidably "idiomatic".

Thank you for these exchanges.

br Sri.
https://www.youtube.com/channel/UCeXBbc4qNkdbNPywhopu1iA
Offline
User avatar

Bryan Ray

  • Posts: 2491
  • Joined: Mon Nov 28, 2016 5:32 am
  • Location: Los Angeles, CA, USA

Re: "Expressions" in Davinci Resolve

PostTue Aug 18, 2020 11:45 pm

You can also get more flexibility, and easier formatting, by using the Frame Render Script field. You have to address the inputs you want to modify explicitly instead of getting the implicit return of an expression field, but it does allow for even more complex behavior than the colon-led one-liners of a Simple Expression.

I believe you can even write Python in the Frame Render script, although you have to wrap it in a Lua command to do so. See the Fusion 8 Scripting Guide for details on cross-language scripting.
Bryan Ray
http://www.bryanray.name
http://www.sidefx.com
Offline

sridharar

  • Posts: 123
  • Joined: Thu Aug 13, 2020 2:56 am
  • Location: Nashua, New Hampshire
  • Real Name: Sri Raghavan

Re: "Expressions" in Davinci Resolve

PostWed Aug 19, 2020 2:43 pm

Thanks Bryan for bringing more options into the view. You have said a lot here which requires experimentation and internalization. Yes reading the Scripting Guide is the thing to do, and I have better general context to relate to and follow the guide. br Sri.
https://www.youtube.com/channel/UCeXBbc4qNkdbNPywhopu1iA
Offline
User avatar

AnthonyReno

  • Posts: 170
  • Joined: Mon May 23, 2022 9:58 am
  • Location: USA
  • Real Name: Mark Reno

Re: "Expressions" in Davinci Resolve

PostFri Nov 04, 2022 5:28 am

Something like this may come in useful for creating expressions.
https://another-davinci-resolve-blog.blogspot.com/2022/10/expression-builder-plugin-v20.html
DR & F Studio v18.1.1,Win11Pro, i9-13900K, 128GB RAM
GPUs:Intel UHD 770 & RTX 3090ti
OS:1.8TB SSD,P&C drives:2x2TB SSD
Speed Editor, Pen:Huion Inspiroy Dial 2 & XPPen Artist 13.3 Pro, Elecom HUGE Trackball

Return to Fusion

Who is online

Users browsing this forum: No registered users and 35 guests