question

Arlon Swaders avatar image
Arlon Swaders asked ·

Operators and namespaces

Hi,

Currently I'm trying to find a way to have dynamic shader assignment. For instance, during production the lookdev on an asset is created in one maya file. The artist uses operators to do the assignment of the shaders. The shaders and operators are published. In the lighting scene the asset and it's shaders are pulled in under a namespace. However, because of the namespace, the operators will not be able to resolve the reference to the shaders anymore.

For the selections I've found a way to fix this by referencing a collection with the namespace in the selection. However, it seems it's not possible to use collections in an assignment string. Therefore this still remains unsolved.

Does someone have any suggestions?

Thanks in advance

shadersoperator
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Arlon Swaders avatar image
Arlon Swaders answered ·

Hi Stephen,

Thanks for the answer.

Currently, the operators and shaders are created by a lookdev artist in a separate maya scene.

It this scene the operator might look like this:

selection: #namespace and *car_body*
assignment: shader = 'car_body_shader'

(#namespace is referring to a collection operator, containing a namespace selection)


Next, the shaders and operators are published. In the lighting scene these operators and shaders are pulled in under a namespace. However, due to the namespace, the name of the shader would now look something like: car_001:car_body_shader

Therefore, Arnold will not be able to resolve the reference to the shaders anymore.

I was wondering if there is a way to overcome this problem in a dynamic manner.

Thanks in advance

10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Arlon Swaders avatar image
Arlon Swaders answered ·

Hi Orn,

First of all thanks for the elaborate answer! My apologies for the late responds. I've been occupied with other tasks and didn't have time to get back to this one.

The latest solution I implemented to resolve the namespace is adding a special tag during lookdev publish and replacing this tag with the correct namespace when building the light scene.

For example:

assignment "shader = '@namespace@car_body_shader'"

Looking at the options you suggested. The second and third seem the most efficient to me. Adding a namespace to the shapes during the shot build process seems like a potential option. Additionally, the MaterialX option is something I'd like to explore.

However, I was wondering if it would be possible to implement referencing the collection name from an aiCollection node in the input? This already works in the selection of the aiSetParameter and thus I assume the input is already being evaluated by the node. This way we could achieve something like this:

collection {
 name aiCollection1
 selection "car1:*"
 collection "namespace"
 declare prefix constant STRING
 prefix "car1"
}
set_parameter {
 name aiSetParameter1
 inputs "aiCollection1"
 selection "#namespace and *car_body*"
 assignment 2 1 STRING
  "string full_name = #namespace.prefix + 'car_body_shader'"
  "shader = full_name"

Would this be at all possible. If yes, would this be suitable for a bug fix?

Thanks in advance

10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Orn Gunnarsson avatar image
Orn Gunnarsson answered ·

@Arlon Swaders

We have plans to provide means to turn native Arnold shading networks and assignments to a .mtlx file which would be used by all our plug-ins. The first implementation of this is in all likelihood going to be available in the very near future.

10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Arlon Swaders avatar image
Arlon Swaders answered ·

@Orn Gunnarsson

In your previous post you mentioned MaterialX as an alternative. I've become extremely interested in going with MaterialX now and am currently looking into writing a exporter for native Maya (and later Houdini) shaders to MaterialX. Is your team already working on something similar? I would be grateful for tips or direction on this.

Thanks in advance

10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Orn Gunnarsson avatar image
Orn Gunnarsson answered ·
Hi Arlon

As you probably know, the assignment expressions can use references and operators (e.g. +) to build dynamic expressions such as the following fictitious example

assignment "radius += geo_scale * (random_factor + 0.1)^2 - regulariser[1]"

Given the current workflow you have I have 3 suggestions for a workaround which I'm hoping could be workable for you, albeit only 1 is doable with the current version of Arnold, whereas the latter 2 would need a bug fix on our side (more on that below).

String-like types such as strings, enums and nodes such as shaders typically use string literal values, but the quotes are omitted then the value is interpreted as a reference. By default the reference is picked up from the selected (cooked) location, so if the shape 'car_001:car_body' conveniently had a custom string parameter ref_shader with the name of the shader, then you could have an assignment to dynamically pick that up, i.e.

assignment "shader = ref_shader"

Alternatively, the reference can come from another node (perhaps a dummy storage node) using the # in a similar way to how collections are referenced, e.g.

assignment "shader = #some_node.ref_shader"
assignment "shader = #some_node.ref_shaders[0]"
assignment "shader = #some_node.some_array[1].ref_shader"


1) The reason I mention this relates to the first suggestion, where if you are able to build it into the workflow to use references instead of literal assignments (perhaps on a dummy node), then the references in the lighting scene could differ and the assignment will dynamically pick up the namespaced name. Admittedly this might be a bit cumbersome unless you wrap it in a nice UI for the look-dev artists.

2) Perhaps an easier way would be use a references to a namespace in similar way to the selection expressions, where you'd have one assignment to build the full name and a second assignment to assign the shader to the concatenated name, e.g.

assignment 2 1 STRING 
 "string full_name = namespace + 'car_body_shader'" 
 "shader = full_name"

Here, the namespace in the look-dev scene would be empty, but the lighting shot build process would add the namespace on the shapes so the assignment would dynamically reference the correct namespace for each shape being selected and build the full name.

This brings me to the bug fix, as at the moment strings can't be concatenated in the same way other types can. This is a simple bug fix on our side though.

3) The final suggestion is along the same lines as the second one, but it's a bit cleaner as only one shader assignment expression is needed. However, it's a more involved change which may or may not be suitable in a bug fix release.

assignment "shader = namespace + 'car_body_shader'"


Appendix

On a side note, you may be interested in looking at MaterialX as we already have an operator that can assign look-dev by performing material/property/visibility assignments dynamically. At the moment we only support the consumption of MaterialX so you'd have to build the MaterialX documents from the Maya scene yourselves. We can discuss this further if that's of any interest.

10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Stephen Blair avatar image
Stephen Blair answered ·

No, I don't see a way to dynamically figure out the value for an assignment expression.

10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Stephen Blair avatar image
Stephen Blair answered ·

Do you have a simple example of your setup?

I tried importing an mb file that had some shaders, and I was able to assign those shaders like this

shader = "my_test_scene:aiUtility1"
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Welcome to the Arnold Answers community.

This is the place for Arnold renderer users everywhere to ask and answer rendering questions, and share knowledge about using Arnold, Arnold plugins, workflows and developing tools with Arnold.

If you are a new user to Arnold Answers, please first check out our FAQ and User Guide for more information.

When posting questions, please be sure to select the appropriate Space for your Arnold plugin and include the plugin version you are using.

Please include images, scene and log files whenever possible as this helps the community answer your questions.

Instructions for generating full verbosity log files are available for MtoA, MaxtoA, C4DtoA, HtoA, KtoA, and Kick.

If you are looking for Arnold Documentation and Support please visit the Arnold Support site.

To try Arnold please visit the Arnold Trial page.

Bottom No panel present for this section.