Skip to content
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

Fix z-fighting on overlapping extrusions #3324

Closed
lbud opened this issue Oct 7, 2016 · 2 comments
Closed

Fix z-fighting on overlapping extrusions #3324

lbud opened this issue Oct 7, 2016 · 2 comments
Labels

Comments

@lbud
Copy link
Contributor

lbud commented Oct 7, 2016

Extrusions (#3223) suffer from the same problem as #3320: when the map is pitched, extrusions at the same coordinate with different colors are z-fighting and flicker. Since we're drawing all elements in a bucket's element buffer in one draw call, there's currently no way to draw to the depth buffer at a higher resolution (per feature). We should investigate drawing to the depth buffer per-feature or based on actual z index in ↕️ space…

@ansis
Copy link
Contributor

ansis commented Oct 20, 2016

This is a hard problem to solve. I think gl.polygonOffset(factor, units) can be sometimes used to fix these things but I think it can also introduce other problems.

@lucaswoj lucaswoj changed the title Investigate more granular depth buffering Fix z-fighting on overlapping extrusions Oct 24, 2016
@mourner
Copy link
Member

mourner commented Jul 31, 2018

No clear way to address this at the moment, so I'll close for now as not actionable.

@mourner mourner closed this as completed Jul 31, 2018
astojilj added a commit that referenced this issue May 24, 2022
Styleable layout property fill-extrusion-faux-ao (boolean). Implementation in shaders done under #ifdef FAUX_AO not to affect other use cases.

This is a low cost approach that potentially combined with line-blur (TODO: line-blur artefacts issue #10000) provides plausible results, somewhat reminding of ambient occlusion.

The approach shades vertical walls vertically near ground and horizontally near concave angles. In contrast to vertical-gradient that's linearly interpolated in fragment shader, exponential shading is exponential
Implementation is specialized for scale of buildings. Open for later introduction of data constant paint property fill-extrusion-faux-ao-radius (in meters). E.g. defgault value of 3 would correspond to this implementation. Arguably, data visualizations on globe zoom levels benefit more from vertical-gradient that is linearly interpolated from ground to top than from this since in most of use cases there are no concave angles.

Setting the property also activates an improvement for #3324 - z-fighting artefacts are especially noticeable on buildings. This improvement could be promoted to all the cases later. As it would take time to re-evaluate if the fix is acceptable for all the cases, it is enabled in shaders under #ifdef FAUX_AO. The appropach is based on common z-fighting culprits coming from overlapping fill extrusion walls that have different height and different base. In such case, higher planes and those with higher base (since often height is the same) are brought forward.
astojilj added a commit that referenced this issue Jun 15, 2022
Styleable layout property fill-extrusion-faux-ao (boolean). Implementation in shaders done under #ifdef FAUX_AO not to affect other use cases.

This is a low cost approach that potentially combined with line-blur (TODO: line-blur artefacts issue #10000) provides plausible results, somewhat reminding of ambient occlusion.

The approach shades vertical walls vertically near ground and horizontally near concave angles. In contrast to vertical-gradient that's linearly interpolated in fragment shader, exponential shading is exponential
Implementation is specialized for scale of buildings. Open for later introduction of data constant paint property fill-extrusion-faux-ao-radius (in meters). E.g. defgault value of 3 would correspond to this implementation. Arguably, data visualizations on globe zoom levels benefit more from vertical-gradient that is linearly interpolated from ground to top than from this since in most of use cases there are no concave angles.

Setting the property also activates an improvement for #3324 - z-fighting artefacts are especially noticeable on buildings. This improvement could be promoted to all the cases later. As it would take time to re-evaluate if the fix is acceptable for all the cases, it is enabled in shaders under #ifdef FAUX_AO. The appropach is based on common z-fighting culprits coming from overlapping fill extrusion walls that have different height and different base. In such case, higher planes and those with higher base (since often height is the same) are brought forward.
astojilj added a commit that referenced this issue Jun 20, 2022
Styleable layout property fill-extrusion-faux-ao (boolean). Implementation in shaders done under #ifdef FAUX_AO not to affect other use cases.

This is a low cost approach that potentially combined with line-blur (TODO: line-blur artefacts issue #10000) provides plausible results, somewhat reminding of ambient occlusion.

The approach shades vertical walls vertically near ground and horizontally near concave angles. In contrast to vertical-gradient that's linearly interpolated in fragment shader, exponential shading is exponential
Implementation is specialized for scale of buildings. Open for later introduction of data constant paint property fill-extrusion-faux-ao-radius (in meters). E.g. defgault value of 3 would correspond to this implementation. Arguably, data visualizations on globe zoom levels benefit more from vertical-gradient that is linearly interpolated from ground to top than from this since in most of use cases there are no concave angles.

Setting the property also activates an improvement for #3324 - z-fighting artefacts are especially noticeable on buildings. This improvement could be promoted to all the cases later. As it would take time to re-evaluate if the fix is acceptable for all the cases, it is enabled in shaders under #ifdef FAUX_AO. The appropach is based on common z-fighting culprits coming from overlapping fill extrusion walls that have different height and different base. In such case, higher planes and those with higher base (since often height is the same) are brought forward.
astojilj added a commit that referenced this issue Jun 20, 2022
* Faux ambient occlusion specialized for buildings

Styleable layout property fill-extrusion-faux-ao (boolean). Implementation in shaders done under #ifdef FAUX_AO not to affect other use cases.

This is a low cost approach that potentially combined with line-blur (TODO: line-blur artefacts issue #10000) provides plausible results, somewhat reminding of ambient occlusion.

The approach shades vertical walls vertically near ground and horizontally near concave angles. In contrast to vertical-gradient that's linearly interpolated in fragment shader, exponential shading is exponential
Implementation is specialized for scale of buildings. Open for later introduction of data constant paint property fill-extrusion-faux-ao-radius (in meters). E.g. defgault value of 3 would correspond to this implementation. Arguably, data visualizations on globe zoom levels benefit more from vertical-gradient that is linearly interpolated from ground to top than from this since in most of use cases there are no concave angles.

Setting the property also activates an improvement for #3324 - z-fighting artefacts are especially noticeable on buildings. This improvement could be promoted to all the cases later. As it would take time to re-evaluate if the fix is acceptable for all the cases, it is enabled in shaders under #ifdef FAUX_AO. The appropach is based on common z-fighting culprits coming from overlapping fill extrusion walls that have different height and different base. In such case, higher planes and those with higher base (since often height is the same) are brought forward.

* AO: Replace faux-ao layout boolean by intensity and radius paint properties

Instead of fill-extrusion-faux-ao layout constant property, 2 paint properties are introduced:
- fill-extrusion-ambient-occlusion-intensity, in range [0..1]
- fill-extrusion-ambient-occlusion-radius, in meter units, values larger than 0.

Reasons:
- is it too early top specify layout property that would be use as a hard switch of the feature. In future, we might have multiple types of AO (server side included) where type of AO would be used, not a boolean property.
- separate properties intensity and radius are needed for globe zoom level visualization and those properties are expected when modelling AO, e.g. similar is found in Blender.

* Fill extrusion z fighting render test, fill extrusion pattern support for AO

With ambient occlusion intensity of 0.001, expected result is the same as with no ambient occlusion, but with z fighting fixed.

* Render tests, process review comments.

Shaders: removed sqrt and mix-es that are using constants

Thanks @karimnaaji

* Process review comments. Render tests for small angles

* Link to documentation in shader code.

Processing the latest comments and rebase.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants