Long answer: So while working on the rain implementation, I noticed that some rain drops are too close to the camera. That means that I would have to increase the near-Z clipping plane to fix it. I knew that I would have issues with it since I never could get the scaling to work in a mathematically precise manner. So I put a day aside to investigate this very thoroughly. I found out that when I convert a map coordinate to a screen coordinate, the X and Y values work fine, but the actual Z value doesn't. Since I use the Z for scaling, this broke scaling when larger values were used for the near-z clipping plane. It would be perfect if one used 0 and would still look reasonably well with a value of 10. But the higher you go, the more the scaling is offset. So after 6h or so of digging and experimenting, I finally figured out the formula that I need to apply to the Z coordinate to get the proper value.
If you want the formula, just find the piece of code that is changed with LEGACY_SCALING. It's just one if-block. The code reads:
Code:
const factor = -projection.data[10];
result.z = result.z / factor + (factor - 1) / factor * UltraMode7.FAR_CLIP_Z;The value for projection.data[10] is:
Code:
-(UltraMode7.FAR_CLIP_Z + UltraMode7.NEAR_CLIP_Z) / (UltraMode7.FAR_CLIP_Z - UltraMode7.NEAR_CLIP_Z)So the transformation formula is:
Code:
factor = (UltraMode7.FAR_CLIP_Z + UltraMode7.NEAR_CLIP_Z) / (UltraMode7.FAR_CLIP_Z - UltraMode7.NEAR_CLIP_Z)
properZ = previouslyUsedZ / factor + (factor - 1) / factor * UltraMode7.FAR_CLIP_Z;But again, it's better if you just remove your custom setups and disable LEGACY_SCALING. You can now use any NEAR_CLIP_Z and FAR_CLIP_Z and the plugin will properly handle scaling and visibility.
There's just something about the map now that makes it look significantly better. It's such a subtle thing, but now the sprites actually feel like part of the 3D map rather than slapped-on 2D sprites.[/b]