Skip to content
This repository has been archived by the owner on Apr 10, 2018. It is now read-only.

Add a per-layer opacity property #273

Closed
nickidlugash opened this issue Mar 25, 2015 · 14 comments
Closed

Add a per-layer opacity property #273

nickidlugash opened this issue Mar 25, 2015 · 14 comments

Comments

@nickidlugash
Copy link
Contributor

Background: mapbox/mapbox-gl-js#859 (comment)

Is this currently possible for JS/native to render (or will it ever be)?

Useful for layers that are designed to have overlapping geometries, such as all the layers in Mapbox Terrain.

@nickidlugash
Copy link
Contributor Author

It looks like the current opacity properties have switched to per-geometry. So I guess the new question is: can we add a per-layer opacity property? Useful for tunnels on basemaps:

screen shot 2015-03-31 at 5 33 36 pm

@samanpwbb @ajashton Any thoughts?

@ansis @kkaefer is this feasible?

@samanpwbb
Copy link
Contributor

What if setting RGBA fill/stroke was per-feature while setting Opacity was per layer?

Both per-feature and per-layer are important, but if I had to pick one I'd pick per-layer (to avoid the kinds of problems you can see in the screenshot above).

@nickidlugash
Copy link
Contributor Author

What if setting RGBA fill/stroke was per-feature while setting Opacity was per layer?

This seems like a good idea for me. I don't currently tend to use a lot of RGBA values, but this might make more sense than implementing two different opacity properties for each layer type.

@kkaefer
Copy link
Contributor

kkaefer commented Apr 2, 2015

Per-layer and per-feature alpha values are hard to implement; a per-layer alpha value means that we'd have to render to a buffer first, then composite onto the main framebuffer.

@nickidlugash
Copy link
Contributor Author

Per-layer and per-feature alpha values are hard to implement; a per-layer alpha value means that we'd have to render to a buffer first, then composite onto the main framebuffer.

@kkaefer does this mean that having a per-layer opacity property would take a lot of time/energy but is doable, or that it's something you don't think we should consider doing at all?

@ansis
Copy link
Contributor

ansis commented May 1, 2015

We could implement per-layer alpha by just using the depth buffer to prevent double drawing. We would have to draw lines with two calls so that we can draw the solid part first and the antialiasing second. It wouldn't be exactly the same as carto if you have both per-layer and feature-level opacity, but this case doesn't seem that important.

@nickidlugash nickidlugash changed the title Add a per-geometry opacity property? Add a per-layer opacity property? May 22, 2015
@jfirebaugh
Copy link
Contributor

Can someone define what "per-layer" opacity means precisely? Or with an example? E.g. if you have a layer with a red triangle at 50% opacity on top of a blue square at 50% opacity, with a "layer opacity" of 50%, how is that supposed to render?

@nickidlugash
Copy link
Contributor Author

@jfirebaugh I think like this (although I'm not sure I'm rendering @ansis's suggestion correctly):

screen shot 2016-06-28 at 11 25 49 am

/cc @samanpwbb

@samanpwbb
Copy link
Contributor

samanpwbb commented Jun 28, 2016

Yep, what @nickidlugash said. I would expect the cartoCSS behavior rather than Ansis's suggested implementation in cases where there is both per-layer and per-feature opacity. Here's an example with strokes that illustrates how per-layer opacity might be preferable:

screen shot 2016-06-28 at 11 32 59 am

@jfirebaugh
Copy link
Contributor

Thank you, those examples are great.

I believe the annotations here are correct:

image

The cartoCSS behavior is the one that requires composited rendering (rendering the layer first to a buffer, then compositing that layer with the scene using the layer-wide opacity).

@ajashton
Copy link
Member

Normally it's not really necessary to have both per-object and per-layer opacity on the same layer, just one or the other. So if we can't fully replicate the Mapnik behavior then that's fine, just these two are key:

screenshot-2016-06-28-12 23 15

@jfirebaugh
Copy link
Contributor

With data-driven styling it's already possible to set a different fill-color rgba value for each feature. So it's pretty awkward to prohibit per-feature opacity.

@ezheidtmann
Copy link

It looks like this is now implemented for fill layers via the fill-opacity paint property. Is there any way to do this for line layers? The line-opacity property seems to set a per-geometry opacity, at least in js v0.23.0.

@lucaswoj lucaswoj changed the title Add a per-layer opacity property? Add a per-layer opacity property Dec 22, 2016
@lucaswoj
Copy link

lucaswoj commented Feb 1, 2017

This issue was moved to mapbox/mapbox-gl-js#4090

@lucaswoj lucaswoj closed this as completed Feb 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants