Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Background Texture Error #446

Merged
merged 13 commits into from
Aug 20, 2021
24 changes: 12 additions & 12 deletions packages/core/src/Background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,24 @@ export class Background {

switch (this._textureFillMode) {
case BackgroundTextureFillMode.Fill:
positions[0].setValue(-1, -1, -1);
positions[1].setValue(1, -1, -1);
positions[2].setValue(-1, 1, -1);
positions[3].setValue(1, 1, -1);
positions[0].setValue(-1, -1, 1);
positions[1].setValue(1, -1, 1);
positions[2].setValue(-1, 1, 1);
positions[3].setValue(1, 1, 1);
break;
case BackgroundTextureFillMode.AspectFitWidth:
const fitWidthScale = 1 / ((this._texture.width * (height / 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);
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;
positions[0].setValue(-fitHeightScale, -1, -1);
positions[1].setValue(fitHeightScale, -1, -1);
positions[2].setValue(-fitHeightScale, 1, -1);
positions[3].setValue(fitHeightScale, 1, -1);
positions[0].setValue(-fitHeightScale, -1, 1);
positions[1].setValue(fitHeightScale, -1, 1);
positions[2].setValue(-fitHeightScale, 1, 1);
positions[3].setValue(fitHeightScale, 1, 1);
break;
}
_backgroundTextureMesh.setPositions(positions);
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { RenderState } from "./shader/state/RenderState";
import { Texture2D, TextureCubeFace, TextureCubeMap, TextureFormat } from "./texture";
import { PhysicsManager } from "./PhysicsManager";
import { ModelMesh, PrimitiveMesh } from "./mesh";
import { CompareFunction } from "./shader";

/** TODO: delete */
const engineFeatureManager = new FeatureManager<EngineFeature>();
Expand Down Expand Up @@ -190,6 +191,7 @@ export class Engine extends EventDispatcher {

this._backgroundTextureMaterial = new Material(this, Shader.find("background-texture"));
this._backgroundTextureMaterial.isGCIgnored = true;
this._backgroundTextureMaterial.renderState.depthState.compareFunction = CompareFunction.LessEqual;

this._backgroundTextureMesh = PrimitiveMesh.createPlane(this, 2, 2, 1, 1, false);
this._backgroundTextureMesh.isGCIgnored = true;
Expand Down