question

J Frey avatar image
J Frey asked ·

How do I feed an object ID value into a shader?

Hi everybody! I am using Maya 2018 and Arnold. I'm looking for a way to feed the objectID value (the integer NOT the RGB value from the ai Utility) to an ai switch node.

Essentially I'm trying to set up a shader that I can put on to different objects that will change color according to object ID but keep all the other attributes the same. However, I need the color values to be specific not random like what results from using the objectID mode of the aiUtility shader. I should also mention I have a set override that applies the same object ID to each group of objects I want to have a different color. I have set up the colors I need using aiUserDataColor nodes hooked into an ai Switch node. I just need the actual object ID integer to link to the switch node's index attribute to switch between the colors.

Any help would be appreciated. Thanks in advance!

mtoaarnold object properties
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.

Tim Harding avatar image
Tim Harding answered ·

I didn't know you could override the object ID that way. Regardless, I feel like an easier way about this would be to use integer user data on the objects to identify them. You can learn about that workflow here: https://docs.arnoldrenderer.com/display/A5AFMUG/Ai+User+Data+Float+Tutorial

What is the case for this aiSwitch workflow over just assigning materials by hand?

Share
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.

J Frey avatar image
J Frey answered ·

Thanks for your response!

Your link definitely describes a working solution. The issue is I am working with literally hundreds of objects so adding an attr to each one is a bit prohibitive (without writing a script). It also makes it harder to add objects later.

So here's what I did:

1. Added a custom override attribute to the aiUserOptions node on the set itself (as opposed to the individual objects as described in your link) and also set it to a value (in this case 1). This was done by writing in:

declare colorID constant FLOAT colorID 1

into the aiUserOptions text field (I set the value for colorID to different values for each set so they will have different colors)

2. Created an aiUserDataFloat node and in the "attribute" field put "colorID" (same as instructed on your link only i used "colorID" instead of "Float")

3. Hooked up the output of the aiUserDataFloat node to the "index" attribute of the switch mode and it works like a charm!

Thanks so much for your help! Your link definitely unlocked the problem.

(BTW, the reason why I want to do this is I am doing some look dev and I want to be able to change one attribute and have all the objects be affected in the render instead of having to change all the shaders individually (since the only attribute that is unique will be base color). I didn't want to use a texture because I didn't want to mess with UVs and I still wanted to be able to adjust the colors by hand within Maya. More than that, I'm really trying to familiarize myself with some of these Arnold Utility nodes as well. Thanks again.)

Share
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.