How to rotate environment map at runtime?

There seems to be an open issue about this here:

Is there a way to apply a shader modification to achieve this in the mean-time? It’s possible to add custom uniforms using onBeforeCompile so I can add a vec3 for the rotation and I can insert a transform somewhere in the shader but I can’t see where to add the transform.

The env map direction is controlled by envmap_fragment. This is included in some of the main material shader types. For some reason that include isn’t in meshphysical_frag though so I’m not sure where the envmap chunk is being used there. But I could modify the reflectVec in envmap_fragment with the custom uniform.

How do I modify those chunks? onBeforeCompile shows the main shader so I could paste the whole modified shader in but where is meshphysical_frag processing the environment map?

Found it, the envmap code for the standard material shader is in:
#include <envmap_physical_pars_fragment>

so with an onBeforeCompile, it’s possible to do shader.fragmentShader.replace on that line and paste the contents of that file in with the new uniform. That should let me rotate the environment map at runtime.