Jump to content

Assing ids to objects for shading


haggi

Recommended Posts

Hi,

I like to add some ids to my objects in the scene. I'd like to assign the Ids to some instances, not to the geometry itself. e.g. I have 100 trees, all instances of the same geometry. But the trees on the left side should get an integer id value of 1 and thel ones on the right side should receive id 2.

From renderman I know the usage of user variables that can be evaluated in a shader. Or I can define a color to a rib block and this color will be used if the geometry has no color defined itself. Is something like this possible in houdini with mantra?

Link to comment
Share on other sites

renderstate("object:id", id)

returns unique integer per instance. So either you use it like that as a mask output, or (compositors friendly) use it as a sid for a random function (actually stratified random does better work), to generate hue component for hsv color (then hsv->rgb).

Edited by SYmek
Link to comment
Share on other sites

Thats great, thanks.

But this method would give me a different id for every instance. What I need is a way to assign my own id to the object instances and use this value in the shader. Is this possible? And how can I assign such a value to my instances?

Link to comment
Share on other sites

Create you attribute in the sop level with attribute create, and then in the shader use a parameter with the same attribute name to bring it in.

Cd is a good example of this going from sops to shader on a regular basis. You can open up the constant shader in houdini and see how this works.

Then you can use if blocks and switches to define what it is you to do your object if the value exist.

Edit: Need to check on instances, missed that line. I guess the better question is do you want this controls at object level? If that is the case you can have two delayed load objects and the if condition in the instance object parameter of which one to choose based on location, or the defining values you want.

Edit2: I can't get a file of it working from a sop level attribute on instancing, but the object level switching based on an if statement will work.

Here is the local help card if you need more, online help is down for me now.

http://localhost:48626/copy/varying

Edited by LaidlawFX
Link to comment
Share on other sites

Great infos, thanks.

I use an exporter from maya to ifd files for a mantra rendering. So I could do it in my exporter.

But if I imagine to have quite large geometry and define it twice is not a optimal solution.

I think a better way would be to define the variable in my shader as mentioned above and give it the correct value for every instance in my exporter. This would be similiar to the way you can do it with instances and the instancepoint() function.

Edited by haggi
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...