diff --git a/include/mbgl/renderer/layer_tweaker.hpp b/include/mbgl/renderer/layer_tweaker.hpp index 91871893b..b533fcd35 100644 --- a/include/mbgl/renderer/layer_tweaker.hpp +++ b/include/mbgl/renderer/layer_tweaker.hpp @@ -62,6 +62,13 @@ protected: /// Determine whether this tweaker should apply to the given drawable bool checkTweakDrawable(const gfx::Drawable&) const; + /// Multiplies with the projection matrix (either default, near clipped or aligned) for the given drawable + static void multiplyWithProjectionMatrix(/*in-out*/ mat4& matrix, + const PaintParameters& parameters, + const gfx::Drawable& drawable, + bool nearClipped, + bool aligned); + std::string id; Immutable evaluatedProperties; diff --git a/metrics/android-render-test-runner/render-tests/combinations/fill-opaque--image-translucent/metrics.json b/metrics/android-render-test-runner/render-tests/combinations/fill-opaque--image-translucent/metrics.json new file mode 100644 index 000000000..8ed0fcb07 --- /dev/null +++ b/metrics/android-render-test-runner/render-tests/combinations/fill-opaque--image-translucent/metrics.json @@ -0,0 +1,35 @@ +{ + "network": [ + [ + "probeNetwork - default - end", + 1, + 48979 + ], + [ + "probeNetwork - default - start", + 0, + 0 + ] + ], + "gfx": [ + [ + "probeGFX - default - end", + 13, + 11, + 19, + 1, + [ + 1298436, + 1298436 + ], + [ + 318, + 318 + ], + [ + 236, + 236 + ] + ] + ] +} \ No newline at end of file diff --git a/metrics/cache-style.db b/metrics/cache-style.db index e26cc7689..b24c05547 100644 Binary files a/metrics/cache-style.db and b/metrics/cache-style.db differ diff --git a/metrics/integration/image/radar2.png b/metrics/integration/image/radar2.png new file mode 100644 index 000000000..8209fa0f9 Binary files /dev/null and b/metrics/integration/image/radar2.png differ diff --git a/metrics/integration/render-tests/combinations/fill-opaque--image-translucent/expected.png b/metrics/integration/render-tests/combinations/fill-opaque--image-translucent/expected.png new file mode 100644 index 000000000..a2e525d05 Binary files /dev/null and b/metrics/integration/render-tests/combinations/fill-opaque--image-translucent/expected.png differ diff --git a/metrics/integration/render-tests/combinations/fill-opaque--image-translucent/style.json b/metrics/integration/render-tests/combinations/fill-opaque--image-translucent/style.json new file mode 100644 index 000000000..3fde0be5a --- /dev/null +++ b/metrics/integration/render-tests/combinations/fill-opaque--image-translucent/style.json @@ -0,0 +1,109 @@ +{ + "version": 8, + "metadata": { + "test": { + "width": 456, + "height": 456 + } + }, + "center": [ + -75.9705, + 42.1865 + ], + "zoom": 5, + "sources": { + "image": { + "type": "image", + "url": "local://image/radar2.png", + "coordinates": [ + [ + -80.425, + 46.437 + ], + [ + -71.516, + 46.437 + ], + [ + -71.516, + 37.936 + ], + [ + -80.425, + 37.936 + ] + ] + }, + "geojson": { + "type": "geojson", + "data": { + "type": "Polygon", + "coordinates": [ + [ + [ + -80.425, + 46.437 + ], + [ + -71.516, + 46.437 + ], + [ + -71.516, + 37.936 + ], + [ + -80.425, + 37.936 + ], + [ + -80.425, + 46.437 + ] + ], + [ + [ + -78.425, + 44.437 + ], + [ + -78.425, + 39.936 + ], + [ + -73.516, + 39.936 + ], + [ + -73.516, + 44.437 + ], + [ + -78.425, + 44.437 + ] + ] + + ] + } + } + }, + "layers": [ + { + "id": "fill-opaque", + "type": "fill", + "source": "geojson", + "paint": { + "fill-color": "blue" + } + }, + { + "id": "image-translucent", + "type": "raster", + "source": "image", + "paint": { + "raster-fade-duration": 0 + } + } + ] +} \ No newline at end of file diff --git a/metrics/linux-gcc8-release/render-tests/combinations/fill-opaque--image-translucent/metrics.json b/metrics/linux-gcc8-release/render-tests/combinations/fill-opaque--image-translucent/metrics.json new file mode 100644 index 000000000..8ed0fcb07 --- /dev/null +++ b/metrics/linux-gcc8-release/render-tests/combinations/fill-opaque--image-translucent/metrics.json @@ -0,0 +1,35 @@ +{ + "network": [ + [ + "probeNetwork - default - end", + 1, + 48979 + ], + [ + "probeNetwork - default - start", + 0, + 0 + ] + ], + "gfx": [ + [ + "probeGFX - default - end", + 13, + 11, + 19, + 1, + [ + 1298436, + 1298436 + ], + [ + 318, + 318 + ], + [ + 236, + 236 + ] + ] + ] +} \ No newline at end of file diff --git a/src/mbgl/renderer/layer_tweaker.cpp b/src/mbgl/renderer/layer_tweaker.cpp index 2158661c5..2c1b7701d 100644 --- a/src/mbgl/renderer/layer_tweaker.cpp +++ b/src/mbgl/renderer/layer_tweaker.cpp @@ -32,7 +32,7 @@ mat4 LayerTweaker::getTileMatrix(const UnwrappedTileID& tileID, style::TranslateAnchorType anchor, bool nearClipped, bool inViewportPixelUnits, - [[maybe_unused]] const gfx::Drawable& drawable, + const gfx::Drawable& drawable, bool aligned) { // from RenderTile::prepare mat4 tileMatrix; @@ -40,24 +40,7 @@ mat4 LayerTweaker::getTileMatrix(const UnwrappedTileID& tileID, if (const auto& origin{drawable.getOrigin()}; origin.has_value()) { matrix::translate(tileMatrix, tileMatrix, origin->x, origin->y, 0); } - - // nearClippedMatrix has near plane moved further, to enhance depth buffer precision - auto projMatrix = aligned ? parameters.transformParams.alignedProjMatrix - : (nearClipped ? parameters.transformParams.nearClippedProjMatrix - : parameters.transformParams.projMatrix); - -#if !MLN_RENDER_BACKEND_OPENGL - // If this drawable is participating in depth testing, offset the - // projection matrix NDC depth range for the drawable's layer and sublayer. - if (!drawable.getIs3D() && drawable.getEnableDepth()) { - projMatrix[14] -= ((1 + drawable.getLayerIndex()) * PaintParameters::numSublayers - - drawable.getSubLayerIndex()) * - PaintParameters::depthEpsilon; - } -#endif - - matrix::multiply(tileMatrix, projMatrix, tileMatrix); - + multiplyWithProjectionMatrix(/*in-out*/ tileMatrix, parameters, drawable, nearClipped, aligned); return RenderTile::translateVtxMatrix( tileID, tileMatrix, translation, anchor, parameters.state, inViewportPixelUnits); } @@ -67,4 +50,31 @@ void LayerTweaker::updateProperties(Immutable newProps) propertiesUpdated = true; } +void LayerTweaker::multiplyWithProjectionMatrix(/*in-out*/ mat4& matrix, + const PaintParameters& parameters, + [[maybe_unused]] const gfx::Drawable& drawable, + bool nearClipped, + bool aligned) { + // nearClippedMatrix has near plane moved further, to enhance depth buffer precision + const auto& projMatrixRef = aligned ? parameters.transformParams.alignedProjMatrix + : (nearClipped ? parameters.transformParams.nearClippedProjMatrix + : parameters.transformParams.projMatrix); +#if !MLN_RENDER_BACKEND_OPENGL + // If this drawable is participating in depth testing, offset the + // projection matrix NDC depth range for the drawable's layer and sublayer. + if (!drawable.getIs3D() && drawable.getEnableDepth()) { + // copy and adjust the projection matrix + mat4 projMatrix = projMatrixRef; + projMatrix[14] -= ((1 + drawable.getLayerIndex()) * PaintParameters::numSublayers - + drawable.getSubLayerIndex()) * + PaintParameters::depthEpsilon; + // multiply with the copy + matrix::multiply(matrix, projMatrix, matrix); + // early return + return; + } +#endif + matrix::multiply(matrix, projMatrixRef, matrix); +} + } // namespace mbgl diff --git a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp index bd0e3c7f7..3f7655731 100644 --- a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp @@ -55,8 +55,9 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, // this is an image drawable if (const auto& data = drawable.getData()) { const gfx::ImageDrawableData& imageData = static_cast(*data); - matrix = imageData.matrix; + multiplyWithProjectionMatrix( + /*in-out*/ matrix, parameters, drawable, /*nearClipped*/ false, /*aligned*/ true); } else { Log::Error(Event::General, "Invalid raster layer drawable: neither tile id nor image data is set."); return; diff --git a/src/mbgl/renderer/sources/render_image_source.cpp b/src/mbgl/renderer/sources/render_image_source.cpp index 6c23c386c..f860e0316 100644 --- a/src/mbgl/renderer/sources/render_image_source.cpp +++ b/src/mbgl/renderer/sources/render_image_source.cpp @@ -101,7 +101,9 @@ void RenderImageSource::prepare(const SourcePrepareParameters& parameters) { mat4& matrix = matrices[i]; matrix::identity(matrix); transformParams.state.matrixFor(matrix, tileIds[i]); +#if MLN_LEGACY_RENDERER matrix::multiply(matrix, transformParams.alignedProjMatrix, matrix); +#endif } renderData = std::make_unique(bucket, std::move(matrices), baseImpl->id); }