Conversation
- alpha of background should not affect foreground - more consistent handling of alpha cutout behavior for opaque blending
|
@matteblair It looks like the same issue described in #741 also exists in Tangram ES (because it looks like it more or less copies the previously faulty Tangram JS logic... 😅). I took a couple stabs at fixing it, and found some other edge cases (the alpha cutout test was too early, causing inconsistent alpha handling depending on texture + blend mode combinations), and found it easier to just revamp to the logic in this PR, which hopefully is clearer (but using nested We should open a corresponding issue to #741 for ES as well. |
|
Actually, I don't think Tangram ES suffers from the same specific behavior reported in #741, current logic here: https://github.com/tangrams/tangram-es/blob/master/core/shaders/polyline.fs#L67-L82 But, I still think it has related issues, particularly with the order of the alpha cutout test vs. the tinting (vertex color multiplied by line texture color), and would benefit from a review in conjunction with this PR. |
|
Hey @matteblair, any further thoughts here? I'd like to cut a minor release with @meetar's geojson-vt upgrade. I tried to be complete with the logic description in the PR, but the actual shader code is pretty concise ;) |
matteblair
left a comment
There was a problem hiding this comment.
Looks good!
I checked this out in Tangram ES too and there's a similar problem, so I applied the same logic implemented here (see tangrams/tangram-es#2137, though there are minor differences because Tangram ES still only has dash defined per-style).
This PR revamps the logic for applying line dash patterns and textures. The prior logic had some holes and inconsistencies, including #741. It implements the following logic in the fragment shader for lines (and also replaces some conditional
if/elseshader branching with nestedmixfunctions):dashpattern (the texture is automatically generated from the dash pattern).colorparameter, available in the shader as the vertexcolor) and background color (via thedash_background_colorparameter, available in the fragment shader asu_dash_background_color).textureparameter (instyleordrawgroup).u_has_dashindicates this, with a float value of0or1.mixfunction controlled by the line texture alpha channel (following the monochrome texture described above).mix(u_dash_background_color, color, _line_color.a), // choose dash foreground or background colorcolorto the texture color ("tinting" it), consistent with other similar behaviors, e.g. raster textures on polygons.color * _line_color, // no dash: tint the line texture with the vertex colormixfunction, controlled by theu_has_dashuniform described above.opaqueblending is active, a simple "alpha cutout" behavior is applied, in which any alpha pixel with an alpha of less than 0.5 (TANGRAM_ALPHA_TEST) is discarded. This enables basic transparency-like behavior for dashes and textures when using opaque blending.