Physics

jersmi's picture

Went on a search for emulating flowing fabric using quad structures and ended up (via a very interesting Jitter recipe page) at Verlet Integration, here. If I could explore this right now in QC, I would. In the meantime I thought I'd share the info and see if anyone has any thoughts.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

dust's picture
Re: Physics

//// edit

went on a rant there. great find.the paper that is. you can simply hook up a gl quad structure to my cloth simulation. see attached. i think using the mesh creator is a bit faster maybe but it works. check attachment.

//// end edit

cool we just got to the verlet method in my computer simulations class yesterday. also got introduced the runge kutta methods as well. http://en.wikipedia.org/wiki/Runge–Kutta_methods. what a cool name runge kutta, sounds like some bad ass jamacian gangster lol.

the verlet's method is accurate down to a fourth order error term. meaning the that at the 4th order it is completely accurate and doesn't accumulate errors each step. the verlet's is 3rd order differential equation that can be solved with a coupled second order euler methods.

so the interesting thing about the verlets and runge kutta style programming is that they require some steps to be completed first. now i haven't taken a physics class, but some basic things from grade school help out. at first you have force = mass * acceleration and that depends on three things functions of time, velocity and position all divided by mass.

so we should all remember from grade school the mass's cancel out each other in uniform gravity and acceleration can simply be in a linear accel = gravity. it gets a bit more complicated when you add non uniform gravity. for now lets just say on a basic level a = g; if gravity is set to negative number things fall down.

so if we understand force = mass * acceleration or mass * derivative in respects to velocity divided delta time. m*(dv/dt) you can solve this easily like Vn+1 = Vn + a * ∆t then update your position with velocity like pos += v * ∆t; you got to understand this first because the verlet's method although makes more logical since needs you to derive these initial steps.

ok remember accel can depend on three things v , t, and p. velocity time or positions. so you would need to integrate all three functions in respects to ∆t. doing this in the gpu with lets say open cl is pretty easy to understand because you can write your 4d vectors like pos += velocity * ∆t; then if you need to access a specific component you would prepend the vector like pos.x.

so back to velet's, without going into lengthy explanation as to why this is more accurate. ( because you carry out to 4th order terms) lets just say if we know the position we can get the velocity of calculating for acceleration first.

now this formula should be remembered as its the basis to the tuio mass acceleration integration and important for any iOS multi-touch application. p2-p1/2*∆t or lets say touch start pos - touch end pos divided by the time between the two times 2;

ok so with verlet's your not truncating to the first term arbitrarily [ p += v * ∆t ] you would do a taylor series expansion and bring the error out to 1/6 it would written something like this.

[p=p+v∆t+1/2p+v∆t^2+1/4p+v∆t^3+1/6p+v*∆t^4]

so its a bit more coding, i have yet to postulate if its more efficient or not but that stuff is all subjective.

the point is that you have to use euler to solve as well as do some initial calc to derive your second point. it would be like if you took the sample and hold patch and queued up the first spot where you clicked. you cant solve mass acceleration from position without having two points.

now using the verlt's like i said is accurate to the fourth order and does not accumulate error past this term. but you need to a lower order euler solve first to get a prediction based on a position in order for verlets to work. that sounds complicated but its not. the only thing is a lower order method carries an error with it.

in physics lets just say we don't know the error its unknown so we cant just subtract the error from the result each step, we need to use a euler with a big loop like carry it out to 100 steps. this way we know the error is really small and that way you can run the verlets with this small initial error. remember the velets doesn't accumulate error each step so it will only be off the unknown fraction error on the first step.

now the runge kutta is similar to the euler richardson and verlets. remember these all use euler to solve so the first thing is to learn euler. it involves probing to get a mid point. this is a style of programming so you can do many things to get your mids like using a euler predict the half step and the dividing the whole step by 2 then using both the probes in the integration.

oh man went on a rant here. you don't really need to use the verlets method unless your doing molecular stuff.

PreviewAttachmentSize
rug-cloth 3.zip43.29 KB

franz's picture
Re: Physics

nice, but it looks much more like a ripple than a pseudo-real cloth. I guess verlet WOULD be your friend in that case....

Anyway, thanks for sharing, and keep up patching, you're an amazing boiling source of QC-crazyness ! Kind regards.

