Skip to content

Commit 00cb114

Browse files
authored
Background material: Fix material not working with floating origin mode + fix use of the sceneCenter property (#17362)
It also fixes a bug in the original implementation of the background material because `vBackgroundCenter` was only set when `REFLECTIONFRESNEL` was defined, whereas if you look at the shader code, you will see that this uniform is only used when both `REFLECTIONFRESNEL `and `REFLECTIONFALLOFF `are defined, or when `OPACITYFRESNEL` is defined.
1 parent 9f4c325 commit 00cb114

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

packages/dev/core/src/Materials/Background/backgroundMaterial.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Logger } from "../../Misc/logger";
55
import type { Nullable, int, float } from "../../types";
66
import type { Scene } from "../../scene";
77
import type { Matrix } from "../../Maths/math.vector";
8-
import { Vector3, Vector4 } from "../../Maths/math.vector";
8+
import { TmpVectors, Vector3, Vector4 } from "../../Maths/math.vector";
99
import { VertexBuffer } from "../../Buffers/buffer";
1010
import type { SubMesh } from "../../Meshes/subMesh";
1111
import type { AbstractMesh } from "../../Meshes/abstractMesh";
@@ -964,6 +964,21 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
964964

965965
this._uniformBuffer.updateFloat("fFovMultiplier", this._fovMultiplier);
966966

967+
// Fresnel
968+
if (defines.REFLECTIONFRESNEL) {
969+
this._uniformBuffer.updateFloat4(
970+
"vReflectionControl",
971+
this._reflectionControls.x,
972+
this._reflectionControls.y,
973+
this._reflectionControls.z,
974+
this._reflectionControls.w
975+
);
976+
}
977+
if ((defines.REFLECTIONFRESNEL && defines.REFLECTIONFALLOFF) || defines.OPACITYFRESNEL) {
978+
const center = TmpVectors.Vector3[0].copyFrom(this.sceneCenter).subtractInPlace(scene.floatingOriginOffset);
979+
this._uniformBuffer.updateFloat3("vBackgroundCenter", center.x, center.y, center.z);
980+
}
981+
967982
// Textures
968983
if (scene.texturesEnabled) {
969984
if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {
@@ -972,17 +987,6 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
972987

973988
if (reflectionTexture && MaterialFlags.ReflectionTextureEnabled) {
974989
BindIBLSamplers(scene, defines, this._uniformBuffer, reflectionTexture);
975-
976-
if (defines.REFLECTIONFRESNEL) {
977-
this._uniformBuffer.updateFloat3("vBackgroundCenter", this.sceneCenter.x, this.sceneCenter.y, this.sceneCenter.z);
978-
this._uniformBuffer.updateFloat4(
979-
"vReflectionControl",
980-
this._reflectionControls.x,
981-
this._reflectionControls.y,
982-
this._reflectionControls.z,
983-
this._reflectionControls.w
984-
);
985-
}
986990
}
987991

988992
if (defines.PROJECTED_GROUND) {

0 commit comments

Comments
 (0)