Can you make my popgrains roll in the right direction?

   3168   7   0
User Avatar
Member
12 posts
Joined: Jan. 2017
Offline
Okay so I have a setup I am prototyping and will put more detailed object into later. But essentially it is a popgrain setup conformed to a surface. I wanted to add some "rolling" to the popgrains so it adds a layer of realism to the physics without resorting to bullet physics since I am guessing but not sure, the sheer amount of particles and geometry would crash a RBD simulation. Someone directed me to a page that had the following VEX code to simulate the rolling effect...

v@axis = cross(normalize(@v), {0,1,0});
vector4 newq = quaternion(@axis*-length(@v)*1.5);
@orient = qmultiply(newq, @orient);

The problem I am facing is that they tend to roll in the wrong direction and don't seem to be rolling right. I've included my hip file if anyone wants to check it out and tinker around and tell me what I did wrong.
Edited by neutrosophic - March 27, 2022 04:15:21

Attachments:
littlegems.hip (670.4 KB)

User Avatar
Member
1803 posts
Joined: May 2006
Offline
Couple of things here.

The example from the wiki assumes for rolling on the groundplane, meaning it assumes 'up' is 'the y axis', ie {0,1,0}. The cross product takes those 2 vectors to derive the axis of rotation.

In your case, the particles aren't rolling on the groundplane, but over a 3d shape. As such, the 'up' really needs to be the nearest @N from your source shape. Luckily you've already done the hard work to sample the closest @P, so you just need to copy it and change a little to get @N:

@N = primuv(1,'N',pr,uv);

But then you run into the problem I mention in the article, the motion still looks a little jittery. The @v that comes directly from the pop grain sim is glitchy. I had a hunch that if you blew it away and used a point velocity sop (a fancy version of the trail sop), it might make nicer @v, and lo, it does!

That means that the rolling has to run after that recalc, so I use a solver sop to do that.

Also, the hip is much faster to playback if you enable 'pack and instance' on the copytopoints, but breaks the colours. Handy to know this to ensure the movement feels right, can turn it off if you want to back to your original colours.

Attached my changes...

Cheers,

-matt

Attachments:
littlegems_me.hip (715.1 KB)

http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
12 posts
Joined: Jan. 2017
Offline
Ah dude. If I made the cake you put the icing on top it looks amazing. Just out of curiosity though. The VEX code for the rolling behaviour is in the wrangle in the popnet as well as the new solver node you added inside a wrangle there too. Do I need both for the behaviour to function properly or can I get rid of the code inside the popnet? And when you say it breaks the color, You aren't wrong. I am trying my best to get any kind of art directed colour in the sim. Do you have any suggestions for that?
User Avatar
Member
1803 posts
Joined: May 2006
Offline
Best way to find out is give it a go. But, yes, you can remove the orient code from the popnet.

Re colours, its a quirk of packed shapes and how they display in the viewport. If they have colour defined before packing, the viewport will stubbornly stick with that, even though it should inherit point colour.

If you just bypass all the colour nodes in your shape library, it should work as expected.

Attachments:
packed_colour.PNG (572.5 KB)

http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
12 posts
Joined: Jan. 2017
Offline
Ahh that is super useful to know and thank you again. I only have one last question before I consider this project ready for render! Well I guess it's two questions.

In my Attribute Adjust Color node, Instead of using a sexy gradient I have changed that to "Specific Values" to define a set of around 6 colors. My question is can I reference those colors which have names like "Color 0" "Color 1" etc and use them to either reference or define specific and different materials for the final render? I would love to be able to render the materials based on those colors instead of adding material nodes to the objects.

Last question. In my hip file the geometry was really "sharp" in the sense that there was no polygon smoothing or "Phong angle" on my geometry. In your file there seems to be some geometry smoothing going on. Now since I did want to add that along the way, instead of being content but still ignorant knowing that it is done but not knowing how it was done. For the sake of future projects could you tell me how that was done?

Again thanks for all your help. It literally took my project from noob status to dang that looks sexy status.
User Avatar
Member
1803 posts
Joined: May 2006
Offline
The normals in my hip are again a byproduct of packing. You want to be explicit and throw in a normal sop before the assemble, and dial the threshold for sharp/smooth to whatever you need.

Materials were trickier. I've done a hacky way here, I suspect there's a cleaner method. This gets a bit vexy, I've explained as best I could.

A material sop adds a @shop_materialpath attribute, but you can do this yourself in vex if you want complete control. I put 4 materials in /obj/mat/mat1, /obj/mat/mat2, /obj/mat/mat3, /obj/mat/mat4. If I set in a wrangle @shop_materialpath='/obj/mat/mat1', then that will be assigned.

But here, I want to broadly match the colour assignment you're using in the adjust colour sop. It's too tricky to do this after the assignment, but because your pop colour is a grayscale ramp, easier to do this before the adjust.

So we assume for a 0 to 1 colour ramp, and we want to assign the 4 materials within that range. If we store the material paths in an array, use a chramp to remap that 0 to 1 colour range to 0 to 4, then we can refer to the array elements from that index. The wrangle looks like this:

string mats[] = {'mat1','mat2','mat3','mat4'};
s@shop_materialpath = '/obj/mat/'+mats[int(chramp('mapping',@Cd.r))];

@shop_materialpath needs to be an attribute at the primitive level, and by default a copytopoints won't copy any attribute to primitives. As such I added an entry to the 'attribute from target' multiparm on the copytopoints, set it to primitive, and pointed it to shop_materialpath.

I tweaked a few settings on the materials, so some are rough, some are sharp, some are transparent, you can see them doing stuff in the viewport.

Attachments:
littlegems_me2.hip (1.0 MB)

http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
12 posts
Joined: Jan. 2017
Offline
Hey look I need to thank you again. It has been amazing learning from you. I spent at least 15 to 20 minutes looking at your file reading what you said and trying to make it work on my file and after some tinkering checking everything then realising my file cache was keeping everything from kicking in I finally got it to work. It looks absolutely amazing. And it's all because of your help with those little details I wanted to add to get it looking how I felt it would look cool.

So consider this case solved. I will thank not only the houdini community but you in particular once the render is all done and up on my instagram which looking at these render times will be some time next month hahah. I really can't thank you enough. It's like having a chemistry book and you are learning to read the book one word at a time before you can do any experiments. I KNOW Houdini can do the things I want it to do but the secrets lie in the experience and knowledge of people like yourself that can bring ideas into reality.

I am so happy VEX is making more sense to me too also. I really hated code and even defining a variable or using a fit expression was a confusing experience but now I sorta get all the code I have used in this project. You are really awesome for taking the time to help the noobs like me I really appreciate it.
User Avatar
Member
1803 posts
Joined: May 2006
Offline
Cool, make sure you post a link here when you're done!
http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
  • Quick Links