Skip to content

Fix rendering of symbol layers under solid fill layers #2074

Closed

Description

@ansis

It looks like depth testing is disabled for symbol rendering. Is there a good reason?

@scothis

Activity

  1. lucaswoj commented on Feb 5, 2016

    @lucaswoj
    Contributor
  2. ansis commented on Feb 5, 2016

    @ansis
    ContributorAuthor

    When rendering we draw all solid fills top down. We then render everything else bottom-up. We use the depth buffer to drop all fragments that are behind solid fills. This is faster than rendering everything bottom-up because we can drop fragments.

    Depth testing is disabled for symbols because it breaks rotation-alignment: viewport labels in perspective view. Since the extrudes are added after projection the depth values don't match up. I don't think there is a simple way to fix the depth values in this case.

    screen shot 2016-02-05 at 2 43 11 pm

    We can enable depth testing for rotation-alignment: map labels and fix rendering order in all those cases. We should definitely do this. This would fix oneway arrows drawn under bridges.

    We can enable depth testing for rotation-alignment: viewport labels when pitch is 0. Should we do this? The labels would pop up above the fill layers as soon as you tilt.

    If we really want to obey layer order for rotation-alignment: viewport labels in tilted views we need to treat all fill layers above the symbol layers as if they are transparent and draw them in the bottom-up pass. Should we do this? Are there any cases when this would matter? I'm not sure this would make sense conceptually since in perspective view these labels exist in 3d space not the 2d layer space.

  3. lucaswoj commented on Feb 10, 2016

    @lucaswoj
    Contributor

    The "highlight features under the mouse pointer" example demonstrates this bug well

  4. changed the title [-]symbol layers cannot be rendered under solid fill layers[/-] [+]Fix rendering of symbol layers under solid fill layers[/+] on Jul 29, 2016
  5. scothis commented on Aug 25, 2016

    @scothis
    Contributor

    A hacky workaround is to set the fill layer's opacity to 0.99

  6. jfirebaugh commented on Apr 11, 2017

    @jfirebaugh
    Contributor

    I'm starting to think we should just not bother with a two-pass implementation. Currently, the only layers we draw in the opaque pass are opaque, non-patterned fills. And since we'd eventually like to figure out how to antialias fills without a separate GL_LINES draw call, even opaque fills may eventually need to be drawn in the transparent phase.

  7. anandthakker commented on Apr 12, 2017

    @anandthakker
    Contributor

    @jfirebaugh was the original reason for the two-pass approach to allow for the depth buffer optimization @ansis described above? I.e.:

    When rendering we draw all solid fills top down. We then render everything else bottom-up. We use the depth buffer to drop all fragments that are behind solid fills. This is faster than rendering everything bottom-up because we can drop fragments

  8. jfirebaugh commented on Apr 12, 2017

    @jfirebaugh
    Contributor

    Yes, precisely, the two pass approach is intended to minimize overdraw.

  9. ansis commented on Oct 26, 2018

    @ansis
    ContributorAuthor

    I think enabling depth testing for symbols and setting nearDepth and farDepth to the exact same value here could fix this:

    depthModeForSublayer(n: number, mask: DepthMaskType, func: ?DepthFuncType): DepthMode {
    const farDepth = 1 - ((1 + this.currentLayer) * this.numSublayers + n) * this.depthEpsilon;
    const nearDepth = farDepth - 1 + this.depthRange;
    return new DepthMode(func || this.context.gl.LEQUAL, mask, [nearDepth, farDepth]);
    }

    That should make all fragments in the layer have the same value which should make the depth clipping work correctly. I can't remember why they were made different but I don't think that is necessary.

    If depthRange with identical values doesn't work as expected we could modify the matrix to achieve the same result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions