I am trying to create a webgl canvas with a renderer viewport restricted to a portion of it. The idea is to have some hidden canvas real estate I can use for hidden rendering that I then present in a div/canvas.
So, for creating thumbnails with different rendering styles for example.
Anyway, I am getting distorted rendering and I cannot figure out what is wrong with my setup.
Code:
// scratch space for hidden rendering
const scratchSpaceYOffset = 512;
let main = (container) => {
const [ w, h ] = [ container.offsetWidth, container.offsetHeight ];
// setup renderer with viewport restricted to NOT include
// scratch space for hidden rendering
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(w, scratchSpaceYOffset + h);
renderer.setViewport(0, scratchSpaceYOffset, w, h);
renderer.setPixelRatio(window.devicePixelRatio);
// insert canvas in DOM hierarchy
container.appendChild(renderer.domElement);
// camera and orbitalControl setup
const [ fov, near, far ] = [ 40, 1e-1, 7e2 ];
camera = new THREE.PerspectiveCamera(fov, w / h, near, far);
orbitControl = new OrbitControls(camera, renderer.domElement);
}
The variable scratchSpaceYOffset
sets the size of the hidden canvas which extends beyond to bottom of the parent div that host the webgl canvas.
When scratchSpaceYOffset
is zero the rendering is correct, as expect:
When scratchSpaceYOffset
is non-zero (512) the rendering is stretched vertically:
Notice the screen filling calibration quad shows only the upper half (0 - 0.5).
Not sure what I missed.