- Edited
Fade to White
Hi, I'm fairly new to Spine/Unity so please bear with me.
Basically all I am trying to do is create a fade to white animation. I know that Spine uses multiply for color blending (the same as the standard sprite shader), but the default spine shader has no color property (like the sprite one does) so I don't really know how it works (I more or less understand this http://answers.unity3d.com/questions/709687/shader-to-flash-a-2d-sprite-to-white.html). Anyway I've looked through the code to see where I could attempt to brute-force the colors, but really I'm just getting lost.
I came across this post: http://esotericsoftware.com/forum/Custom-Material-Shader-on-Spine-Animation-5906?p=27321&hilit=white#p27321 however I can't get the .zip attachment to import into unity for whatever reason (I know how to import .unitypackages but I don't get one from that zip on my mac).
I'm really after the path of least resistance here, I don't need much flexibility, it just has to fade to white while the running animation is also occurring (I have fading out using alpha values right now, but the designer is not happy with that ).
Thanks in advance!
Custom Material / Shader on Spine Animation
I'm not sure why OSX goes nuts trying to read that zip.
This is the shader code for SkeletonFillable.shader
:
// - Unlit + no shadow
// - Premultiplied Alpha Blending (One OneMinusSrcAlpha)
// - Double-sided, no depth
Shader "Spine/Skeleton Fillable" {
Properties {
_FillColor ("FillColor", Color) = (1,1,1,1)
_FillPhase ("FillPhase", Range(0, 1)) = 0
[NoScaleOffset]_MainTex ("MainTex", 2D) = "white" {}
}
SubShader {
Tags { "IgnoreProjector"="True" "Queue"="Transparent" "RenderType"="Transparent" "PreviewType"="Plane" }
LOD 100
Blend One OneMinusSrcAlpha
Cull Off
ZWrite Off
Lighting Off
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform float4 _FillColor;
uniform float _FillPhase;
struct VertexInput {
float4 vertex : POSITION;
float2 texcoord0 : TEXCOORD0;
float4 vertexColor : COLOR;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
float4 vertexColor : COLOR;
};
VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput)0;
o.uv0 = v.texcoord0;
o.vertexColor = v.vertexColor;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
float4 frag (VertexOutput i) : COLOR {
float4 rawColor = tex2D(_MainTex,i.uv0);
float finalAlpha = (rawColor.a * i.vertexColor.a);
float3 finalColor = lerp((rawColor.rgb * i.vertexColor.rgb), (_FillColor.rgb * finalAlpha), _FillPhase);
return fixed4(finalColor, finalAlpha);
}
ENDCG
}
}
FallBack "Diffuse"
}
Just follow the directions from the thread.
Essentially, just set the _FillColor to Color.white and animate the Material's _FillPhase property.
_FillPhase 0 means it will look normal.
_FillPhase 1 means it will be completely filled with the color assigned to _FillColor.
Animating it from 0 to 1 will make it fade to white.
Two color tinting in v3.6 may also do what you need.
@[deleted]
Not really. Skeleton doesn't have a 2nd color set. Adding it would also mean slowing down the renderer for everyone.
True, skeleton doesn't have a second color. However, you could set the Slot darkColor
for every slot in the skeleton, starting from black and transitioning to white over time. If you were already using two color tinting for something, this could interfere.