[SOLVED] Camera far clip in Editor different from in-game

I’ve set the far camera clips to a reasonable 5000 (5 km) for the editor camera and the camera attached to a player entity.

A simple box entity will disappear anyway under that range. In the editor, it will disappear at around 3.25 km. In the game, it will disappear at around 0.8 km.

That’s a large disparity, while both are also very much under 5 km.

Is there anything I might not be doing or could be doing to get these cameras to function properly?

Edit: It did just occur to me that I could scale everything down by a factor of 10…

But I think it would still be good to know if there’s something I may not be doing correctly. For suggestions, I also think that if these short clippings are somehow built in or “necessary”,

  1. the editor camera and any game camera could at least be roughly equal in capability if they’re set equally (because why couldn’t they be equal in capability?)

  2. the fields for far camera clips should restrict quantities that wouldn’t work, or at least the tool tip should tell you the operational upper bound.

Edit 2: Everything scaled down by a factor of 10 won’t be a good workaround. Shadows are terrible at that scale.

I get this behavior myself as well, actual viewing distances are less than the far clip value set on camera.

Any ideas why this is happening? Far distance set to camera not respected.

It is quite limiting in some big world projects.

Thanks,

@bridger Can you share a simple scene that illustrates the problem? If I place a camera that has near set to 0.1 and far set to 5000, I can quite happily view a sphere of radius 0.05 at Z=0 when the camera is at Z=0.15.

Am I missing something?

Hi @will

The scene below consists of boxes on platforms, plus one platform for our viewpoint. Each box is 20 m^3, and each of their platforms is 100 m^2, and these start from the origin. Our viewpoint is on a platform 200 m directly to the right from the origin and 50 m up. We can ignore the trig we can do that accounts for our exact location; the issues here can be made sense of over an error within 200-500 m.

One series of boxes-on-platforms extends adjacently up to 1 km in front of us. The tenth box is at the end of this series. After that, one box-on-platform is placed every 0.5 km.

Three windowshots follow.

(1) From the editor, we see that the actual far clip limit is around 3.3 km. Anything beyond that disappears. I actually have box-on-platforms going out to 5 km. But we only see the farthest one at 3 km and not at 3.5 km and beyond. I placed a “threshold” box-on-platform to the right of the 3 km one. It’s at 3.3 km. At 3.4 km, it cannot be seen from this viewpoint.

Note the Editor Far Camera Clip field is set to 5000 (5 km).

(2) This second shot from the editor shows the perspective of the player at the start of the sim. We can see that its camera far clip is set to 5 km, while the editor clues us that we may not see that far in-game as the peripheries’ solid white lines turn gray.

(3) The final shot is in-game, with all the settings as they were. We’re able to see the tenth 1 km box-on-platform to the left, but not that ones at 1.5 km and beyond. I placed another threshold box-on-platform to the right. This one’s at 0.9 km and disappears if it’s placed directly backwards at 1 km (incidentally, we can see a little farther at the periphery, but this point is of no matter to the present issue.)


So these are the issues:

While it’s quite understandable that there must be limits to camera far clips for optimization purposes, either (a) the editor and camera far clip settings should have a restricted upper-bound, higher numbers than which you cannot enter, which represent the actual capacities of the editor and game cameras, or (b) let the developer deal with any problem that arises from arbitrarily far camera clips … but don’t let us enter in numbers and present us with something that goes against user-friendly expectations.

And finally, other than a probable oversight deep in the source code (which not all developers have time to learn to fix), it makes very little sense for the editor camera and game camera to have different ultimate capacities. If the editor camera lets us see out to 3.3 km, then there wouldn’t be any natural barrier to the game camera letting us see out to 3.3 km.

Best regards

I’m presuming you only notice problems if you have a skybox set up? Notice that my test scene has no skybox.

Yup I had a skybox set up, presuming it’s regularly so essential that it wouldn’t be factor…

Taking out the skybox … while it does seem to eliminate the problem in editor mode (e.g., I can still faintly see a box at 9.5 km when the editor camera far clip is set to 10 km—promising), I get the same results as before in game mode:

I still can’t reproduce this problem.

https://playcanvas.com/editor/scene/530002

I’ve created a camera like this:

And a cube like this (scaled in X and Y so I can see it from a long way away):

Due to depth buffer precision, I can actually still see it at -5010! It disappears beyond that.

All looks fine to me - same behavior in the Editor and in game. Obviously, this is a simple, minimal example. Can you provide an equivalent that clearly shows the problem?

Thanks.

Hey @will

I do get the right results if the game camera I’m using is standalone.

But I don’t have an equivalent to provide since I’m interested in a first-person camera attached to a player.

https://playcanvas.com/editor/scene/530728

This scene is like yours except the camera is attached to a player. The player first-person-movement script is an exact copy from the First Person Movement tutorial on PlayCanvas.

If we turn off the script, the camera works like yours. If the script is turned on, we get the odd limiting behavior of the camera.

So the problem seems to be with the script. I don’t know what it is though.

In the script, you are creating a new camera (which I assume is using default values) rather than using the camera that is setup in your scene.

Although you have an attribute reference to the Camera in the script, you null the reference in the init function:

// initialize code called once per entity
FirstPersonMovement.prototype.initialize = function() {
    this.force = new pc.Vec3();
    this.camera = null;
    this.eulers = new pc.Vec3();

So a new camera is created in the update function here:

// update code called every frame
FirstPersonMovement.prototype.update = function(dt) {
    // If a camera isn't assigned from the Editor, create one
    if (!this.camera) {
        this._createCamera();
    }

Remove the this.camera = null; line from the init function and you should be good to go.

I’m not sure why that line is in the first person tutorial/project sample as it doesn’t make much sense and assume it is a typo.

1 Like

@yaustar my good friend, that did it :slight_smile: