Skeleton + refraction off screen generate artifacts in water refraction texture


uncomment line 220, run the PG.
wait for the dude to load, then pivot the camera until you see the cloned dudes. You should see artifacts on the surface of the water as you pivot until the cloned dudes are in view frustrum.

In addition, if you clone the dudes within the camera frustrum, ie const zrand = 20;, no artifacts are generated in the refraction texture, irregardless of skeleton.

This took a while to find (it was showing up in seedborn savefiles). Consistent and reproducible on my hardware and browser (chrome+firefox). Its not version related, running on 4.2.1 also shows the same.

cc @Evgeni_Popov

another repro using bjs’s water material in the doc, similar issue, but this one is captured in the reflection texture.

Meshes behind the camera are culled and therefore not taken into account in the main management loop. In particular, this means that their skeletons are not updated (they don’t need to be, as they can’t be seen).

However, as you explicitly push them into the refraction/reflection texture, they will be rendered in an RTT. But since their skeletons haven’t been updated properly, you get rendering artifacts.

The simplest solution is to simply call skeleton.prepare() when you clone the skeletons :

It would be nice if the RTT noticed that some skeletons weren’t up to date when rendering a mesh, but I don’t think that’s an easy fix… So, for now, it’s the user’s responsibility to call prepare in the case.

1 Like

Awesome! Single line solution, I love it! I think your entire answer should be in the doc, I was looking at the skeleton api for ages and would never have figured out prepare was the solution. Thanks, marking as solved and closing!

I think it is not a problem if the Skeleton.clone method calls prepare on the cloned skeleton itself, so I made a PR for this:

prepare looks expensive to me, traversing all bones plus matrix calculations. Then again, if you are comfy with it, all thumbs up from me!

It’s only done a single time at the end of the clone method, so it should not be a big deal.

1 Like

ok, I will monitor. New build should be out tomorrow? I should be able to stress test with my savefile, yay!

The playground will be updated tomorrow, but I think NPM packages are generated each thursday morning…


Happy to confirm that its working in v6.16.0, the artifacts are gone! Loading is fractionally longer (for 100+ cloned skeletons, only <20 with high bone count) but not excessive. Thanks very much! :slight_smile: