Skip to content

Examples rendering resolution grows when lowering browser zoom below 100% #31943

@davcri

Description

@davcri

Description

As the title says.

I'm happy to work on a PR. I would implement resize logic as described in https://threejs.org/manual/#en/responsive in order to have a consistent approach between the manual and examples section:

        function resizeRendererToDisplaySize(renderer) {
          const canvas = renderer.domElement;
          const pixelRatio = window.devicePixelRatio;
          const width  = Math.floor( canvas.clientWidth  * pixelRatio );
          const height = Math.floor( canvas.clientHeight * pixelRatio );
          const needResize = canvas.width !== width || canvas.height !== height;
          if (needResize) {
            renderer.setSize(width, height, false);
          }
          return needResize;
        }

What do you think?

Reproduction steps

  1. Open https://threejs.org/examples/?q=car#webgl_materials_car
  2. Zoom out the page
  3. Observe canvas width and height from the inspector

Code

I guess this is related to window.devicePixelRatio not being used in the resize logic.

function init() {

	const container = document.getElementById( 'container' );

	renderer = new THREE.WebGLRenderer( { antialias: true } );
	renderer.setPixelRatio( window.devicePixelRatio );
	renderer.setSize( window.innerWidth, window.innerHeight );
	renderer.setAnimationLoop( animate );
	container.appendChild( renderer.domElement );

	window.addEventListener( 'resize', onWindowResize );
                          // ...
                 }


function onWindowResize() {

	camera.aspect = window.innerWidth / window.innerHeight;
	camera.updateProjectionMatrix();

	renderer.setSize( window.innerWidth, window.innerHeight );

}

https://github.com/mrdoob/three.js/blob/r180/examples/webgl_materials_car.html#L187-L194

I picked the car example in this issue, but I think most of the examples are based on the same resize logic.

Live example

https://threejs.org/examples/?q=car#webgl_materials_car

Screenshots

2025-09-25.09-59-35.trimmed.mp4

Version

r180

Device

No response

Browser

No response

OS

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions