+ HOUDINI MATERIAL STYLESHEETS

Houdini material stylesheets

The example scene exists of a geo with a box, copy to points via a grid. The copy to points is set to “Pack and Instance”. We have three materials called red, green & blue.

  • Add a data tree pane tab

  • Choose a viewer: Material Style Sheets

  • Select the geo (in the data tree) that you wish to add the style sheet to and RMB click -> Add Style Sheet Parameter. This will add a tab in the properties panel of the geo node called Shaders. In this tab we find a JSON representation of the data in the data tree.

  • RMB click the newly created style sheet parameter -> Add Style and name it “red”.

  • RMB click the newly created style (named “red”) -> Add Target. Since we wish to add an override to the packed primitives we select “primitives” from the type combobox. (we could go deeper inside the packed primitive and add overrides to polygons or other parts depending on contents of the geo)

  • RMB click the newly created style (named “red”) -> Add Override. The default is “Material Parameter” that means that we can various parms of a material. Since we wish to set material we select that from the combobox.

  • in the Override Value (you might have to scroll right) we set the path to the material we want to use.

  • if we want to add control of which parts that gets the material we can add a condition. RMB click the Target -> Add Condition There is also an option to “Select Target From Vieport Selection”. This is esentially adding a condition node setting the type to “Primitíve Group” and adding the selected prim nums.

Condition Examples

Primitive Group

So lets say that we wants to use an primitive attribute called “col” to choose which material that gets applied. In the geo after the copy to points lets add a primitive wrangle and the following snippet. This will create a prim attr called col from 0 - (max_num-1)

int max_num = chi('max_num');
int col = int(rand(@primnum)*max_num);
i@col = col;

to use this attribute we need to add a condition, set it to “Primitive Group” and enter the following value: @col==0. We do the samr for the remaining conditions and use @col==1 and @col==2

The JSON representation of what we just did:

{
        "styles":[
                {
                        "label":"red",
                        "target":{
                                "label":"Target",
                                "group":"@col==0"
                        },
                        "overrides":{
                                "material":{
                                        "name":{
                                                "type":"string",
                                                "value":"`opfullpath('../../mat/red')`"
                                        }
                                }
                        }
                },
                {
                        "label":"blue",
                        "target":{
                                "label":"Target",
                                "group":"@col==1"
                        },
                        "overrides":{
                                "material":{
                                        "name":{
                                                "type":"string",
                                                "value":"`opfullpath('../../mat/blue')`"
                                        }
                                }
                        }
                },
                {
                        "label":"green",
                        "target":{
                                "label":"Target",
                                "group":"@col==2"
                        },
                        "overrides":{
                                "material":{
                                        "name":{
                                                "type":"string",
                                                "value":"`opfullpath('../../mat/green')`"
                                        }
                                }
                        }
                }
        ]
}

Primitive name or path Attribute

Another way is to use a prim attr called name. add a prim wrangle:

string names[] = {'red', 'green', 'blue'};
int index = int(floor(rand(@primnum*chi('seed'))*len(names)));
s@name = names[index] ;

To make this work set the condition type to “Primitive name or path Attribute” and then we set the value to “red”, “green” and blue.

{
        "styles":[
                {
                        "label":"red",
                        "target":{
                                "label":"Target",
                                "name":"red"
                        },
                        "overrides":{
                                "material":{
                                        "name":{
                                                "type":"string",
                                                "value":"`opfullpath('../../mat/red')`"
                                        }
                                }
                        }
                },
                {
                        "label":"blue",
                        "target":{
                                "label":"Target",
                                "name":"blue"
                        },
                        "overrides":{
                                "material":{
                                        "name":{
                                                "type":"string",
                                                "value":"`opfullpath('../../mat/blue')`"
                                        }
                                }
                        }
                },
                {
                        "label":"green",
                        "target":{
                                "label":"Target",
                                "name":"green"
                        },
                        "overrides":{
                                "material":{
                                        "name":{
                                                "type":"string",
                                                "value":"`opfullpath('../../mat/green')`"
                                        }
                                }
                        }
                }
        ]
}