shapes disappearing when I zoom out

I’m drawing an icosahedron made out of triangles, and when I zoom out it disappears. First thing first, I’m pretty sure this is NOT about the far clipping plane. I’m using glm::infinitePerspective , and when i zoom out I’m just increasing the field of view (to a maximum of 45 deg). I’m just guessing, but I suspect that since I’m using perspective and the object is so “far” away, it’s considered too small to be worth rendering.

What I’d like is for it to always be visible, even if it’s just as a pixel. A minimum perspective size, basically. Switching from perspective to orthographic projection might work, but I’d really prefer to avoid that. I was able to kind of achieve the effect by drawing a GL_POINT at the same location as the shape. The point is always visible, so it works as a placeholder when zoomed out. However, has I zoom in the point remains overlaid on top of the shape, which is distracting. I could only draw the points when the shape is not being rendered, but I’ve got no idea how to tell when that would be.

So is this possible?

The first thing is to understand why your shape disappears.

Is it getting smaller than a pixel? If none of the triangles happen to overlap the point at the center of the pixel, then nothing will be drawn (NOTE: I’m assuming you don’t have MSAA enabled).

A few things you might try: try a normal perspective projection where you “know” the far clip is 2X further than the distance from the eye to the object and the near plane is close. Also, if you’re depth testing, are you clearing the depth buffer at the beginning of rendering every frame?

I tried using a normal perspective, with far plane, but it doesn’t seem to make a difference. I am clearing the depth buffer every frame.

It seems like it is getting smaller than a pixel. I tried drawing a bunch these shapes at the same depth, but scattered around. If I zoom to a certain amount, I can get it so that some are visible and others not. That would make sense based on your description. Some of them just happened to overlap the middle of their pixels. I’m not using MSAA. Had to look up what it meant :slight_smile:

Ok, good. Now you know for sure what’s going on. You’ve got a number of options. You can dynamically determine when your object is going to be smaller than the pixel by determining how wide a bounding sphere around your object would be in screen space. Then you can dynamically increase the size of the object to prevent it from getting smaller than a pixel or change to some “iconic” representation like a point.

Do you mind telling me how to convert to screenspace? I’m guessing it’s something like this:

  1. projection * view * model * point, for all the points in the object
  2. That is giving me some large numbers, which I’m thinking should be scaled to (-1,1). But what should I use for that scaling? The field of view width and height at the depth of the objects?
  3. After those results are normalized, I find the width of the object by scaling again ugins the pixel dimensions of the window.

Am i at least on the right track here?

Step 1.5: Divide X, Y and Z by W to convert from homogeneous coordinates to Euclidean coordinates. That should give you normalised device coordinates (NDC) in the range -1 to +1. Then, X and Y are converted to window coordinates using the viewport transformation set by by glViewport(), Z is converted to depth according to glDepthRange() (the initial state is equivalent to glDepthRange(0,1)).