# Does BJS take into account window.devicePixelRatio?

**URL:** <https://forum.babylonjs.com/t/does-bjs-take-into-account-window-devicepixelratio/33734>\
**Category:** Questions\
**Created:** [September 7, 2022, 5:55am UTC](https://forum.babylonjs.com/t/does-bjs-take-into-account-window-devicepixelratio/33734 "2022-09-07T05:55:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rata\_Blanca](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rata_blanca/32/24779_2.png) [@Rata\_Blanca](https://forum.babylonjs.com/u/Rata_Blanca)\
**Post date:** [September 7, 2022, 5:55am UTC](https://forum.babylonjs.com/t/does-bjs-take-into-account-window-devicepixelratio/33734/1 "2022-09-07T05:55:32Z")

</div>

I have strange behaviour with my android device. I think it’s because of its cheap gpu but anyway. I get bad antialiasing for textures on my blocky-style project (like minecraft textures, I use Constants.TEXTURE\_NEAREST\_SAMPLINGMODE). It has: **1920x1080** and **window.devicePixelRatio=1**.  
On other phones all look good: iphone 6, iphone 11.  
The only one solution for that Android phone that I’ve success it’s:  
`engine.setHardwareScalingLevel( 0.5 );`  
then it looks great on that Android. And no any difference on iphones. iPhones don’t need to set such option all looks good without it.

As I read it hear it’s not the best solution just for impoving visual quality 😀  
iPhones have devicePixelRatio=3.0, Android has devicePixelRatio=1.0. My thought was is to check first does BJS use **window.devicePixelRatio** setting inside the engine?  
Do you have any suggestions why do I face such behaviour?

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [September 7, 2022, 9:06am UTC](https://forum.babylonjs.com/t/does-bjs-take-into-account-window-devicepixelratio/33734/2 "2022-09-07T09:06:24Z")

</div>

Babylon can take devicePixelRation into account, if you want it to. You need to pass the option to the engine when you create it -

> **[EngineOptions | Babylon.js Documentation](https://doc.babylonjs.com/typedoc/interfaces/BABYLON.EngineOptions#adaptToDeviceRatio)**
>
> Interface defining initialization parameters for Engine class \[API\]

It defaults to false.

---

<div class="post-metadata">

**Author:** ![brianzinn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brianzinn/32/28013_2.png) [@brianzinn](https://forum.babylonjs.com/u/brianzinn)\
**Post date:** [September 7, 2022, 2:15pm UTC](https://forum.babylonjs.com/t/does-bjs-take-into-account-window-devicepixelratio/33734/3 "2022-09-07T14:15:31Z")

</div>

here is the code:  
[Babylon.js/webgpuEngine.ts at master · BabylonJS/Babylon.js (github.com)](https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Engines/webgpuEngine.ts#L570)

The reason I show the code is that you said your device has a `devicePixelRatio` of 1.0, but you only get success with `.setHardwareScalingLevel(0.5)` - I don’t think that will happen with the `adaptToDeviceRatio` option… then again I haven’t had any coffee this morning! 😄

---

<div class="post-metadata">

**Author:** ![trusktr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/trusktr/32/840_2.png) [@trusktr](https://forum.babylonjs.com/u/trusktr)\
**Post date:** [February 17, 2024, 8:13am UTC](https://forum.babylonjs.com/t/does-bjs-take-into-account-window-devicepixelratio/33734/4 "2024-02-17T08:13:15Z")

</div>

We can set the hardware scaling level to adjust the pixel ratio:

```js
engine.setHardwareScalingLevel(1 / window.devicePixelRatio)

```

(equivalent to `renderer.setPixelRatio(window.devicePixelRatio)` in Three.js)
