Materials should use stereo eye position for reflections in multiview

In this playground, for example: https://playground.babylonjs.com/#9K3MRA#754
We have a PBR material that is rendered in multiview, but the uniform vEyePosition used to calculate reflections is only derived from the current active camera (which in multiview rendering corresponds to the left eye). In order to get proper reflections when rendering in multiview we should have a second uniform vEyePositionR or a matrix that compensates for the stereo offset between the left & right eyes that we’d multiply by vEyePosition in order to create vEyePositionR in the shader.

Babylon.js/src/scene.ts

Lines 786 to 791 in 4bc7b80

public bindEyePosition(effect: Nullable, variableName = “vEyePosition”, isVector3 = false): Vector4 {
const eyePosition =
this._forcedViewPosition ? this._forcedViewPosition :
this._mirroredCameraPosition ? this._mirroredCameraPosition :
this.activeCamera!.globalPosition ?? (this.activeCamera as WebVRFreeCamera).devicePosition;

Babylon.js/src/Shaders/ShadersInclude/reflectionFunction.fx

Line 132 in 4bc7b80

return computeCubicCoords(worldPos, worldNormal, vEyePosition.xyz, reflectionMatrix);

*Ported From GitHub

1 Like

Anything to aid, I am for.

Reflections on headsets typically also have problems with inter-frame scattering. This is due to very minor head rotation changes from the prior frame. Increasing distance away the headset from the mesh, quickly magnifies the effect. Regular antialising is powerless for inter-frame camera shake.

Flat shading helps greatly, but for smooth, I also found that mat.enableSpecularAntiAliasing dulls the reflection in the most except able way for inter-frame issues.

2 Likes