{"id":903,"date":"2019-01-30T10:46:12","date_gmt":"2019-01-30T10:46:12","guid":{"rendered":"https:\/\/howiem.org\/wordpress\/?p=903"},"modified":"2019-01-30T10:46:12","modified_gmt":"2019-01-30T10:46:12","slug":"houdini-redshift-varying-disk-based-instance-materials","status":"publish","type":"post","link":"https:\/\/howiem.org\/wordpress\/2019\/01\/30\/houdini-redshift-varying-disk-based-instance-materials\/","title":{"rendered":"Houdini \/ Redshift: Varying disk-based instance materials"},"content":{"rendered":"<p>Thought I&#8217;d better try writing this up as it took me bloody ages to get my head round it.<\/p>\n<p>Situation: you have an object that you want lots of instances of, all with different looks. Say, one tree object, but you want lots of instances with variations in their colouring.<\/p>\n<p>The approach differs depending on whether your tree object is in the scene file somewhere (ie instanced using s@instance=&#8221;\/obj\/my_tree&#8221;) or if it&#8217;s a file on disk (s@instancefile=&#8221;$HIP\/geo_trees\/my_tree.rs&#8221;).<\/p>\n<h5>Instancing a scene object<\/h5>\n<p>You can use either point attributes or stylesheets to poke new values into the material parameters: see\u00a0<a href=\"https:\/\/docs.redshift3d.com\/pages\/viewpage.action?pageId=12419786&amp;product=houdini\">https:\/\/docs.redshift3d.com\/pages\/viewpage.action?pageId=12419786&amp;product=houdini<\/a> for guidance.<\/p>\n<h5>Instancing a proxy file from disk<\/h5>\n<p>This is slightly more tricky: you <strong>must<\/strong> use stylesheets, and you can only poke new values into parameters that are exposed at the material&#8217;s top level VOP node. I&#8217;ve created a hip file to illustrate:<\/p>\n<p>Download:\u00a0<a href=\"https:\/\/howiem.org\/wordpress\/wp-content\/uploads\/2019\/01\/RS-per-instance-colours_001.hiplc_.zip\">RS per-instance colours_001.hiplc<\/a><\/p>\n<p>To test it, just make sure you &#8220;render&#8221; the Proxy ROP first, to create an .rs proxy file for the scene to use. It&#8217;ll create an RS proxy containing this single plane with some nasty coouring:<\/p>\n<p><a href=\"https:\/\/howiem.org\/wordpress\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-30-at-10.10.28.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-910\" src=\"https:\/\/howiem.org\/wordpress\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-30-at-10.10.28.png\" alt=\"\" width=\"423\" height=\"230\" \/><\/a><\/p>\n<p>Then you can go to Render view and render an image.<\/p>\n<p>You should see this lurid mess:<\/p>\n<p><a href=\"https:\/\/howiem.org\/wordpress\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-30-at-10.14.11.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-906\" src=\"https:\/\/howiem.org\/wordpress\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-30-at-10.14.11.png\" alt=\"\" width=\"573\" height=\"314\" \/><\/a><\/p>\n<p>But that means everything is working. Every plane has a different hue shift going on, even though they&#8217;re all identical instances. If it wasn&#8217;t working, you&#8217;d see this:<\/p>\n<p><a href=\"https:\/\/howiem.org\/wordpress\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-30-at-10.13.34.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-907\" src=\"https:\/\/howiem.org\/wordpress\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-30-at-10.13.34.png\" alt=\"\" width=\"487\" height=\"286\" \/><\/a><\/p>\n<p>This is how it works: to vary the material, I&#8217;ve stuck an RS Color Correct node in the material, and an RS Multiply node to multiply an\u00a0incoming 0-1.0 value by 360 (turns out the hue shift parameter on a colour correct node wants a value in degrees, which caught me out for a while):<\/p>\n<p><a href=\"https:\/\/howiem.org\/wordpress\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-30-at-10.17.51.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-905\" src=\"https:\/\/howiem.org\/wordpress\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-30-at-10.17.51.png\" alt=\"\" width=\"536\" height=\"290\" \/><\/a><br \/>\nand exposed the Hue Shift parameter\u2014promoted it to the top level VOP\u2014so it now appears as a parameter on the material itself:<\/p>\n<p><a href=\"https:\/\/howiem.org\/wordpress\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-30-at-10.11.07.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-909\" src=\"https:\/\/howiem.org\/wordpress\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-30-at-10.11.07.png\" alt=\"\" width=\"325\" height=\"569\" \/><\/a><\/p>\n<p>That parameter name is important\u2014hue, in this case\u2014as that&#8217;s the thing we can bind and alter on an instance-by-instance basis using a stylesheet override.<\/p>\n<p>So\u2014into the stylesheets: to get to them, open a Data Tree pane, and choose &#8220;Material Style Sheets&#8221; from the dropdown. I&#8217;ve added a Style Sheet Parameter, and a Style, a target (&#8220;Point Instances&#8221;) and two overrides:<\/p>\n<p><a href=\"https:\/\/howiem.org\/wordpress\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-30-at-10.19.07.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-904\" src=\"https:\/\/howiem.org\/wordpress\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-30-at-10.19.07.png\" alt=\"\" width=\"1050\" height=\"320\" \/><\/a><\/p>\n<p>The first override sets the material to the one that&#8217;s in the scene (as opposed to any that may be saved in the proxy file itself). You can only override materials present in your scene, not ones within the proxy (as far as I can tell).<\/p>\n<p>The second override is an &#8220;Override Script&#8221; &#8211; even though it&#8217;s not really a script: you can choose &#8220;Material Parameter&#8221; and &#8220;Attribute Binding&#8221; from the dropdowns. The Override Name is the parameter that&#8217;s exposed on the material\u2014&#8221;hue&#8221;\u2014and the Override Value is the point attribute you want to bind it to. In this case, my Instance object has a bunch of points to instance to, each with an @hue_shift attribute.<\/p>\n<p>And that&#8217;s it. No reason to only use this for shifting hues: you could create a\u00a0material with a shader switch, or a texture, and as long as you expose the switch parameter or the texture filename string in the top VOP level of the material, you can poke new values in at render time like this.<\/p>\n<p><strong>One caveat\/limitation:<\/strong> Redshift is blazingly fast at rendering loads of instances. But if you try tweaking 1000s of instance&#8217;s\u00a0materials like this, you may find that the pre-render processing, as Redshift builds the scene, could become quite time-consuming. I&#8217;m guessing that behind the scenes Redshift is creating a new shader for each tweaked material. So for huge scenes with loads of instances, you may need to take a different approach to adding variety. Stay tuned.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Thought I&#8217;d better try writing this up as it took me bloody ages to get my head round it. Situation: you have an object that you want lots of instances&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-903","post","type-post","status-publish","format-standard","category-houdini-tips"],"_links":{"self":[{"href":"https:\/\/howiem.org\/wordpress\/wp-json\/wp\/v2\/posts\/903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/howiem.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/howiem.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/howiem.org\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/howiem.org\/wordpress\/wp-json\/wp\/v2\/comments?post=903"}],"version-history":[{"count":0,"href":"https:\/\/howiem.org\/wordpress\/wp-json\/wp\/v2\/posts\/903\/revisions"}],"wp:attachment":[{"href":"https:\/\/howiem.org\/wordpress\/wp-json\/wp\/v2\/media?parent=903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/howiem.org\/wordpress\/wp-json\/wp\/v2\/categories?post=903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/howiem.org\/wordpress\/wp-json\/wp\/v2\/tags?post=903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}