In trying to avoid the camera shake of an XR device, Quest 2 as an example, I have tried a couple of methods which have involved NOT altering on a dimension basis, the cameras rotation / position for very small changes from the previous frame.
While this does work, the big gains are not observed before there is the side effect of noticing.
The primary beneficiary though are PBR materials, especially ones that do a lot of reflection. One thing I was thinking about was not altering the camera, but use the same prior frame checking to alter the reflection texture instead to counteract the rotation and stabilize the reflection.
If it worked, the major advantage is it would probably not produce a side effect until beyond observing a large improvement. And any side effect would also probably not involve ones sense of balance.
The quick setup would be:
let smallYChange = n;
let smallXChange = n2;
let texture;
const mat = texture.getReflectionTextureMatrix();
BABYLON.Matrix.RotationYawPitchRollToRef(smallYChange, smallXChange, 0, mat);
// already sort did this, by using the reference, but it manages the change
texture.setReflectionTextureMatrix(mat);
While feel free to poke holes in this anywhere, looking at the stuff in setReflectionTextureMatrix()
, below, the scene markAllMaterialsAsDirty()
seems ominous. Is that going be a devistating performance hit?
/**
* Returns the reflection texture matrix
* @returns the reflection texture matrix
*/
public getReflectionTextureMatrix(): Matrix {
return this._textureMatrix;
}
/**
* Sets the reflection texture matrix
* @param value Reflection texture matrix
*/
public setReflectionTextureMatrix(value: Matrix): void {
if (value.updateFlag === this._textureMatrix.updateFlag) {
return;
}
if (value.isIdentity() !== this._textureMatrix.isIdentity()) {
this.getScene()?.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag, (mat) => mat.getActiveTextures().indexOf(this) !== -1);
}
this._textureMatrix = value;
}