Calculating screen space bounds of an object

I have been trying to calculate the bounding box of an object in screen space. I want to use this calculation in my shaders eventually but right now I’m unable to get it working.

I have been following the source code and calculation as described in the paper:
“2D Polyhedral Bounds of a Clipped, Perspective-Projected 3D Sphere” https://jcgt.org/published/0002/02/05/.

Here is the implementation replicated in a playground:

As you will see the calculations all lead to null coordinates. Ideally these should be bounding box coordinated that I can see in the screen space, I’ve added a post process to check the values.

Other references I’ve followed:

I maybe using the apis incorrectly, so any pointers would be really helpful.

1 Like

Thanks a lot for the pointers!

I was able to get a cpu version working: https://playground.babylonjs.com/#H6NHBZ#11

Also trying my hand at a glsl version but looks like something is incorrect:

I’m going to try and debug this but let me know if you spot an obvious error.

1 Like

Hello and welcome :slight_smile:

In this topic I had given this Playground which computes ratio of the mesh seen in the camera (projecting vertices and computing 2D bounding box). If it can help…

++
Tricotou

1 Like

Thanks that’s exactly what i was looking for!

1 Like