Skip to content

Commit 4c2fb5b

Browse files
authored
WebGPURenderer: Prevent translation of skybox. (#32537)
1 parent 0437660 commit 4c2fb5b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/renderers/common/Background.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ class Background extends DataMap {
106106

107107
// compute vertex position
108108
const modifiedPosition = isOrtho.select( positionLocal.mul( orthoScale ), positionLocal );
109-
let viewProj = cameraProjectionMatrix.mul( modelViewMatrix.mul( vec4( modifiedPosition, 1.0 ) ) );
109+
110+
// by using a w component of 0, the skybox will not translate when the camera moves through the scene
111+
const viewPosition = modelViewMatrix.mul( vec4( modifiedPosition, 0.0 ) );
112+
113+
// we force w=1.0 here to prevent the w_clip=0 divide-by-zero error for ortho cameras.
114+
let viewProj = cameraProjectionMatrix.mul( vec4( viewPosition.xyz, 1.0 ) );
110115

111116
// force background to far plane so it does not occlude objects
112117
viewProj = viewProj.setZ( viewProj.w );
@@ -127,12 +132,6 @@ class Background extends DataMap {
127132
backgroundMesh.frustumCulled = false;
128133
backgroundMesh.name = 'Background.mesh';
129134

130-
backgroundMesh.onBeforeRender = function ( renderer, scene, camera ) {
131-
132-
this.matrixWorld.copyPosition( camera.matrixWorld );
133-
134-
};
135-
136135
function onBackgroundDispose() {
137136

138137
background.removeEventListener( 'dispose', onBackgroundDispose );

0 commit comments

Comments
 (0)