Is it possible to set intersection ordering?

I have a camera and some layer of meshes:

Then I wanna make a fake cone from camera and hide elements that’s first intersected with cone (by the path from the camera):

And the second one to hide first intersected meshed with it:

What is the best way to do this? As I realized the ray-casting to every mesh is expensive by performance. And native intersection algorithm will affect all meshes, but not first from the camera.

Ray casting seems to be logical solution.
I believe, you may try also to use occlusion queries with some custom logic.
Here is a lot of info about it - How to Occlusion Culling properly

So it probably would be like this:

  1. Find meshes that intersected with the cone.
  2. Get ray casting from the camera to every filtered (from prev step) meshes.

This may work with first render call, but what for second, when meshes already will be hidden from previous call.

I think the PG would help a lot to sort out all things.

1 Like

Thats just a thoughts about the task, currently I have this PG
Looks like intersection checks strongly affects performance, so I probably will try approach with ray casting.

I dont want to spent your time, I just wanted to know general approaches which I can to apply. You helped with them, thank you! :slight_smile:

1 Like

Why intersection with mesh work faster then several (72) ray casting?
Loop with intersection check pass in 2-3 ms.
But ray casting take around 125 ms.

I though ray casting should be much faster.

Here I switch approaches:

  //setTimeout(() => this.rayCastingLayerCulling(), 2000);

Is it correct? Rycasting really should be more expensive?

1 raycasting should be less expensive than intersections check.
But 72 raycasts are pretty much…