Skip to content

Updated renderer to allow viewport to be set manually #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ZeppelinGames
Copy link

  • Updated setViewport function on Renderer
  • Added updateViewport function on Renderer
  • Reordered state and setSize initialisation in Renderer

Allows for functionality using normalized coordinates:

// w, h, x=0, y=0
renderer.setViewport(0.5, 0.5, 0, 0);
renderer.render({ scene, camera });

By default/on screen resize viewport resets to [1,1,0,0] (setViewport(1,1))

@ZeppelinGames
Copy link
Author

ZeppelinGames commented Apr 22, 2025

Will allow for rendering the same camera twice using the same renderer context
(ignore the jank)

// Render camera at bottom left corner
camera.position.z = 5;
renderer.setViewport(0.5, 0.5, 0, 0);
renderer.gl.enable(renderer.gl.SCISSOR_TEST);
renderer.setScissor(viewport3D.clientWidth * 0.5, viewport3D.clientHeight * 0.5);
renderer.render({ scene, camera });
renderer.gl.disable(renderer.gl.SCISSOR_TEST);

// Render same camera at bottom right corner
camera.position.z = 3
renderer.setViewport(0.5, 0.5, 0.5, 0);
renderer.gl.enable(renderer.gl.SCISSOR_TEST);
renderer.setScissor(viewport3D.clientWidth * 0.5, viewport3D.clientHeight * 0.5, viewport3d.clientHeight * 0.5);
renderer.render({ scene, camera });
renderer.gl.disable(renderer.gl.SCISSOR_TEST);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant