From 938dae007a0e35d1d48c7dcd74830a78387d89f3 Mon Sep 17 00:00:00 2001 From: gz65555 Date: Sat, 28 Aug 2021 10:46:49 +0800 Subject: [PATCH] refactor: fix background calculation --- packages/core/src/Background.ts | 4 ++-- packages/core/src/RenderPipeline/BasicRenderPipeline.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/Background.ts b/packages/core/src/Background.ts index 53c55097fa..3927fac0be 100644 --- a/packages/core/src/Background.ts +++ b/packages/core/src/Background.ts @@ -92,14 +92,14 @@ export class Background { positions[3].setValue(1, 1, 1); break; case BackgroundTextureFillMode.AspectFitWidth: - const fitWidthScale = 1 / ((this._texture.width * (height / width)) / height); + const fitWidthScale = (this._texture.height * width) / this.texture.width / height; positions[0].setValue(-1, -fitWidthScale, 1); positions[1].setValue(1, -fitWidthScale, 1); positions[2].setValue(-1, fitWidthScale, 1); positions[3].setValue(1, fitWidthScale, 1); break; case BackgroundTextureFillMode.AspectFitHeight: - const fitHeightScale = (this._texture.width * (height / width)) / height; + const fitHeightScale = (this._texture.width * height) / this.texture.height / width; positions[0].setValue(-fitHeightScale, -1, 1); positions[1].setValue(fitHeightScale, -1, 1); positions[2].setValue(-fitHeightScale, 1, 1); diff --git a/packages/core/src/RenderPipeline/BasicRenderPipeline.ts b/packages/core/src/RenderPipeline/BasicRenderPipeline.ts index 21d3ca9e10..5f9da6a13b 100644 --- a/packages/core/src/RenderPipeline/BasicRenderPipeline.ts +++ b/packages/core/src/RenderPipeline/BasicRenderPipeline.ts @@ -181,7 +181,7 @@ export class BasicRenderPipeline { this._alphaTestQueue.render(camera, pass.replaceMaterial, pass.mask); if (background.mode === BackgroundMode.Sky) { this._drawSky(engine, camera, background.sky); - } else if (background.mode === BackgroundMode.Texture) { + } else if (background.mode === BackgroundMode.Texture && background.texture) { this._drawBackgroundTexture(engine, background); } this._transparentQueue.render(camera, pass.replaceMaterial, pass.mask);