godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91k stars 21.17k forks source link

alpha Shaders on sprites cause weird issues #38419

Open blazelink3 opened 4 years ago

blazelink3 commented 4 years ago

Godot version: 3.2.1 OS/device including version: Windows 10 Issue description: As title Suggests, editing the alpha values on a sprite with a shader causes the sprite to stretch out oddly, as seen below, as well as losing previous transparency values

image

to recreate, simply specify COLOR.a to be any valid value

clayjohn commented 4 years ago

Could you maybe provide a picture of what the sprite should look like? I can't tell what the issue is from your description.

Zylann commented 4 years ago

What you are seeing is a PNG where pixels that normally are invisible due to their alpha being zero have had their colors compressed away. Many PNGs are encoded this way, and it's the default of all image editors I know. If you bring back alpha to 1 with a shader, you then see garbage.

If you want RGB channels to not be compressed, you have to configure that in the image editor you used to make this image (if you made it).

Example in Gimp: image

However it looks like you just wanted to animate alpha, so what you should do is to modulate existing alpha, rather than outputting values > 0 even for pixels that are originally fully transparent.

COLOR.a = COLOR.a * custom_alpha;