Vat animation speed change

repro: Babylon.js Playground

I’m trying to change the animation speed for vat on my instanced mesh. It works for the first cycle but subsequent cycles show increasing visual disparities. Also console throws error msges where the instance buffer is missing for a single frame?

Something is wrong but I’m not sure where/which, can someone point me in the right direction?

I think you are cumulating all your registerFunction :slight_smile:
You need to call unregisterBeforeRender to remove the previous one or they will all happen simultaneously

Like that:
vat animation speed testing | Babylon.js Playground

1 Like

erm, still seeing the same visual issue even with unregister. Not sure what you are seeing on your end. You have to let it run for 10+s. See attached video.

The story at the beginning: I’m trying to change animation speeds smoothly. Initially, I was just using vec.set(vec.x,vec.y,vec.z,40); and vec.set(vec.x,vec.y,vec.z,32); on the buffer which should be 40 fps to 32 fps and so on and forth. But I kept seeing visual glitches, the animation wasn’t smoothly changing between the values, like so. Thought the step change might be too much of a jump, so I switched to a callback to ramp the values gradually. It works! for the 1st cycle only tho. It seems like the act of setting the buffers is causing problems. Setting it every frame and setting it once are both causing visual issues? hmm…

edit: made a repro that doesn’t depend on registering/deregistering callbacks. Same issue, seems like I can’t write to the vertex buffer every frame for vat… :frowning: Need to dig deeper… :pick:

hey @phaselock you sure the vec.w thing is doing what it is supposed to do?

Because if I look at this:

It doesn’t really start/stop at the same frames each time, does it?

1 Like

I’ve created a PG whichi visualizes the current frame of the VAT animation with a bar so you can easily observe how the current frame changes. I copied out the shader code to JS so we can easily debug why do we have an issue here:

The problem here is with the manager.time value and how it affects the current frame.
The shader calculates the value like this:
float time = bakedVertexAnimationTime * VATSpeed / totalFrames;
The bigger the time the faster is the animation.

I think a solution would be not to set the speed but the current animation frame directly so we could have complete control over how the animation.

This one changes the time smoothly and it does what is supposed to do. But it affects all instances.

I believe @Tricotou or @mawa could come up with a solution quite quickly with tweaking the code according to vec.w which is the animation speed factor. Just do the correct math :wink: I have to work today so I am off, sry :wink:

EDIT: @labris as well :wink:

2 Likes

Woah, thanks for all the help! I have a solution, not 100% sure its correct but it looks good to me right now. To summarize, yh, you can’t just change anim speed for vat w/o recomputing new offset (which imo is unintuitive, shrugs…). The problem is to take the current animation frame at curr anim speed and compute new offset at new anim speed w/o restarting the whole animation cycle.

my solution so far: https://playground.babylonjs.com/#1ZA2DA#1

Its not perfect, due to Math.floor, I think. So there’s always a worse case 1 frame difference when switching speeds. The 3fps is deliberate to make it easier to visualize. You can set highfps at, say 5fps to chk the maths is correct.

Thanks to @Joe_Kerr , @roland! The greased line helped!

Gonna have to do more testing, I really would like to get rid of the 1 frame discrepancy but not sure how…so not marking as solved yet. Cheers!

3 Likes

Yup. That’s what I figured when innocent me wanted to quickly fix your PG in 2 sec :sweat_smile: :face_with_hand_over_mouth: yesterday after @roland pinged me (probably just to bother me of course :joy:) But I had some important things to do like continuing my gaming session of Xcom 2 WOTC (which I reinstalled because of @Joe_Kerr 's project giving me the desire to assess once again which is the best turned-base tactical RPG?! :grin: :joystick: :rofl:

I had two things that had me leave this request before the 5min counter. First is I don’t know why the first animation frame starts at 7? … And then the second, is indeed, since you are not using the regular animation that runs at 60FPS… probably would need to make your own ‘currentFrame’ ? :thinking:

2 Likes

I’m getting there… :star_struck:

2 Likes

1 Like

I’ve got to say it: I love this community:) I was about to check what was going on and boom problem already solved!!!

1 Like