tangrams / tangram

WebGL map rendering engine for creative cartography
https://tangram.city
MIT License
2.22k stars 290 forks source link

Optional `alpha` parameter for `draw` groups #740

Closed bcamper closed 4 years ago

bcamper commented 4 years ago

This PR adds a new alpha parameter inside several draw group contexts. It allows the scene author to set only the alpha channel of a color, independently of the RGB channels.

Use cases where this is helpful include:

Syntax

bcamper commented 4 years ago

It's possible the alpha support for font fill and stroke is overkill, though it led to me having some fun with fonts... :D

bcamper commented 4 years ago

cc @matteblair @meetar @sensescape @burritojustice @nvkelso @tallytalwar for comment.

meetar commented 4 years ago

@bcamper Looks great from here! Couple of questions about the PR description:

In cases where a color value is required, the alpha parameter has no effect if no color is specified.

This is because nothing will draw, correct? So this line is clarifying that there won't be some kind of default color applied in order to apply an alpha to it.

If a sub-layer sets alpha: null, it un-sets any value set by an ancestor layer. The color's alpha channel returns to its original, unmodified value.

Are there cases where the "original unmodifed value" could be something other than 1.0?

bcamper commented 4 years ago

@meetar:

In cases where a color value is required, the alpha parameter has no effect if no color is specified.

This is because nothing will draw, correct? So this line is clarifying that there won't be some kind of default color applied in order to apply an alpha to it.

Yep, that's right, feel free to help clarify the language if you have suggestions.

If a sub-layer sets alpha: null, it un-sets any value set by an ancestor layer. The color's alpha channel returns to its original, unmodified value.

Are there cases where the "original unmodifed value" could be something other than 1.0?

For sure! Any time color sets an alpha already, like this:

depth1:
  draw:
    points:
      color: [1, 0, 0, 0.25] # renders at 25% opacity

  depth2:
    draw:
      points:
        alpha: 0.5 # overrides color, renders at 50% opacity

    depth3:
      draw:
        points:
          alpha: null # back to the original 25% opacity

I should have put in an example where it is very explicitly overriding, even at one level, like:

  draw:
    points:
      color: [1, 0, 0, 0.25]
      alpha: 0.5 # overrides color, features will render w/50% opacity

Basically, whenever alpha is present, it overrides the color alpha. All the other behavior, including the alpha: null "un-set", falls out of the regular draw group and import merging (because an explicitly set null gets merged on top of others, like any other value).

tallytalwar commented 4 years ago

Again, 👏 on the great description @bcamper. Sorry couldn't jump on this before. But looks good to me too.