Skip to content

Conversation

@ansis
Copy link
Contributor

@ansis ansis commented May 10, 2014

Partial support for blending layers with compositing operations.

The layer looks like this:

{
    "id": "somecompositedlayer",
    "base": layerGroup,
    "layers": layerGroup
}

The layerGroup layers is blended on top of base.

And the style:

"somecompositedlayer": {
    "comp-op": "hard-light"
}

Two comp-ops are exposed right now: hard-light and multiply.

More are implemented in the shader, but the way they are exposed right now involves compiling a separate shader for each one. This means we'll need to:

  • add support for lazily initializing shaders. We don't want to initialize 30 when most aren't used.
  • skip running shaders through the optimizer so that macros are evaluated in the browser. This would let us initialize multiple shaders from one source text.

Should we drop having base explicitly specified, and instead use all the layers below it in the style?

@mourner
Copy link
Member

mourner commented May 10, 2014

Awesome!

Not sure we want to complicate the style format with the concept of "base" layers though. Moreover we're trying to get on parity with Mapnik here, and the styles there just blend over layers below it, right?

@edenh
Copy link
Contributor

edenh commented May 11, 2014

This is great!

I'm imagining one potential option where the blend only gets applied within the specified 'layer group'.

{"layers": [
    {"id": "one"},
    {
        "id": "two",
        "layers": [
            {"id": "three"},
            {"id": "four"}
        ]
    },
    {"id": "five"}
],
"styles": {
    "three": {"comp-op": "multiply"},
    "five": {"comp-op": "multiply"}
}}

If a layer is within a composite, the comp-op gets applied to all layers under it within that group (ie. applied to "four" only affects "three"). If the layer with the comp-op is not within a composite group or the comp-op is applied to the composite layer itself, the comp-op is applied to all layers beneath it (ie. applied to "five" affects all). This is similar to how photoshop blend modes work.

Not sure if that makes sense or if I'm understanding this correctly. Either way, I like the idea of removing the base layer complexity.

@mourner
Copy link
Member

mourner commented May 12, 2014

@edenh yes, I think this is the right way they should work implicitly — makes perfect sense.

@mourner
Copy link
Member

mourner commented May 26, 2014

@ansis any updates?

@ansis
Copy link
Contributor Author

ansis commented Jun 23, 2014

Not sure we want to complicate the style format with the concept of "base" layers though. Moreover we're trying to get on parity with Mapnik here, and the styles there just blend over layers below it, right?

I think we should introduce base into the style, because it's closer to how the rendering actually works. The implementation renders two separate groups and then blends them together. If we don't have it this way in the style, we'd need to automatically group layers when processing the style. Having to explicit specify base makes some uses more awkward, but I think that's ok. comp-op use should be careful and infrequent.

@mourner
Copy link
Member

mourner commented Jun 23, 2014

@ansis when you define a composite layer that specifies some base, is the place of this base layer within the layer structure irrelevant and gets superseded because it's drawn only as a part of composite?

@ansis
Copy link
Contributor Author

ansis commented Jun 23, 2014

and gets superseded because it's drawn only as a part of composite

I'm not sure I understand what you're asking.

When its time to render the blended layer, it first renders both child layer groups into separate, blank textures. It blend the two together and draws the result onto the main canvas. Both layer groups are only used within the blended layer.

@mourner
Copy link
Member

mourner commented Jun 23, 2014

Oh, I misunderstood the sample config. It's clear now.

@mourner
Copy link
Member

mourner commented Jun 23, 2014

OK, I thought about this in context of a real style (outdoors) and now I see what's the issue. If it works magically and you're not careful, it's very easy to screw up the performance. Explicit compositing makes it much harder to do this. So good to merge from me 👍

@mourner mourner added this to the v1.0.0 milestone Jun 24, 2014
This was referenced Jun 24, 2014
@mourner mourner modified the milestones: future, v0.1.0 Jul 1, 2014
@yhahn yhahn closed this Jul 9, 2014
@yhahn yhahn mentioned this pull request Jul 9, 2014
@ansis ansis deleted the blend branch August 13, 2014 23:02
@georgbachmann
Copy link

As I'd also love to see blend modes for my own hill-shading layer...
Can somebody give me a quick update? It's still not possible, right? Is it because of performance I guess? Will we see blend modes in the future? Are there any updates about is?
Would be cool if somebody could bring me up to date :)

@AbelVM
Copy link

AbelVM commented Jul 8, 2020

Any news on getting comp-op back to life? If luma.gl can do it, MapboxGL can do it too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants