Jump to content
david_adan

Object instance - randomize instance parameters

Recommended Posts

Hello, I am having trouble randomizing parameters from instanced geometry from within an "instance" subnet. Say for example I wanted to randomize the speed of an instance's animation (on the sop "timeWarp" node), or the start frame of the instance's animation (on the sop "timeShift" node), or perhaps randomize it's material.

Please check attached file.

Thanks in advanced.

instance_randomize.hiplc

Share this post


Link to post
Share on other sites

any particular reason why you're using instance object? that's sort of old school approach to instancing that only makes sense if you use 3rd party renderer. randomizing things this way is quite limited. it's just instancing whatever is there in the source object. use loop and copy to points instead.

take a look at this video

 

Share this post


Link to post
Share on other sites

There is a companion to the s@instance attribute. It is called s@instancefile and allows you to instance form disk instead of scene memory. When you know you want to temporally alter an instanced animation try writing the animation out to disk as a sequence. In your example that would be a 96 frame .bgeo.sc sequence.

In your attribute wrangle construct a valid filename using the frame number from the sequence.

float frame_to_instance = @Frame;
s@instancefile =  sprintf("c:\my_folder\my_sequence_%03d.bgeo.sc",frame_to_instance);

This allows you to implement delays or time warping inside the wrangle itself. For instance to run at half-speed...

float frame_to_instance = @Frame*0.5;
s@instancefile =  sprintf("c:\my_folder\my_sequence_%03d.bgeo.sc",frame_to_instance);

To delay until a frame then run at quarter speed...

float frame_delay = 24;
if (@Frame > frame_delay) {
  float frame_to_instance = (@Frame-frame_delay)*0.25;
  s@instancefile =  sprintf("c:\my_folder\my_sequence_%03d.bgeo.sc",frame_to_instance);
}

 

Share this post


Link to post
Share on other sites

Thank you so much for your replies guys.

@davpe The reason I am using instance subnet is because I will render the scene in Arnold and each instance is almost 4 million polys, I was under the impresion that the instance method had the best performance but I may be wrong. Your approach seams like a very good alternative, I will give it a try.

 

@Atom Thanks for the reply, sounds also like a good approach, actually I do have a bgeo sequence for the animations, will give it a try as well. Although with this approach I am still not sure how I would randomize the materials, the thing is my animated geometry will have several material groups, will keep you guys posted.

 

Cheers.

Share this post


Link to post
Share on other sites

One simple way to handle random materials is to export a geo sequence with each possible material choice already embedded in the geometry. Then you can leverage your filename construction to automatically pick from a sequence with one of the random materials. This is practical if your geometry does not take up a lot of disk space.

int max_material_count = 3;
int rnd_index = int(fit01(rand(@ptnum),1,max_material_count));
float frame_to_instance = @Frame;
s@instancefile =  sprintf("$HIP\geo\my_geo_sequence_M%02d_%03d.bgeo.sc",rnd_index, frame_to_instance);

Basically assign your materials and kick out a sequence with each of the materials already assigned.

untitled-2.jpg

 

You can also look into style sheets if you plan on rendering with Mantra.

Edited by Atom

Share this post


Link to post
Share on other sites
5 hours ago, david_adan said:

@davpe@Atom The reason I am using instance subnet is because I will render the scene in Arnold and each instance is almost 4 million polys, I was under the impresion that the instance method had the best performance but I may be wrong. Your approach seams like a very good alternative, I will give it a try.

yeah that loop and copy method won't work with arnold as it doesn't support packed primitives.you can still use the method but you won't get instances, only copies :/ mantra is so much better in this respect.

Edited by davpe

Share this post


Link to post
Share on other sites

Again, thank you guys, for the advice.

@davpe The attribute randomization works very well with the "for each loop" method. Unfortunately, when I try to render the packed copies, the material sometimes renders fine and sometimes renders completely gray, as if there where no material assigned (renders fine with unpacked copies though), a bug maybe? Has anyone encountered the same problem?

I am using Houdini Indie 16.5.405 under Windows 10 OS.

Share this post


Link to post
Share on other sites

not sure, it works fine for me. might be the way you assign materials... hard to say. can you post a scene file?

Share this post


Link to post
Share on other sites

i looked into your file and this is gotcha everybody bums into at some point :) if you're assigning materials like you did, you have to indicate that there are materials embedded in packed prims (normally, mantra doesnt look into it to save resources - this can make a difference for large scenes). so all you have to do is to set Declare Materials option to Save All Materials. It's in Mantra ROP>Rendering>Render tab all the way at the bottom.

anyways, more up to date way to handle materials on instances is Material stylesheet which i suggest you to explore. there are several pretty good tutorials covering this on sidefx website.

Edited by davpe

Share this post


Link to post
Share on other sites

FYI. and for future reference, I decided to go with the old school instance node, rather than the copy to points approach. The later was taking much more time to refresh on viewport even with a few hundred copieas displayed as a box. The geo "instance" node could easily handle over half a million instances in the viewport. The other thing is as @davpe mentioned, packed instances are not suported by Arnold, which I need to use the final render. With the geo "instance" node I managed to render half a million instances, animated with over 3 million faces each with no problem.

I will just try to implement time randomness with the techique sugested by @Atom.

Share this post


Link to post
Share on other sites

hey, good summary :) however, i haven't found copy to points instancing to perform worse than original instance object (it is mostly a workflow difference more than anything else). it should definitely be able to handle any instancing scenario. if you see a performance hit even with hundreds of copies you are definitely doing something wrong, or you do much more data handling than with instance object.

cheers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×