Skip to content

Commit d70aea1

Browse files
authored
Fix global viewport calculations in AdvancedDynamicTexture (#16757)
Adjust viewport calculations to correctly account for hardware scaling, ensuring accurate rendering in different environments. See https://forum.babylonjs.com/t/problem-with-adapttodeviceratio-and-adaptivescaling/57373/16?u=raananw
1 parent 03bb1d0 commit d70aea1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/dev/gui/src/2D/advancedDynamicTexture.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -774,11 +774,13 @@ export class AdvancedDynamicTexture extends DynamicTexture {
774774
const size = this.getSize();
775775
const globalViewPort = this._fullscreenViewport.toGlobal(size.width, size.height);
776776

777-
const targetX = Math.round(globalViewPort.width * (1 / this.rootContainer.scaleX));
778-
const targetY = Math.round(globalViewPort.height * (1 / this.rootContainer.scaleY));
777+
const targetX = Math.round(globalViewPort.width / this._rootContainer.scaleX);
778+
const targetY = Math.round(globalViewPort.height / this._rootContainer.scaleY);
779779

780-
globalViewPort.x += (globalViewPort.width - targetX) / 2;
781-
globalViewPort.y += (globalViewPort.height - targetY) / 2;
780+
const scale = this._adjustToEngineHardwareScalingLevel ? this._renderScale / (this.getScene()?.getEngine().getHardwareScalingLevel() || 1) : 1;
781+
782+
globalViewPort.x += (globalViewPort.width / scale - targetX) / 2;
783+
globalViewPort.y += (globalViewPort.height / scale - targetY) / 2;
782784

783785
globalViewPort.width = targetX;
784786
globalViewPort.height = targetY;

0 commit comments

Comments
 (0)