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:
@@ -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() {
|
||||
|
||||
@@ -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:
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user