Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
renderTexture->saveToFile() bugged for image alpha values #18193
Steps to Reproduce:
Take any image that has transparent pixels in it and try to save it as a png using renderTexture. The transparent pixels will get added with the background color of the renderTexture despite setting the background's alpha channel to zero with clear(0,0,0,0). Below is the code I used:
So in the above case because I cleared with rgba(0,0,0,0), my transparent pixels will end up being darker. One would assume that having an alpha of zero shouldn't change the image at all.
I posted an example image on the forums:
Just want to assume this bug and add something.
Create a simple HelloWorld project add transparent image bellow and add this code.
I have this scene:
Result rendered image of this scene:
Take a closer look:
Notice that not only transparent image but text has some artefacts.
Add this code on top of code posted before:
Result of rendered image compare to actual scene with gradient:
Left - rendered. Right - actual scene.
Notice - rendered gradient is different than actual saved file.
It’s like has some transparency where it should’t have. Top of gradient isn’t transparent, but on rendered image - it’s transparent:
The default blend function of Sprite is BlendFunc::ALPHA_NON_PREMULTIPLIED, which will blend with background. So you should change the blend function before visit, such as
And you may change to default blend function after rendering into render texture. Because
@minggo If I have a design in my game so I can't change
Just simple fact: I’m using RenderTexture for some sprites and got artifacts on final image.
@minggo any comments? I can't change
upd: even with just tested 1 sprite with mask, I'm getting this bug. Disable blend not helped me.
Other developers faced this same problem, see details in this post: