mateuszJS Posted November 9, 2020 Share Posted November 9, 2020 Hey! I'm trying to make calculations in a shader, and use all 4 channels, but unfortunately the alpha channel does not work as expected. I was thinking that if I will set gl.blendFunc(gl.ONE, gl.ZERO) then the output should be only just the source, without any blending, but it's not. So I have tried to combine it also with premultipling alpha (and keep gl.blendFunc(gl.ONE, gl.ZERO)), I get sort of closer results to the expected, but still behaviour is strange. In the demo below I'm just filling mesh with one color, and console.log values of the first pixel, was expecting [25, 178, 229, 25] but I got [255, 255, 255, 25] (without premultipled alpha) and [31, 184, 235, 25] (with premultipled alpha)https://www.pixiplayground.com/#/edit/785nGjqG5wSZoa9r2Xn7I Thank you in advance for a response! Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted November 9, 2020 Share Posted November 9, 2020 (edited) extract assumes that data in buffer is premultiplied, so it postdivides it premultiplied ok, so, your R*A = 0.1 * 0.1 , that's 0.01, that's only 2.55 if interval is 0..255, it gets rounded to just 2. Then it divides it by alpha, which is 0.1, and that's how I get red=20 in my console. Welcome to 8-bit per channel premultiplied hell Edited November 9, 2020 by ivan.popelyshev Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted November 9, 2020 Share Posted November 9, 2020 What can you do: modify extract that way it doesnt postdivide stuff. If you want to just use that renderTexture somewhere else, you can use non-premultiplied alpha and everything will be fine. mateuszJS 1 Quote Link to comment Share on other sites More sharing options...
mateuszJS Posted November 10, 2020 Author Share Posted November 10, 2020 (edited) Awesome! Thank you! Just in case if someone else will run into that issue, here is the fixed code sample https://www.pixiplayground.com/#/edit/JBJ_NTNOIwcxv64JdNMZE Output from the fragment shader are not premultipled by alpha Created function extractPixelsWithoutPostdivide, it's just copy of https://github.com/pixijs/pixi.js/blob/068e0af7f2851c51618b463b7fccc555e6ffb4b0/packages/extract/src/Extract.ts#L192 but with removed Extract.arrayPostDivide(webglPixels, webglPixels); Edited November 10, 2020 by mateuszJS Typo ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.