-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate tighter near far bounds in View.js #8850
Conversation
Thanks for the pull request @IanLilleyT!
Reviewers, don't forget to make sure that:
|
bump @lilleyse |
I think it makes sense to move this to the July release, but we should merge it as soon as possible after the June release is out. |
@IanLilleyT @lilleyse bump |
I like the approach and I like how much the simpler the code got. Performance is comparable with master - this sandcastle shows The only thing that should be addressed is that |
@lilleyse updated |
The latest changes look good. Thanks @IanLilleyT |
Fixes #8346
Fixes #8439
View.js
is responsible for deciding which commands get rendered into which frustums, and every frame it calculates the global near / far values of all commands in order to figure out how many frustums are needed. Problem is, the heuristics it was using to decide if the frustums needed to be adjusted was not triggered when switching to orthographic camera, resulting in the orthographic transform using near / far bounds meant for logarithmic depth (since perspective camera uses logdepth and we just switched away from it). This resulted in an extremely tiny value in the orthographic matrix which ended up becoming 0 by the time it was converted to float32 for the shader. So all triangles were considered to have the same Z value post-transformation, overwriting each other.This PR recalculates the frustums whenever the near / far changes, resulting in a much more sane transformation matrix. It also has the added benefit of making our depth values more accurate for all kinds of projections, though I haven't noticed any visual quality difference.
This can be seen from displaying the camera's frustum before and after using tighter near / far (using perspective + log depth):
Before:
After:
One thing to watch out for is now the near / far change constantly when you move the camera. I don't think this is a problem though.
In working on this a bug, another bug popped up with point cloud eye dome lighting. Somehow, the farther near value created some floating point imprecision issues when reading and writing the log depth value. Then @lilleyse realized we could just passthrough the depth value without unpacking and repacking it, solving the problem. This hit a snag with derived commands because it expects to see czm_writeLogDepth, otherwise it appends log depth code to the shader. Had to add a
LOG_DEPTH_WRITE
define to inform the system that log depth was truly being written already.