Skip to content

Commit

Permalink
refactor: fix background calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
gz65555 committed Aug 28, 2021
1 parent 60430f6 commit 938dae0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/Background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/RenderPipeline/BasicRenderPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 938dae0

Please sign in to comment.