Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 2c5528e

Browse files
committed
Fix layers rendering after fill-extrusion
This fixes following issues: * Fix some false passing combinations/fill-extrusion-translucent--XXXX tests * Fix and enable other, failing but ignored, combinations/fill-extrusion-translucent--XXXX tests * Fix rendering of layers that are on top of fill-extrusion layers state.getProjMatrix(nearClippedProjMatrix, 100) caused that tests with size 64x64 were not rendering fill extrusions: far plane calculated as 96.9 and near plane set to 100 was the cause. near plane is changed from hardcoded 100 to depend on state.getCameraToCenterDistance() - producing similar value but one that follows max zoom. This caused that e.g. combinations/fill-extrusion-translucent--fill-opaque was falsely passing as only fill-opaque layer got rendered. combinations/fill-extrusion-translucent--XXXX tests expose regression #14844 (comment) in #14844, #14779. Fix (opaquePassCutoff, is3D) is ported from mapbox/mapbox-gl-js#7821 Fixes: #14844, #14779, #15039
1 parent 929824e commit 2c5528e

11 files changed

Lines changed: 31 additions & 33 deletions

platform/node/test/ignores.json

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,7 @@
8787
"render-tests/text-rotate/with-offset": "https://github.com/mapbox/mapbox-gl-native/issues/11872",
8888
"render-tests/video/default": "skip - https://github.com/mapbox/mapbox-gl-native/issues/601",
8989
"render-tests/background-color/colorSpace-hcl": "needs issue",
90-
"render-tests/combinations/fill-extrusion-translucent--heatmap-translucent": "needs investigation",
9190
"render-tests/combinations/heatmap-translucent--background-opaque": "needs investigation",
92-
"render-tests/combinations/heatmap-translucent--fill-extrusion-translucent": "needs investigation",
93-
"render-tests/combinations/background-opaque--fill-extrusion-translucent": "needs investigation",
94-
"render-tests/combinations/background-translucent--fill-extrusion-translucent": "needs investigation",
95-
"render-tests/combinations/circle-translucent--fill-extrusion-translucent": "needs investigation",
96-
"render-tests/combinations/fill-extrusion-translucent--background-translucent": "needs investigation",
97-
"render-tests/combinations/fill-extrusion-translucent--circle-translucent": "needs investigation",
98-
"render-tests/combinations/fill-extrusion-translucent--hillshade-translucent": "needs investigation",
99-
"render-tests/combinations/fill-extrusion-translucent--fill-extrusion-translucent": "needs investigation",
100-
"render-tests/combinations/fill-extrusion-translucent--fill-translucent": "needs investigation",
101-
"render-tests/combinations/fill-extrusion-translucent--line-translucent": "needs investigation",
102-
"render-tests/combinations/fill-extrusion-translucent--symbol-translucent": "needs investigation",
103-
"render-tests/combinations/hillshade-translucent--fill-extrusion-translucent": "needs investigation",
104-
"render-tests/combinations/fill-opaque--fill-extrusion-translucent": "needs investigation",
105-
"render-tests/combinations/fill-translucent--fill-extrusion-translucent": "needs investigation",
106-
"render-tests/combinations/line-translucent--fill-extrusion-translucent": "needs investigation",
107-
"render-tests/combinations/raster-translucent--fill-extrusion-translucent": "needs investigation",
108-
"render-tests/combinations/symbol-translucent--fill-extrusion-translucent": "needs investigation",
10991
"render-tests/feature-state/composite-expression": "https://github.com/mapbox/mapbox-gl-native/issues/12613",
11092
"render-tests/feature-state/data-expression": "https://github.com/mapbox/mapbox-gl-native/issues/12613",
11193
"render-tests/feature-state/vector-source": "https://github.com/mapbox/mapbox-gl-native/issues/12613",

src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ bool RenderFillExtrusionLayer::hasCrossfade() const {
5555
return getCrossfade<FillExtrusionLayerProperties>(evaluatedProperties).t != 1;
5656
}
5757

