Jump to content

[Solved] Device Scaling Resolution


Recommended Posts


I have my canvas stretching 100% width and height of the page. When running it in a small resolution screen and in a big resolution screen, the whole thing is scaled up.

Is there any simple way to simple increase the radius of the camera based on the device resolution instead of having everything scale up? (Everything stays the same size just like regular html elements)

Link to comment
Share on other sites

I am. But that is not the behavior I want. You can test it with the default playground environment. I am expecting the camera radius to increase rather than the whole scene to scale up just like in game engines such as Unity. (I tested it with my laptop and my tv, the whole scene scales up and the html stuff looks really tiny next to the scene)

Link to comment
Share on other sites

I'm sorry but I do not understand what you want to achieve :(

We need to adapt the buffer size to align with the new aspect ratio. It is then up to you to move the camera where you want it 

Link to comment
Share on other sites

Yep so you can do that but manually. There is no automatic way to keep the same visual representation as this clearly 

You are the first to ask but I'm interested to see if more people could use it


Why not starting to hack something in the playground to see how we could do that?

Link to comment
Share on other sites

I had a similar problem. I solved it using this function when canvas resize. I don't have too much time now, but I'll provide a playground later. Play with it ;)

function fitToView()
    //component - is an object from the midle of the scene :))
	let radius = component.getBoundingInfo().boundingSphere.radiusWorld;
    let aspectRatio = engine.getAspectRatio(scene.activeCamera);
    let halfMinFov = scene.activeCamera.fov / 2;
    if (aspectRatio < 1) {
        halfMinFov = Math.atan( aspectRatio * Math.tan(scene.activeCamera.fov / 2) );
    let viewRadius = Math.abs( radius / Math.sin(halfMinFov));
    scene.activeCamera.radius = viewRadius;


Link to comment
Share on other sites

  • 2 weeks later...

I solved this problem by looking at the "window.devicePixelRatio" variable which is either 2 or 1. And I have "adaptToDeviceRatio" turned on. So, for an orthographic camera, I just change the radius(orthoTop, orthoBottom...) which should be doubled at devicePixelRatio 1. And for perspective camera, I also change the radius, but I set custom values for both 2 and 1 so they would match nicely since doubling didn't work too well.

Thanks for the help.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...