- Modifié
[Unity3d/tk2d] Alpha color animation
Hello, I have the problem of alpha animation.
There are a lot of objects on the scene, which hide after some player actions with alpha changing (fade in/fade out).
So, while alpha changes (in spine editor) everything is ok, but when the animation runs in unity editor (and on mobile devices), the alpha animation looks black colored. I attached screenshots
The left image - it's standart tk2dSprite with changed alpha (looks like normal alpha)
The right image - spine's SkeletonAnimation with changed alpha (looks like bad black-colored alpha)
The atlas of that rock image is the same, the material is the same and the shader is the same (tk2d/BlendVertexColor). It's not the worst pic I ever had. When I try to show/hide with alpha more complex objects (with 10+ bones) the image looks worse like big transparent black-colored spot.
Any ideas how to fix that?
ping
Any thoughts? suggestions?
I can't say if this is related, but are you packing your textures with "Premultiply" on or off ? Try going into Texture Packer settings in Spine and check "Premultiply" if you haven't done so already.
You can read more about it here viewtopic.php?p=4233#p4233
I will try it.
All my images are PNG, and making the whole atlas with Premultiply "on" makes some images with lots of alpha look with kind of gray-colored. Well, I will try to make them look normally
I believe that if you export with premultiply you also have to set up Unity to use it. I'm not super familiar with Unity though.
I just fixed this, by editing from
color.r = (byte)(r * slot.R * color.a);
color.g = (byte)(g * slot.G * color.a);
color.b = (byte)(b * slot.B * color.a);
to
color.r = (byte)(r * slot.R * 255);
color.g = (byte)(g * slot.G * 255);
color.b = (byte)(b * slot.B * 255);
in SkeletonComponent.cs
I think that this will not work for people who use premultiply, but not sure
The final fix should be the similar, I think
byte aColor = (skeletonDataAsset.spriteCollection.premultipliedAlpha) ? color.a : (byte)255;
color.r = (byte)(r * slot.R * aColor);
color.g = (byte)(g * slot.G * aColor);
color.b = (byte)(b * slot.B * aColor);
It's suggested to use premultiplied alpha to have proper blending.