58+
bool RenderFillExtrusionLayer::is3D() const {
59+
return true;
60+
}
61+
5862
void RenderFillExtrusionLayer::render(PaintParameters& parameters) {
5963
assert(renderTiles);
6064
if (parameters.pass != RenderPass::Translucent) {

src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class RenderFillExtrusionLayer final : public RenderLayer {
1717
void evaluate(const PropertyEvaluationParameters&) override;
1818
bool hasTransition() const override;
1919
bool hasCrossfade() const override;
20+
bool is3D() const override;
2021
void render(PaintParameters&) override;
2122

2223
bool queryIntersectsFeature(

src/mbgl/renderer/layers/render_fill_layer.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,10 @@ void RenderFillLayer::render(PaintParameters& parameters) {
130130
);
131131
};
132132

133-
// Only draw the fill when it's opaque and we're drawing opaque fragments,
134-
// or when it's translucent and we're drawing translucent fragments.
135-
if (bucket.triangleIndexBuffer &&
136-
(evaluated.get<FillColor>().constantOr(Color()).a >= 1.0f &&
137-
evaluated.get<FillOpacity>().constantOr(0) >= 1.0f) == (parameters.pass == RenderPass::Opaque)) {
133+
auto fillRenderPass = (evaluated.get<FillColor>().constantOr(Color()).a >= 1.0f
134+
&& evaluated.get<FillOpacity>().constantOr(0) >= 1.0f
135+
&& parameters.currentLayer >= parameters.opaquePassCutoff) ? RenderPass::Opaque : RenderPass::Translucent;
136+
if (bucket.triangleIndexBuffer && parameters.pass == fillRenderPass) {
138137
draw(parameters.programs.getFillLayerPrograms().fill,
139138
gfx::Triangles(),
140139
parameters.depthModeForSublayer(1, parameters.pass == RenderPass::Opaque

src/mbgl/renderer/paint_parameters.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ TransformParameters::TransformParameters(const TransformState& state_)
1919
// odd viewport sizes.
2020
state.getProjMatrix(alignedProjMatrix, 1, true);
2121

22-
// Calculate a second projection matrix with the near plane clipped to 100 so as
23-
// not to waste lots of depth buffer precision on very close empty space, for layer
24-
// types (fill-extrusion) that use the depth buffer to emulate real-world space.
25-
state.getProjMatrix(nearClippedProjMatrix, 100);
22+
// Calculate a second projection matrix with the near plane moved further,
23+
// to a tenth of the far value, so as not to waste depth buffer precision on
24+
// very close empty space, for layer types (fill-extrusion) that use the
25+
// depth buffer to emulate real-world space.
26+
state.getProjMatrix(nearClippedProjMatrix, 0.1 * state.getCameraToCenterDistance());
2627
}
2728

2829
PaintParameters::PaintParameters(gfx::Context& context_,
@@ -72,6 +73,9 @@ mat4 PaintParameters::matrixForTile(const UnwrappedTileID& tileID, bool aligned)
7273
}
7374

7475
gfx::DepthMode PaintParameters::depthModeForSublayer(uint8_t n, gfx::DepthMaskType mask) const {
76+
if (currentLayer < opaquePassCutoff) {
77+
return gfx::DepthMode::disabled();
78+
}
7579
float depth = depthRangeSize + ((1 + currentLayer) * numSublayers + n) * depthEpsilon;
7680
return gfx::DepthMode { gfx::DepthFunctionType::LessEqual, mask, { depth, depth } };
7781
}

src/mbgl/renderer/paint_parameters.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ class PaintParameters {
104104
uint32_t currentLayer;
105105
float depthRangeSize;
106106
const float depthEpsilon = 1.0f / (1 << 16);
107-
108-
107+
uint32_t opaquePassCutoff = 0;
109108
float symbolFadeChange;
110109
};
111110

src/mbgl/renderer/render_layer.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class RenderLayer {
6666
// Returns true if the layer has a pattern property and is actively crossfading.
6767
virtual bool hasCrossfade() const = 0;
6868

69+
// Returns true if layer writes to depth buffer by drawing using PaintParameters::depthModeFor3D().
70+
virtual bool is3D() const { return false; }
71+
6972
// Returns true is the layer is subject to placement.
7073
bool needsPlacement() const;
7174

src/mbgl/renderer/render_orchestrator.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,16 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(const UpdatePar
342342
}
343343
}
344344

345-
for (auto& renderItem : layerRenderItems) {
346-
RenderLayer& renderLayer = renderItem.layer;
347-
renderLayer.prepare({renderItem.source, *imageManager, *patternAtlas, *lineAtlas, updateParameters.transformState});
345+
uint32_t i = static_cast<uint32_t>(layerRenderItems.size()) - 1;
346+
for (auto it = layerRenderItems.begin(); it != layerRenderItems.end(); ++it, --i) {
347+
RenderLayer& renderLayer = it->layer;
348+
renderLayer.prepare({it->source, *imageManager, *patternAtlas, *lineAtlas, updateParameters.transformState});
348349
if (renderLayer.needsPlacement()) {
349350
layersNeedPlacement.emplace_back(renderLayer);
350351
}
352+
if (renderLayer.is3D() && renderTreeParameters->opaquePassCutOff == 0) {
353+
renderTreeParameters->opaquePassCutOff = i;
354+
}
351355
}
352356
// Symbol placement.
353357
{

src/mbgl/renderer/render_tile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void RenderTile::prepare(const SourcePrepareParameters& parameters) {
121121
}
122122

123123
// Calculate two matrices for this tile: matrix is the standard tile matrix; nearClippedMatrix
124-
// clips the near plane to 100 to save depth buffer precision
124+
// has near plane moved further, to enhance depth buffer precision
125125
const auto& transform = parameters.transform;
126126
transform.state.matrixFor(matrix, id);
127127
transform.state.matrixFor(nearClippedMatrix, id);

src/mbgl/renderer/render_tree.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class RenderTreeParameters {
4747
TimePoint timePoint;
4848
EvaluatedLight light;
4949
bool has3D = false;
50+
uint32_t opaquePassCutOff = 0;
5051
Color backgroundColor;
5152
float symbolFadeChange = 0.0f;
5253
bool needsRepaint = false;

0 commit comments

Comments
 (0)