(funnily, I'm also working on cloth sim. at the moment)

btw. @jersmi: coding your own Verlet integrator isn't such a burden, be it with built-in patches only (using queue) or JS ....

gtoledo3's picture
Re: Physics

There's some QC demo cloth sim stuff recorded somewhere, that was on tape from the wwdc sl qc presentation. It looks sort of like the jiggle interaction warp setup with a little feedback loop thing going on, to my memory.

dust's picture
Re: Physics

here this version is a much better cloth type effect. i added collision object and viscous drag parameters. you want to mess with the collision drag and viscous drag parameters to get a cloth type of draping effect. this one is sort of a silky cloth. you can sort of drape the cloth with your mouse as i use the mouse velocities to update the mesh.

PreviewAttachmentSize
viscous 2.zip101.04 KB

franz's picture
Re: Physics

just posted on my blog a very early test plugin that just does .... cloth sim. Too few controls at the moment.

monobrau's picture
Re: Physics

Impressive!

jersmi's picture
Re: Physics

Wow, this is good! I'll be digging in shortly.

dust's picture
Re: Physics

you can use this for particles as well. just use a vertex display or mesh creator for that. i will make a verlet's version soon. now that we are working in two body simulations it will come in handy.

jersmi's picture
Re: Physics

Franz -- your plugin is looking f'in great -- speedy and cloth-like. Exactly what I was imagining.

Feature requests:
1. Rows/columns for the grid.
2. Assign or somehow grab arbitrary or closest point in the mesh with the mouse (actually in my case a tracking point), then pull the cloth around. Possible? Maybe via mesh structure member index input or something? Please? Somehow?

Dust, thanks for this interesting approach. Curious to see your verlets method. GT, curious about the examples you mention. How can I find these?

Thanks, gentlemen, for your generosity.

dust's picture
Re: Physics

nice one franz, i see what your talking about by pinning the corner verts down. i guess i would need to re-work my cloth a bit as i'm not using any spring tension to hold the verts together just using drag. i vote for jersmi having structure input would be cool. maybe even processor type of plugin having structured output would be cool as well.

@jersmi good idea to check out the cloth dev example. i have it laying around on a beta drive somewhere. i don't remember it running on my system but lots has changed since beta SL. i'm sure now it may make more sense now as i have learned more since leopard.

jersmi's picture
Re: Physics

how can i get that dev example?

dust's picture
Re: Physics

im not sure how you would get it now. the only seed available for download is snow leopard is 10A432 which was the last beta seed. so you need the seed before that 10A4xx.

thats where i remember seeing the cloth example it was with the n-body example which you can still download. i'm using 10A432 beta as my restore disk and updating to 10J858 beta right now. i'm hoping there will be some graphics improvements and not break anything. (fingers crossed)...

an honest answer is i don't have that build laying around anymore. if GT or someone else saved it and wants to share that would be the best bet. i only have access to the current developer beta seeds. sorry, i thought i had that example on my drive but i forgot i updated my restore disk to 10A432.

actually any xcode build prior to 10A432 is a good source for developer examples. they are not included on the discs anymore. most of the stuff is online now but there are a few things that didn't make the the disc to site -> leopard to snow leopard transition.

jersmi's picture
Re: Physics

hmm, i may still have some of that stuff... thanks, dust.

gtoledo3's picture
Re: Physics

I don't think that example was ever posted. It was a mashup of alessandro's interaction example, where kevin did a cloth sim, instead of the default sprites (or billboards). I've looked back through old archives and don't see it. I really don't think that composition was ever posted.

Looking back, I can't find the film clip offhand (I've had all kinds of iTunes woes), but the ports on the actual kernel are kinda similar looking to jiggle, but I seem to remember one or two parameters that were different. There seemed to be a bit of a wild feedback reaction that got semi uncontrollable at some point. There was also some z-fighting that looked ugly.

Cloth sim is wide... I always assumed it to be dynamic, super duper real looking stuff. However, there is a whole wealth of examples that consider cloth sim to be basically akin the the GLSL Vertex Noise example, with or without texturing. That kind of seems like a stretch, until you consider that in video games, etc., you really can make something look like a waving flag, or a number of other things, just be vertex noise, or maybe some more refined vertex weighting.

I may as well toss in a a cloth sim, since franz has now as well. This uses all stock stuff. It doesn't have any kind of "auto physics", it's purely interactive in it's warp/physics reaction stuff.

PreviewAttachmentSize
cloth_sim_gt.qtz289.33 KB

jersmi's picture
Re: Physics

Quite a demo for openCL and meshes, GT.

I'd be interested to know how you feel at this point in time about stability and common sense use in a live performance scenario with these tools. Still seems a bit on the bleeding edge. Speed I see. The use of the interaction patch would require a workaround for a tracking point. How would the kinect interact with a patch like this?

gtoledo3's picture
Re: Physics

Oh, I would feel fine about it, if it was the same computer I was actually vetting the stuff on. If you're setting stuff up on one computer, and then throwing it on something majorly different, all bets are off, because you don't know if the gpu is going to respond the same.

For most stuff like an OpenCL approach, there is some kind of alternate approach that skirts around it and gets it accomplished some other way. If a computer supports OpenCL and OpenGL well, you're rockin' and getting great fps. I don't feel like there are really unpredictable OpenCL glitches like there may/may not have been in the early SL days. Stuff is consistent in working or not working on a given gpu/OS X version.

I'm kind of cracking up, because we're now at a point where even with a cloth sim, it's like "how can we get it to work with kinect!". I think I published a hand tracking interaction thing here...but I can't find the file. An easy way would be to take the take the centroid color tracker and threshold the image from the kinect to get an x/y point for the white hand. I guess you could use optical flow to derive an x/y point too, but I haven't had great results with getting a solid point that way...not that I've put much time into it.

itsthejayj's picture
Re: Physics

Just been checking out Victor Martins Kinect cloth experiments http://www.vimeo.com/18188808 .

Time to dig into this i think. Looks like the mesh noise patch would be the best starting point for work like this. Any one attempted work like this?