Foreach loop, file path and dependency issues

   4120   8   1
User Avatar
Member
21 posts
Joined: Nov. 2017
Offline
Hi, I'm having trouble with a sop foreach loop.
I'd like to apply a material for each piece of geometry, and that material to use a texture from file defined by the iteration number of the loop.
It works on single passes, but if I let the loop run all the way through all the pieces end up with the texture of the final iteration.
When I turn on show dependencies for each node, there is a dependency going from the material, to the matnet, and from the matnet to where the iteration number is held, and like I said it works individually for single passes.
I've had the same trouble referencing the textures from a cop2net, and found I could get it to work if instead of a for loop I used a solver, then it would update every frame.
The loop is on the merge setting, not sure if that's important.
User Avatar
Member
738 posts
Joined: Dec. 2006
Offline
You would really need to post a hipfile for help with this.
Sean Lewkiw
CG Supervisor
Machine FX - Cinesite MTL
User Avatar
Member
21 posts
Joined: Nov. 2017
Offline
Hi, thanks for replying, here's the hip

Attachments:
cells_test_08_dpendency_bug.hipnc (1.1 MB)

User Avatar
Member
738 posts
Joined: Dec. 2006
Offline
I wasn't able to figure out what you were trying to do in your file, (the displayed node was not in the foreach loop).

Here is a simple example of looping through each prim and assigning a different texture. I added a spare channel to keep track of the iteration, used the 7 butterfly pics that ship with Houdini, and used a modulus to loop through them:
1+(detail(-1,"iteration",0)%7)

I then assigned this to “basecolor_texture” to override the file path at render time.

I hope this helps.

Attachments:
loop_texture.1.hipnc (860.6 KB)

Sean Lewkiw
CG Supervisor
Machine FX - Cinesite MTL
User Avatar
Member
21 posts
Joined: Nov. 2017
Offline
Cool! Thanks for that, sorry if the hip was indecipherable.
With your hip I ended up putting the material inside the loop and using a file sop to export it with the iteration variable as part of the name, it works! It's a shame you can't see it in the viewport though.
One question, I can't see how the material picks up the base color texture name, I can only think you used a material override, but there isn't one on the material node.


PS: I tried it with a material override, and it shows in the viewport
Here's the hip

Attachments:
loop_texture1_material_override.hipnc (880.4 KB)

User Avatar
Member
21 posts
Joined: Nov. 2017
Offline
Unfortunately I still can't get the copnet to cook for every iteration of the loop.
Attached is a simple hip to show the principle.
Try running over each iteration with the single pass, it works, and then, when you do it all at once, all the textures end up the same as the final iteration.

Attachments:
copnet_with_forloop.hipnc (274.9 KB)

User Avatar
Member
738 posts
Joined: Dec. 2006
Offline
wmpcg
One question, I can't see how the material picks up the base color texture name, I can only think you used a material override, but there isn't one on the material node.

If you hover your mouse over the texture name label in the material, you will see that the parm name is “basecolor_texture”. If you have a primitive attribute of the same name, (assuming you are assigning your material to prims), the shader will use that instead of whatever you have put in the shader's interface. As you can see, this is a very powerful way to override any parm on any shader on a per-primitive basis.
Sean Lewkiw
CG Supervisor
Machine FX - Cinesite MTL
User Avatar
Member
738 posts
Joined: Dec. 2006
Offline
wmpcg
Unfortunately I still can't get the copnet to cook for every iteration of the loop.
Attached is a simple hip to show the principle.
Try running over each iteration with the single pass, it works, and then, when you do it all at once, all the textures end up the same as the final iteration.
I see a single primitive which you loop over ten times, assigning a different different color on each loop. At the end you can only have one color, the final one.

What is the effect you are trying to achieve?
Sean Lewkiw
CG Supervisor
Machine FX - Cinesite MTL
User Avatar
Member
21 posts
Joined: Nov. 2017
Offline
I was hoping to have procedural textures from the cop2net, without having to write them out to file and then re-import them. Looks like I might have to end up doing this, either with the solver I mentioned above or a wedge rop.
Strange the cop2net wasn't working for you.
Thanks for your help anyway, I've been wondering for a while how to get per primitive material overrides.
  • Quick Links