- Home /
Framerate Dependent Mesh Deformation
I am attempting to synchronize a mesh deformation with the current frame rate of the scene. The deformation I had in mind is pretty much the same as the Crumple Mesh Modifier on this page
http://unity3d.com/support/resources/example-projects/procedural-examples.html
I need a program that will cycle the deformation once in the same amount of time as it took to complete the current frame.
if the frame took .2s to complete than i need the deformation cycle to last for .2s if the frame took .5s to complete than i need it to last for .5s etc...
i don't have much experience with programing but it seems that the time.deltatime function would return an integer value which is just what I'm looking for, namely the frequency of the deformation. Except that function gives the time needed to complete the PREVIOUS frame not the current frame.
What i suspect needs to be done is to process the frame but delay it from being sent to the screen long enough for the deformation function to receive its needed frequency information, namely how long it took to complete the frame. Then they can perform their functions in tandem; the frame will display to the screen and the mesh will perform a single deformation cycle. Hopefully the delay would be minimal so as not to cause too much lag as the project this will be applied to is designed for small multiplayer applications.
The final effect should be similar to a stop motion animation in that every frame the object will have deformed once. Since the deformation is random it will look like "deformed snapshots" of the object layered on top of each other. I don't want to see the movement only the final image of the object, after deformation, displayed every frame.
This seems like it may be one of those theoretically "simple" problems that turn out to be quite complex in application.
Any help or suggestions on accomplishing this task would be much appreciated.
Answer by Noise crime · Jul 15, 2010 at 05:58 AM
Just use time.deltatime no one is going to notice its the time for the last frame, unless your frames are varying wildly in the time they need, in which case you've got bigger problems than getting deformation to work.
Though at 200ms (0.2s) per frame the effect will still be very fast. I would have thought you'd want to make the delay in updates longer than that if you want to really see the effect.
However its hard to really know what you are trying to do, as you have a kind of paradox
I need a program that will cycle the deformation once in the same amount of time as it took to complete the current frame.
If you haven't done the deformation then the frame cannot be complete, you need to render the frame to know how long it took, but by that point you can't perform the deformation for that frame because the frame is already complete. This is why you'll need to just use the previous deltatime. That is assuming of course this is really what you want to do.
You talk about wildly differing framerates such as 0.2 to 0.5 seconds, but if that was the case your game would be unplayable. It sounds more like you want to control the frequency of the update to the deform code, which really has nothing to do with the time it took to render the frame.
Presuming the mesh deform takes time as an argument (not got round to looking at that demo), then all it should need is to add a timer to control calling the function. You can set the timer to whatever value update you want.
So if Unity is running at 60 fps and you want the stop motion effect to happen every 0.5 seconds, then what will happen is that for 30 frames unity will render the current deformed mesh, then you deform the mesh by 0.5 second value and for the next 30 frames Unity renders the new deformation and so on.
In essence you are decoupling the call to deformation from the actual framerate Unity is running at.
Interesting. I think i understand what you mean about the paradox. You seem to be hitting the nail on the head on what im going for. in fact the deformation frequency needs to be a bit faster.
To use your previous example. if the game is running at 60fps than the frequency of the deformation needs to be (1/60)s or 0.0167s. The overall effect of this would be that for every individual frame the mesh would have completed a single, small, random deformation.
Any thoughts on how this could be accomplished?
Also thank you for help i appreciate the advice
Ok well there is still some confusion in my $$anonymous$$d as to waht you are trying to achieve. At 60 fps deformation will appear to be a smooth animation, but you talk about a stop motion effect, which normally doesn't look so smooth. If you really want 60 fps and again assu$$anonymous$$g that tutorial code you found excepts time as an input you can just feed it time.deltatime
I found a really interesting SIGGRAPH paper called "Painting with Polygons"
http://www.outside-hollywood.com/siggraph/
the video shows how to achieve the look. When it is coupled with motion blur the effect is meant to mimic layered transparent brushstrokes. I wanted to test this out to see if its possible to do in Unity.
When u look at the $$anonymous$$pot is looks like a buncha layers of different deformations piled on top of each other. you dont however see the ripple effect that causes it presumably cause the framerate and the ripple are in synch.
Do you think im on the right track?