Additive blending of layers without using alpha

I'd like to colorize two grayscale layers with two constant colors and then blend them additively. I understand that blending can be done via setting an alpha value on the ImageryLater, but this will result in the output pixel being weighed by the respective alpha values, i.e. OUTPUT_RGB = alpha * SOURCE_RGB + (1 - alpha) * DESTINATION_RGB.
I'd rather have it blended as OUTPUT_RGB = SOURCE_RGB + DESTINATION_RGB. Furthermore, the source color (SOURCE_RGB), i.e. the color of some layer's pixels, should be multiplied by a constant color (for example red), so that the layer's grayscale pixels will colorized.

In another application that used openlayers3 as its mapping framework, I managed to achieve this effect by providing a callback function that was called by the framework right before each rendering step. This callback was called for each layer separately. Using this hook, setting the following parameters worked:

var colorizationColor = [1, 0, 0]; // red
gl.BlendEquation(gl.FUNC_ADD);
gl.blendColor(colorizationColor[0], colorizationColor[1], colorizationColor[2], 1);
gl.blendFunc(gl.CONSTANT_COLOR, gl.ONE); // multiply source color with above color, destination color with 1

and then in a similar callback that was called by the framework after the rendering for this layer was done, I reset the blending parameters to their default value.

My question is if something like this is possible in any way without directly modifying the source code? And if not, where the best place for such a modification would be.

Many thanks!

Hi,

Unfortunately, no, an approach like that won’t work in Cesium. That’s because Cesium issues a single WebGL draw command per terrain tile, no matter how many imagery layers are drawn on that terrain tile. It’s theoretically possible to modify that fragment shader (GlobeFS.glsl) to do what you want, but I don’t know of any way to do it without making changes to Cesium itself.

I can imagine an extension to Cesium that allows user-defined blending, expressed maybe as GLSL or as something like Cesium’s Material system. But there are no current plans to implement something like that.

Kevin