Skip to content

Commit f68c47d

Browse files
committed
Apply env map flip changes from three
1 parent 59c4e57 commit f68c47d

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/utils/Background.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
Camera,
44
CubeTexture,
55
CubeUVReflectionMapping,
6-
Euler,
76
Group,
87
Matrix3,
98
Matrix4,
@@ -22,7 +21,7 @@ import { SkyBoxMaterial } from "../materials/SkyBoxMaterial.js";
2221
import { extractOutputDefinitions } from "./gbuffer/GBufferUtils.js";
2322
import { ClearValues } from "./ClearValues.js";
2423

25-
const euler = /* @__PURE__ */ new Euler();
24+
const flipEnvMap = /* @__PURE__ */ new Matrix3(-1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);
2625
const matrix4 = /* @__PURE__ */ new Matrix4();
2726

2827
/**
@@ -174,17 +173,19 @@ export class Background extends Group implements Disposable {
174173

175174
if(scene.background instanceof CubeTexture || scene.background.mapping === CubeUVReflectionMapping) {
176175

177-
const flipEnvMap = scene.background.isRenderTargetTexture ? 1 : -1;
178-
euler.copy(scene.backgroundRotation);
179-
euler.x *= -1; euler.y *= -1; euler.z *= -1;
180-
euler.y *= flipEnvMap; euler.z *= flipEnvMap;
181-
182176
skyBox.material.envMap = scene.background;
183-
skyBox.material.uniforms.flipEnvMap.value = flipEnvMap;
184177
skyBox.material.uniforms.backgroundBlurriness.value = scene.backgroundBlurriness;
185178
skyBox.material.uniforms.backgroundIntensity.value = scene.backgroundIntensity;
186179
const backgroundRotation = skyBox.material.uniforms.backgroundRotation.value as Matrix3;
187-
backgroundRotation.setFromMatrix4(matrix4.makeRotationFromEuler(euler));
180+
backgroundRotation.setFromMatrix4(matrix4.makeRotationFromEuler(scene.backgroundRotation));
181+
backgroundRotation.transpose(); // Same as invert in this case, but faster.
182+
183+
if(scene.background instanceof Texture) {
184+
185+
backgroundRotation.premultiply(flipEnvMap);
186+
187+
}
188+
188189
skyBox.visible = true;
189190

190191
} else {

0 commit comments

Comments
 (0)