mkrebser / GPUInstance

Instancing & Animation library for Unity3D
Other
228 stars 44 forks source link

Appending Position is 1 frame late? #12

Closed projectBreakableAccAPI closed 11 months ago

projectBreakableAccAPI commented 1 year ago

Hello again! I've noticed that when an instance's position is appended, it only visually applies a frame late, at least when compared with a transform. Is there a way to circumvent this? I typically wouldn't mind an issue this minor, but I'm attempting to use this instance as a player view model, making the delay quite noticeable to players when moving.

Thanks in advance, Max

projectBreakableAccAPI commented 1 year ago

I should also add that when the update is done in Update or LateUpdate I get pretty bad flickering, which doesn't happen with transforms. I'm currently using FixedUpdate to get around this, but that means that the model only updates its position at about 50 fps. So, I guess I'm really asking, "Why is it flickering?" and, "How can I update its position faster?"

projectBreakableAccAPI commented 1 year ago

Ok final update, I did some tests with delaying a transform's position, and the same flickering occurred so that means I just need to know how to update the instance a frame earlier and all of the other problems should disappear.

mkrebser commented 1 year ago

I don't believe I see this issue in any of the demos, have you tried looking at the parasitedemo

This demo calculates the positions of the bones of an entity every frame

projectBreakableAccAPI commented 1 year ago

If they don't come up in the animator it's most likely due to its inclusion in the Instance Modification pass, as it appears a lot of my issues thus far stem from the execution order. Is there a way I can make GPU Instance receive and apply instance changes immediately after the default scripts execute? Like, is there a change I can make to the Script Execution Order?

mkrebser commented 1 year ago

When you are setting the positions/animations/etc you are setting them for what will happen on the next render

You can see what the Update function is doing here: It will update all the buffers, do a simulation step, and then call unity drawindirect https://github.com/mkrebser/GPUInstance/blob/master/Assets/Resources/GPUInstance/scripts/instancemesh.cs#L1674

Here is unity execution order: https://docs.unity3d.com/460/Documentation/Manual/ExecutionOrder.html