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.
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.
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!
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%.
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.
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 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.
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).