worldToScreen function misbehaving

I’m trying to implement a portal ( like this:
Step 1: the white area will be the portal. Find its on-screen co-ordinates.

Step 2: Take the view from the portal (“blue”) camera

Step 3: Using the on-screen co-ordinates from step 1, a cropped version of the “blue” camera’s output is rendered into the white area.

It all seems to work, BUT breaks down when the camera is fairly close to the render area and the render area is only partially visible. See the animation below, as the viewer turns the render area suddenly jumps.


Investigation shows that the worldToScreen function is returning incorrect values. Even for a small change in position there is a disproportionate change in the screen co-ordinates:


-21146095.956585325,     11261290.89697315,
-21146095.956585333,    -10686079.648416352,
      235.775456045,         1072.028363128,
      235.775456045,          -78.914197592

After a small change, the right-most co-ordinates change sign

3635260.91483109,    -1934543.5226093638,
3635260.91483109,     1836833.4723431966,
        235.3796,        1072.2389787654,
        235.3796,         -79.1153285465

but I have no idea why.

I’ve put up a much simplified project at
The call of interest (worldToScreen) is in the follow-world-target.js module.
Move the character controller along the x-axis, the threshold value is x: 6.261 - 6.262

Hi @CarlBateman,

Sharing this issue in case it’s related: Camera worldToScreen wrong results with fixed resolution · Issue #5274 · playcanvas/engine · GitHub

Well, paint me blue and call me an inter-continental ballistic missile.
worldToScreen is working correctly!
The error is related my shader code as per my earlier post (
But I still have no clue why. :frowning:

1 Like