1
votes

I am an absolute beginner in three.js (today first day of exploration) and I am confused about the role of the 'near' and 'far' parameters that are passed to the perspective camera.

The reason why I am asking is because I don't really understand why these parameters are useful at all. The only thing that really seems to matter is the fov angle in combination with the aspect ratio, which would implicitly seem to define the viewbox (frustum), albeit not necessarily the depth of the frustum. Wouldn't it be more logical that near and far parameters (the depth) are automatically generated based on the objects that we want to render, rather than having to set them explicitly?
Reason I'm asking is because it would seem that when an object is placed behind the 'far' parameter of the perspective camera (object's z-axis), it just drops off (which I'm having a hard time comprehending why that makes sense. You wouldn't want to let an object drop off on the z-axis, simply because you made a mistake in setting the 'far' parameter not far enough. Since you set the far parameter yourself at some constant value at the beginning of your script, it seems kind of buggy.

So my question is, based on what criteria do you really determine what the near and far parameters should be (rather than just some random values, which all tutorials / books seem to do)? This may be a rather dumb question, as it seems obvious from all material I've read that these parameters are inherently supposed to be understood as I cannot seem to find an explanation for it. (Probably I'll often be here with a myriad of these sort of dumb questions, lol).

1

1 Answers

1
votes

How "busy" is your scene? Far will control what will/wont be culled during rendering. The more things you render the longer it takes. This applies to all the camera settings. The more you can see, the more you render.

You say

You wouldn't want to let an object drop off on the z-axis, simply because you made a mistake in setting the 'far' parameter not far enough

And I say that you would want it to drop off because the other, closer objects are more important and you dont want to waste time on the further away ones. If you change scene and decide, "this scene is more sparse, I can afford a higher far distance" then increase it at that point.

Its not that these values are arbitrary, its more that they are tuned whenever you decide how fast/slow you are willing to run. If you're targeting 4K 60 FPS, you may need to decrease your FOV and far distance. If you just want 720 30 FPS, you might be able to render everything in your scene.

Tutorials can't decide these settings for you because they don't know what you will be rendering or what hardware you will be rendering on.

One other thing is that your measurement units might be very different from some other implementation. One persons near far of 0.1/1000 is anothers 1/10,000,000.

For example, I think Unreal has its average character height at 156 "units". That number probably seems really random, but was probably tuned to place nicely with a lot of floating point shenanigans. If you are just starting, you probably threw a cube in your OpenGL scene and just set it to 1x1x1 dimensions. That cube sitting near you will no dought fit in your cameras view range at 0.1/100 but that Unreal character won't fit.