Instancing: Import point attribute into shader

   2576   5   2
User Avatar
Member
8 posts
Joined: Feb. 2020
Offline
Hey there,

I'm instancing a bunch of objects with the instance node and would like to access point attributes (like pscale) in my material network to drive the color of my instanced objects. I tried to use the bind node but couldn't get it to work. Am I doing anything wrong there or should I use a different approach?

Cheers,
Philipp
User Avatar
Member
30 posts
Joined: April 2019
Offline
One way is to reference the pscale attribute in the ‘basecolor’ parameter using the point() function. It's important to use ‘instancepoint()’ for point number.

Attachments:
INSTANCE_MATERIAL.png (416.2 KB)
INSTANCES.hipnc (532.4 KB)

User Avatar
Member
8 posts
Joined: Feb. 2020
Offline
Hey Reuben,

Thanks a lot for your answer and the attached scene file! It works like a charm, when used on the material node directly, but it doesn't seem to work, when I have a bunch of nodes feeding into the material (like a color mixer). Is there a way to make that work too? Specifically I would like my attribute to drive the bias on that color mixer, but apparently it's not picked up there.
User Avatar
Member
30 posts
Joined: April 2019
Offline
I see what you mean. My knowledge in this area is relatively small, so, hopefully, someone with a better understanding than I can help. Cheers.
User Avatar
Member
359 posts
Joined: April 2017
Offline
You might have better luck with this using stylesheets. They're a little awkward to use, but they'll allow you to be a little more specific about your shader overrides when using object instancing.

First you need to set up your material so that anything you want to vary is given a Parameter VOP that's then connected to something in your material network. For example, if you want to control the bias of a Mix VOP, either promote the “bias” parameter or create a Parameter VOP, name it anything (let's just use “bias”) and make sure the signature is set to Float.

Next, you need to go to the Data Tree window (New Pane Tab Type > Inspectors > Data Tree) to get the Material Style Sheets view. From there, you can create a new stylesheet on your Instance object. Right-click the stylesheet in the Data View and select “Add Style” if there isn't one by default. Then right-click the Style that's generated and add three things:
  • a Target (set type to Point Instances)
  • an Override (set type to Set Material, and the Override Value to your shader)
  • an Override Script (set type to Material Parameter, set Override Type to Attribute Binding, set Override Value to whatever attribute you want to drive the bias… in your case it's pscale)

This will bind your pscale value directly to the bias of your Mix VOP, per-instance. Stylesheets also have the advantage of being compatible with some third-party render engines, whereas the old school `instancepoint()` expression is not compatible with anything but Mantra.

Attaching a scene file for reference.

Attachments:
styling_instances_toadstorm.hiplc (744.5 KB)

MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
User Avatar
Member
8 posts
Joined: Feb. 2020
Offline
That's brilliant! You saved the day, again, Henry!

Your scene file really helped me wrap my head around it.

Funnily enough I was trying to get it to work with Style Sheets too, because I'm using them in another part of the project, but I think I understand, now, why it didn't work.
I was hooking the parameter up with my Principled Shader directly and hoped it would propagate somehow to the nodes feeding into the shader. But, sure enough, the Principled Shader doesn't have a parameter called ‘bias’ in its interface definition and so the Style Sheet couldn't do anything. By wrapping the whole thing in a Material Builder, I'm able to expose ‘bias’ to the outside world and that allows the Style Sheet to drive it.

Thanks again!
  • Quick Links