[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Public WebGL] toDataURL behavior when the WebGL drawing buffer contains invalid premultiplied alpha values



OpenGL does not enforce correctness of premultiplied alpha values in any way, so the red, green, and blue values can end up greater than the alpha value of the same pixel in a WebGL drawing buffer of a context specified with premultiplyAlpha: true. This causes odd behavior in current Firefox and Chrome, which seem to pass this invalid color data as-is to unpremultiplication if toDataURL is called. An example of this can be seen in https://www.khronos.org/registry/webgl/sdk/tests/conformance/glsl/functions/glsl-function-smoothstep-float.html - the fourth test actually renders a smooth gradient from the shader perspective, and this is what would show up if the WebGL canvas was displayed directly, but as the canvas contents get copied to a PNG image on the page the result ends up wildly different.

I propose that this would be addressed in the WebGL spec so that when toDataURL is called on a WebGL canvas that has premultiplyAlpha: true, the red, green, and blue values of each pixel must be clamped to alpha before unpremultiplying and encoding the image. A test could be added to the conformance suite as well. This would clear up any ambiguity about this matter.

-Olli
-----------------------------------------------------------
You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email:
unsubscribe public_webgl
-----------------------------------------------------------