Webgl / clarify premultiplied alpha handling

By default, alpha premultiplying should be done by the initial rendering
(eg quads) and not the final post processing pass.

The default post processing pass expects premultiplied color values and
will not do this operation itself.
This commit is contained in:
Olivier Guyot
2019-04-02 22:12:45 +02:00
parent b955579a9c
commit c6a859d1ed
3 changed files with 5 additions and 5 deletions

View File

@@ -238,7 +238,7 @@ class Heatmap extends VectorLayer {
float sqRadius = texCoord.x * texCoord.x + texCoord.y * texCoord.y;
float value = (1.0 - sqrt(sqRadius)) * u_blurSlope;
float alpha = smoothstep(0.0, 1.0, value) * v_opacity;
gl_FragColor = vec4(1.0, 1.0, 1.0, alpha);
gl_FragColor = vec4(alpha, alpha, alpha, alpha);
}`,
uniforms: {
u_size: function() {

View File

@@ -110,8 +110,7 @@ const FRAGMENT_SHADER = `
*
* The following uniform is used for the main texture: `u_texture`.
*
* Please note that the main shader output should have premultiplied alpha, otherwise the colors will be blended
* additively.
* Please note that the main shader output should have premultiplied alpha, otherwise visual anomalies may occur.
*
* Points are rendered as quads with the following structure:
*

View File

@@ -28,7 +28,6 @@ const DEFAULT_FRAGMENT_SHADER = `
void main() {
gl_FragColor = texture2D(u_image, v_texCoord);
gl_FragColor.rgb *= gl_FragColor.a;
}
`;
@@ -59,6 +58,9 @@ const DEFAULT_FRAGMENT_SHADER = `
* a pixel which is 100% red with an opacity of 50% must have a color of (r=0.5, g=0, b=0, a=0.5).
* Failing to provide pixel colors with premultiplied alpha will result in render anomalies.
*
* The default post-processing pass does *not* multiply color values with alpha value, it expects color values to be
* premultiplied.
*
* Default shaders are shown hereafter:
*
* * Vertex shader:
@@ -91,7 +93,6 @@ const DEFAULT_FRAGMENT_SHADER = `
*
* void main() {
* gl_FragColor = texture2D(u_image, v_texCoord);
* gl_FragColor.rgb *= gl_FragColor.a;
* }
* ```
*