Feasibility of doing 40000 raycasts onto a 100000 face, animated and skinned mesh

I have been tasked to replicate an effect made in a non-realtime tool. The effect has been achived by setting up 200x200 rays and casting it onto an animated mesh, then placing sprites at the first hit point.

I know about BVH, but because the mesh is animated, the BVH needs to be maintained as well.

I am looking for ideas that I might have missed. I think I will have to come up with another solution that can run in parallell on the GPU, and maybe change the scope of the task.

Thankful for any insight you may have. :slight_smile:

You might check out https://github.com/gkjohnson/three-mesh-bvh, maybe it can handle your numbers.

In this example the mesh is animated.

Thank you!

I have checked out the three-mesh-bvh lib, and the example you linked. But the particular example is not skinned and I think it uses a static BVH.

In this example three-mesh-bvh - Skinned Mesh BVH they are showcasing what I need. But this can not regerate the BVH at 60 fps.

You might use depth buffer instead of so many raycasts. Here is a demo by one of the gurus:

3 Likes

This is a great idea! Thanks a lot for the tip. Could potentially work!

For any kind of close-to-realtime bvh generation for a complex mesh like this you’re probably going to want to generate it on the GPU and then maybe raycast on the GPU, as well.

This generation isn’t supported by the project, yet, but WebGPU compute shaders could enable it. I’m open to anyone who might be interested in submitting a contribution to support it - I can provide any guidance needed.

2 Likes

Why not just render it?

For a little more information, those 200x200 casts is in this project lined up in an orthographic grid. This means I was able to do a 200x200 pixel depth map from an Orthographic camera from which I then could use the depth value per pixel in the vertex shader to read the depth value.

It looks like this depth map may be able to fulful the requirements to meet the required outcome.

Thank you again for this hint.

1 Like