Much cleaner edge rendering when enabling logarithmic depth buffer #1788
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Descrption
Use the same gradient technique has here #1162 (comment) for much better visual quality in edge rendering when the logarithmic depth buffer is enabled.
Screenshots: Before / After
The screenshots below were taken with a far plane distance equal to 1M km!
Before (i)
After (i)
Before (ii)
After (ii)
Explanation
Sub-pixel z-fighting (explained here #1162 (comment)) makes edge drawing worse when logarithmic depth buffer is enabled, possibly because the dynamic range of the Z values get compressed (via the
log
function) together with much bigger far plane distances being used with logarithmic z-buffer.As the rendering of edged surfaces happens in two stages in xeokit-sdk...
... the reduced dynamic range affects more the case where log-depth-buffer is enabled.
This PR makes use of the gradient trick so, during the regular surface rendering, their z-values are "pushed" far away from the camera to the same distance where their immediate furthest neighbour pixel is.
This makes the z-buffer pre-initialization much more friendly with stage "b)", and fixes the sub-pixel z-fighting problem.