deck.gl icon indicating copy to clipboard operation
deck.gl copied to clipboard

Prevent scatterplot point opacity from combining when overlapping

Open SterlingMcCall opened this issue 7 years ago • 3 comments

I am rendered a ScatterplotLayer with the following relevant properties:

new ScatterplotLayer({
  . . .
  colorFormat: 'RGB',
  opacity: 0.5,
  getColor: [255, 140, 0],
  . . .
});

This is what I am seeing: overlapping-points

What I would like is for the entire scatterplot to have the same opacity regardless of how many points overlap, so that the orange area you see would only ever be the least opaque shade you see. Essentially I want to render it as if the points on the layer were first rendered as solid colors, and then the opacity was applied to the layer as a whole. Is this possible?

This seems to be the exact opposite issue from #635 but I'm not really understanding how to change the blend mode for a single layer.

SterlingMcCall avatar Aug 26 '19 13:08 SterlingMcCall

This is tricky to solve in a general case with many overlapping transparent layers, but if you are only rendering a scattterplot you should be able to use Layer.props.parameters and set the blendEquation to GL.MAX.

new ScatterplotLayer {
  parameters: {
    blend: true,
    blendEquation: GL.MAX
  }
}

This will change how the colors are blended.

You can also try to add blendFunc: [GL.ONE, GL.ONE]

You can import the GL constants from @luma.gl/constants, see examples.

ibgreen avatar Aug 26 '19 14:08 ibgreen

@ibgreen Thanks. My understanding of blending modes is definitely lacking, but this definitely gets me going in the right direction. Your solution works pretty well, but I find that it produces darker results than what I would expect from the opacity that I am specifying.

Playing around with different values I found that this gives results closer to the opacity I was specifying, but still appears to be lighter than I would expect. I don't really understand why it works, but it gets me what I want for now. Thanks again.

new ScatterplotLayer ({
  parameters: {
    blendFunc: [GL.SRC_ALPHA, GL.CONSTANT_ALPHA]
  }
})

SterlingMcCall avatar Aug 26 '19 15:08 SterlingMcCall

@SterlingMcCall Interesting, I hadn't played with CONSTANT_* blend functions before. Turns out what you're doing is equivalent to [GL.SRC_ALPHA, GL.ZERO] because the default constant alpha is 0.

You can controls the CONSTANT_COLOR and CONSTANT_ALPHA value via the blendColor parameter, e.g.:

parameters: {
  blendColor: [0, 0, 0, 0.5]
}

tsherif avatar Aug 26 '19 19:08 tsherif