[Solved] FOV and Near Plane Clipping

Is there a known equation to stop clipping of objects near the side of the camera when you change FOV?

If I’m standing right next to a wall in first person and increase the FOV it will begin to clip the wall so I can see through it, and worsens as it increases in a linear fashion.

From what I’ve read to stop this you change the near plane on the camera, but by what degree? Is there a direct correlation to calculate it? I have been toying around with values but if the value is too relaxed it’s going to have a lot of side effects like shadow mapping etc.

Would somebody mind explaining how I might go about solving this in a more calculated manner?

Is it as basic as nearPlane = fov / 45 given that the default fov is 45 and the near plane is 1.0?

So i thought about this for a second and came up with this, if I understand right:

The red one is the clipping plane at 45 deg and 1.0 and the green one the adjusted one.

What I would suggest is just doing some trigonometry with the top line constant at 1/2 and the bottom angle as FOV/2, then you can get the central line’s length. I can’t be quite arsed to go look up which cos/sine/tan mult what this is tho, but should be trivial to figure out from this drawing.

It is an interesting thing to point out, I’ve never actually noticed this effect before.

Unless you got this part already figured out and I’m out of my depth.

1 Like

Oh. I don’t know why I didn’t see it in the first place. So i guess all i need to know is the length of the vertical leg, which calculates as 1.0 based on the default values. So to answer my own question…

float fov = 70; // or whatever you set it to...
float frustumNear = FastMath.tan(fov * FastMath.DEG_TO_RAD * .5f);
1 Like

When you change the FOV also change the near plane to what you want?

How are you changing the FOV? There is a method that will do this all at once.

Like in SiO2’s CameraState:

…or you can just use CameraState which allows changing the values independently but makes sure that the ones you don’t set (like near/far plane) are kept as before.

Edit: though I’m still curious how you set this and maybe it’s just that you are using angles outside of “normal”… but the near plane is generally a distance from the camera.

1 Like

The problem.




Your head.

From what I understood, he wants the camera to have a fixed world size clipping plane so it doesn’t expand sideways when the fov is increased. It’s not about it resetting on setting the fov, it’s just how the math works out.

I see what you mean.

Unfortunately, as the FOV widens, I think quite often the Zbuffer depth becomes more critical… but I guess he’ll see. :slight_smile:

I usually set my near plane really close, such that no matter how wide my FOV is (up to my determined max) nothing will clip. But I need to cover players walking face into a wall and cover that minimum distance which is usually small enough to avoid the side-ways clipping.

Sorry, time zone differences.

I set it like this:

float fov = 70;
float aspect = (float)camera.getWidth() / (float)camera.getHeight();

camera.setFrustumPerspective(fov, aspect, camera.getFrustumNear(), camera.getFrustumFar());

Though I’m not certain I’ve solved my issue, probably because I’m working from presumptions. As you say the camera does do the calculations I presented previously.

By that line of code, it is indeed setting the leg size of the distance between A and B (diagram below). This was the part I did not understand.

As the field of view expands, the screen has more of the world visible in the same space, so understandably it results in being able to see through walls I previously couldnt.

I guess what I was trying to do was increase the length of a which doesnt make sense now because that would alter the field of view. From what you are saying, or from what I now understand, the nearPlane actually sets the distance between a and b. and not the length of a

Correct. Setting it to 0.01 means your face can get 1 cm away from some surface before penetrating.

And I don’t know how wide the FOV is in your second pic or if JME even allows FOV greater than 180… but it would make the math very weird.

1 Like

Just to put an end to the thread with a solution, If I set them all at once using the setFrustumPerspective method it works as expected. If i only change the fov using the setFrustumPerspective method and then later change the nearPlane it displays the output as shown in my screenshots. So the solution is to set them all at once, and not individually.