Updating a texture's __webglTexture works for normal textures but not for scene.environment

This is in the latest Dev version as part of work to fix AR lighting estimation in AFrame

The Lighting estimation API returns a WebGL texture to use as a cube map.

In my scene have 2 relevant objects a torus knot which is has high metalness and low roughness to see the environment and an Octahedron which uses the same texture as a cube map.

During non-AR rendering a WebGLCubeRenderTarget is used to display a scene rendered from the environment.

During AR rendering when lighting estimation is available the __webglTexture is replaced with the one provided from the WebXR Lighting Estimation API. This updates as expected on the Octahedron but the TorusKnot would still show the environment as was rendered by the cube camera.

I think something is cached somewhere for the environment version.

Here is a link to the code: aframe/reflection.js at e5abded3e8b39549626bb764eb00687fd9076fe5 · AdaRoseCannon/aframe · GitHub

Screenshot showing the issue, where the rear Octahedron is correctly using the texture (green-ish) but the torus knot somehow has the old texture (blue-ish)

Solved: For setting the environment needs the PMREMUpdate set to true when the texture is replaced.

this.xrLight.environment.needsPMREMUpdate = true;
1 Like

Sidenote: The flag will be available with r137.