Camera.viewport doesn't handle negative values

For me its a bit confusing that the camera.viewport is using normalized [0, 1] values instead of pixels, but I understand the intent: if you want to render into the right half of the screen, you don’t have to keep calling viewport when the window is resized.

However it seems the viewport is not handling negative coordinates well, here is a demo:
https://playground.babylonjs.com/#8HQ63V#1

I’m passing viewport.x = -0.5 and viewport.width = 1, so in sync with how the original gl.viewport command works I expect that I only see rendering appear in the left half of the canvas, but that doesn’t seem to be the case.

1 Like

our viewport is from the bottom left: https://playground.babylonjs.com/#8HQ63V#1

Thanks for the reply!
I think the link you pasted is the same as mine, so I’m not exactly sure what you mean. Did you have another version of the demo?
Thanks!

Lol I forgot to click save: https://playground.babylonjs.com/#8HQ63V#3

I see now!

So I may be wrong, but in my understand the original WebGL’s gl.viewport is also bottom-left, so viewport(0, 0, width, height) means it starts at the bottom left corner of the canvas and grows to the right and to the top so that matches well with what Babylon does.

In you example the viewport occupies the top left quarter of the canvas, it doesn’t use negative x or y values for the viewport. My intention is to use negative viewport.x to be able to render a viewport potentially of the canvas, some parts of it being cut out. In effect viewport.x = -0.5 would mean rendering normally (viewport: 0,0,1,1) but then moving the entire result (“canvas”) to the left by 50%.

1 Like

We directly send the viewport to webgl with no change so it is aligned with what webgl uses :wink:

Isn’t it what you get in your PG ? https://playground.babylonjs.com/#8HQ63V#1

1 Like

Almost. The left part of the canvas is correct, but when I move the camera with the mouse, I can see pixels in the right half of the canvas being rendered into. If I understand this correctly, if the viewport.x is -0.5 and viewport.width = 1, that should mean the rendering end in the middle of the screen: -0.5 + 1 = 0.5.

Could you make a screenshot?

When I move the camera, the right part of the screen always stays empty.

It looks to be my bad, I was under the impression that viewport should also clip where drawing occurs, but its basically just a transformation and I should apply an additional scissor rectangle to clip everywhere else outside it. So in light of that I think its normal that I can see stuff rendered onto the right half of the canvas (its interesting if the right part is always empty on your end if you’re testing the same link):

I see that:

I checked with Chrome / Firefox and clearing the cache before.

Note that in my screenshot it’s “alpha-4”, but after refreshing the cache I got “alpha-5” with the same display.

1 Like

I have the same for the initial rendering. When I move the camera with the mouse (to move the ball to the right on the screen), it gets rendered into the right half of the screen.

1 Like

With right mouse button down + move mouse I get this:

1 Like

Oh that’s really interesting!
This looks to be OS related, I’m seeing the same as you on Windows now (both Chrome and Firefox).
On Mac however there is rendering on the right half too (in all of Chrome, Firefox, Safari).

I have it all working on any Mac Browsers:

I have literally no idea how it would not work for you :frowning: I am on macos 10.15.3

1 Like

Maybe a driver problem that does not handle negative values in viewport correctly.

1 Like

It could be a driver issue indeed…this is the spec, haven’t upgraded to Catalina yet:Screenshot 2020-03-25 at 20.45.14

Wooot we have a similar spec I have no idea but I would go with the driver issue as well then :frowning: