Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/rendering/tsl/VolumetricFog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,15 @@ export function createVolumetricFogNode(
* Update camera matrices (call before render)
*/
updateCamera: (cam: THREE.PerspectiveCamera) => {
// Ensure camera matrices are current before copying
// (camera position may have changed but matrices not yet updated)
cam.updateMatrixWorld();
cam.updateProjectionMatrix();

uCameraNear.value = cam.near;
uCameraFar.value = cam.far;
uCameraPos.value.copy(cam.position);
// Extract world position from matrixWorld for consistency with world reconstruction
uCameraPos.value.setFromMatrixPosition(cam.matrixWorld);
uInverseProjection.value.copy(cam.projectionMatrixInverse);
uInverseView.value.copy(cam.matrixWorld);
},
Expand Down
10 changes: 8 additions & 2 deletions src/rendering/tsl/effects/EffectPasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1045,15 +1045,21 @@ export function createFogOfWarPass(
};

const updateCamera = (cam: THREE.PerspectiveCamera) => {
// Ensure camera matrices are current before copying
// (camera position may have changed but matrices not yet updated)
cam.updateMatrixWorld();
cam.updateProjectionMatrix();

// Update camera parameters for world position reconstruction
uCameraNear.value = cam.near;
uCameraFar.value = cam.far;
// Inverse projection for clip->view transform (using our own uniform, not built-in jittered one)
uInverseProjection.value.copy(cam.projectionMatrixInverse);
// Camera world matrix transforms view-space to world-space
uCameraWorldMatrix.value.copy(cam.matrixWorld);
// Direct camera position for volumetric fog
uCameraPos.value.copy(cam.position);
// Extract world position from matrixWorld for consistency with world reconstruction
// (using camera.position directly would give local position if camera has a parent)
uCameraPos.value.setFromMatrixPosition(cam.matrixWorld);
};

const applyConfig = (config: Partial<FogOfWarConfig>) => {
Expand Down
Loading