Jump to content

Assign random texture from folder ( htoa ) to each primitive


Recommended Posts

Hi there,

I hope somebody can help me I have read so many threads and tried so many things and I can't seem to get it right.

If i have a very simple setup, like a grid on a copy to points, being copied to another grid. so say there's 9 grids with 1 face each.

How do I tell the arnold shader to assign a different texture at random from a folder to each prim ?
For example say I want to texture the windows of a building. and i have drawn 10 images of people lounging around with different layouts. and I want to randomly assign those image textures to however many primitives I have in the windows group etc.

Any help would be much appreciated.


Link to comment
Share on other sites

Arnold can use special tags in parameters to reference attributes, so what you first need to do is create that attribute.

If you want to do this in VEX without getting Python involved, you just have to name your textures sequentially (tex1.tif, tex2.tif, tex3.tif, etc.) and put them in one folder.

Then in a primitive wrangle, you can generate a random integer between 1 and the number of textures you have, and construct a path string, like this:

int num_tex = ch("texture_count"); // the number of textures you have
float rand = fit01(rand(@ptnum), 1, int(num_tex));
int randint = int(rint(rand)); // round and cast random value as integer
s@texpath = sprintf("/path/to/textures/tex%g.tif", randint);

Once you have that attribute created,  in place of a texture path in your material network you can use the tag <attr:tex default:/some/default/tex> and Arnold will read this tex attribute at rendertime.

  • Like 2
Link to comment
Share on other sites

Thanks so much for taking the time to reply.

I had not heard of the tags thing before that's very cool. I just can't get it to render. It hangs like when the path to an image or hdri isn't working.

Thanks so much for the vex snippet that worked perfectly and I understand what's happening there. and I can see that my 6 test images have been correctly assigned at random to each prim in the geo spreadsheet.

I have all images in the $HIP folder and also brought in a "fail.png" to use as the default for the tag.

I think I just don't fully understand the tag and how it works.
would it not be "<attr:texpath:" instead of "attr:tex:" since that's the attrib name ? Definitely something I'm not understanding there. but either way I try it doesn't work.
Then for the default do I put the file extension to the default image there at the end ?
Also do I still include the $HIP/ before the tag and the extension after like
$HIP/<attr:tex default:/$HIP/fail.png>.tga
or just the tag like
<attr:tex default:/$HIP/fail.png>

I'm definitely messing something up with the paths because if I tick ignore missing texture errors on the "image" node it renders ( though obviously with no image ).



Link to comment
Share on other sites

Thanks for the reply.

This all makes sense to me. Yet Arnold still just hangs on render with the tag. as soon as i remove it everything is fine. I think I will put this aside for now and maybe ask support at Arnold because I'm pretty sure I get it now, and something is wrong.

I would ask what is the Python route as I'm starting to learn it after a year of vex ( my first language ). But just trying to find tutorials for python 3 in houdini is pretty difficult.
But I appreciate your time and effort so won't bug you much further :) .

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.

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...