Usage of scene contex variables

815 views
Skip to first unread message

Jiri Siska

unread,
Oct 1, 2016, 10:02:26 AM10/1/16
to gaffer-dev
Hi everyone,

Does anyone has a sample scene of scene context variables setup in gaffer? I'm trying to create similar setup to katana graph variables but Im struggling with way it is done and used in gaffer.
I would like to create a "variable switch" evaluating different branch based on variable value set further down the nodegraph.

Thank you!

Jiri

john haddon

unread,
Oct 3, 2016, 9:17:19 AM10/3/16
to gaffer-dev
Hi Jiri,
I'm attaching a very simple setup where a variable is used to control the shading applied to a model. Key things to note :

- Variables are created by the SceneContextVariables nodes. In this case I've created a variable called "renderPass", setting it to "red" on one branch and "green" on another.
- Variables flow upstream, while data (the scene) flows downstream.
- Variables are automatically substituted in upstream string plugs. You can see this in the Outputs node, where I'm using "${renderPass}" to include the render pass in the file name.
- Variables can be accessed from python expressions as `context.get( variableName, defaultValue )`. You can see this in the Expression node, where I'm using the variable to choose what colour to make the shader parameter.
- If you execute the TaskList at the bottom, you should get two renders done, one red, one green.

Hopefully that gives you a starting point for the setup you want to create. The key things to remember are that variables flow upstream, and you can use substitutions and expressions on upstream nodes to use the variables however you want.

Cheers...
John
sceneContextVariables.gfr

Jiri Siska

unread,
Oct 5, 2016, 7:24:45 AM10/5/16
to gaffer-dev
Hi John,

Thanks a lot for your explanation and sample file! It is exactly the setup I was looking for. Gaffer's concept of variables sounds very similar to way it is designed in Katana as well.

Best,
Jiri

john haddon

unread,
Oct 5, 2016, 7:46:05 AM10/5/16
to gaffer-dev
Hi Jiri,

No worries, glad it's working for you.

You might find it useful to know that context variables are at the very core of Gaffer, and that there are several "built in" variables. For instance you can get the current frame from an expression with `context["frame"]` and  the current object being computed with `context["scene:path"]`.

It's also often very useful to use a Wedge node to modify a variable over a range. This lets you launch multiple renders (or any other dispatch) without needing a branch in your node graph for each one. I've attached a simple example using a Wedge to sample a range of colours from a spline, doing one render for each colour sampled. You can also place Wedges one after another to generate permutations over multiple variables, as in the example below :

https://cloud.githubusercontent.com/assets/1133871/8594915/9fb46272-263d-11e5-8d90-05508ff9310b.png

Cheers...
John
wedge.gfr

Steve Molin

unread,
Oct 23, 2017, 4:52:22 PM10/23/17
to gaffer-dev
Hi John, brand new to Gaffer and trying to understand how I can change context variables from the command line. I grabbed this script and I try to run it like this:

    gaffer execute -script sceneContextVariables.gfr -nodes AppleseedRender -context SceneContextVariables.renderPass '"green'"

Hoping to change the render from red to green via this context variable; but I get the same red render in projects/default/renders/sceneContextVariables/red/beauty/beauty.0001.exr

Maybe I'm missing something fundamental. Obviously this is a silly example, the idea is just to be able to alter the render process at runtime from the CLI.

Thanks in advance!

Steve Molin

unread,
Oct 23, 2017, 7:01:58 PM10/23/17
to gaffer-dev
Answering my own question: need to drop the namespace, so something like this seems to work:

    gaffer execute -script my.gfr -context renderPass '"green'"

Back to work now ....

Thanks for your attention.

John Haddon

unread,
Oct 24, 2017, 5:25:39 AM10/24/17
to gaffe...@googlegroups.com
Hi Steve,

Glad you got it figured out.

Just to clarify things further, the `-context` command line arguments are entirely separate from any SceneContextVariables nodes that might be in the node graph (hence why you needed to drop the node name). The command line arguments set up the starting context at the node being rendered, and this flows upstream where it may be further modified by SceneContextVariables nodes...

Cheers...
John

--
You received this message because you are subscribed to the Google Groups "gaffer-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gaffer-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
John Haddon - R&D Programmer
Image Engine
studio: +1 (604) 874-5634 | jo...@image-engine.com | www.image-engine.com



15 West 5th Avenue, Vancouver, BC, V5Y 1H4, Canada

If you are not the intended recipient, disclosure, copying, distribution and use of this email is prohibited. Please notify us immediately and delete this email from your systems. You may contact us at in...@image-engine.com if you do not wish to receive further commercial electronic messages. We may still send you messages for which we do not require consent.

Reply all
Reply to author
Forward
0 new messages