Rotated reflection map and clipping planes

Hi,

I had problems with the reflection map being rotated and used the proposed workaround by modifying tileset._initialClippingPlanesOriginMatrix as suggested here: Brown metallic reflection - #8 by Marco13

However, I also want to clip this 3DTiles tileset with a ClippingPlaneCollection with four planes using ECEF coordinates. But this fails since I have modified _initialClippingPlanesOriginMatrix. So I’m stuck between a rock and a hard place here.

Is there a better way of rotating the reflection map correctly than modifying _initialClippingPlanesOriginMatrix? Or what can I do? I tried consulting both ChatGPT and Gemini back and forth during a whole day to try transforming my clipping planes, but to no avail. It’s obviously not optimal to modify a private member. And I don’t really understand why Cesium3DTileset.clippingPlanesOriginMatrix that seems to be the only function using _initialClippingPlanesOriginMatrix is involved in the reflection map rotation?

As it is now, I will have to explain to my customer why the reflective water is brown when looking the wrong way, since that is at least somewhat better than not clipping out a high-res model from a medium-res model. But it can’t be considered a satisfactory delivery, so I’m a bit frustrated. Please help!

Only a quick note for now:

Is there a better way of rotating the reflection map correctly than modifying _initialClippingPlanesOriginMatrix ?

I did emphasize in the linked thread that “this is also not a recommended solution, obviously”. It was a workaround for the still open issue of the rotated environment map.

Given that there don’t seem to be any plans for addressing this issue, maybe the “better” ““solution”” (i.e. workaround) (that would also not interfere with the clipping planes) would be to disable the environment map manager…?

I actually posted additional “workarounds” yesterday, at New 1.123 Environment Map Rotates Together With Model · Issue #12310 · CesiumGS/cesium · GitHub - maybe you want to try the first one, and see whether it unblocks your intended workflow for now…

Thanks Marco, I appreciate it. And I know it wasn’t a recommended solution from you either, just a temporary workaround. Unfortunately, your new suggested workarounds don’t really help since I really want my water to reflect the sky. Maybe turn it off completely but then it would be just black. I will add a comment to the issue as well.

I finally managed to calculate the correct modelMatrix. Not so complex after all:

const modelMatrix = Cesium.Matrix4.inverse(tileset.root.computedTransform, new Cesium.Matrix4());
Cesium.Matrix4.multiply(Cesium.Matrix4.inverse(tileset._initialClippingPlanesOriginMatrix, new Cesium.Matrix4()), modelMatrix, modelMatrix);

It’s not entirely clear where/how this is inserted. If you add some information to the issue, then it might help others investigating (and maybe resolving) it. (As we have seen, there are quite a few matrices that ~“might be wrong” in some ways, so it will require additional investigations and validation, but maybe it helps as a pointer…)