• Unity
  • Hide Spine Sprites From Casting Shadows at Runtime?

Hi all,

I'm using a Spine animation in Unity and my floor mesh is set to receive shadows. It normally works great but sometimes there are certain sprites or animations I don't want to cast shadows. For example, once I fire a gun with the Spine animation, a "blast" sprite momentarily appears at the end of the barrel of the gun in the animation. In Unity, the Spine object's shadow now displays a shadow of that blast sprite indefinitely.

I know that I can turn shadows on and off for the entire Mesh Renderer of the Spine object, but can I simply turn off shadows for specific slots of the animated object?

Related Discussions
...

One thing to achieve this would be to use the Shadow alpha cutoff value at the material properties, so you could make the blast at least a little bit transparent (say 95%) and then adjust the Shadow alpha cutoff value to 0.95 so that the blast is discarded in the shadow pass.

Okay, I'll try that. Is the only other way to accomplish this without alpha cutoff to separate the blast animation into a separate Game Object?


I've reduced the alpha value of the slot attachment of the blast sprite to about 50% and it's still displaying a shadow. The alpha cutoff of the skeleton_Material is set to 95%. I've tried messing with the alpha cutoff of the floor material as well and it doesn't change anything.

Is the only other way to accomplish this without alpha cutoff to separate the blast animation into a separate Game Object?

No, you could also put it on another atlas page so that it will be in a second separate material. At this material you can then change shaders and shader parameters, etc.

I've reduced the alpha value of the slot attachment of the blast sprite to about 50% and it's still displaying a shadow.

What I meant was to change the alpha value in the texture, but changing slot color is also a valid approach.

Unfortunately you just discovered a bug there, the shader does not take slotcolor.alpha into account when applying the alpha cutoff. This will be fixed in the 3.8-beta branch very soon.
I have added an issue ticket here for you to track progress:
[unity] Shadow alpha cutoff ignores SlotColor.a · #1350


The issue has been fixed for all shaders in the 3.8-beta branch.

You can download the latest package from here as usual:
Spine Unity Download

In case you need the shader bugfix for 3.7, you could overwrite only the 3.7 shaders with their 3.8 counterparts in the current latest versions (May 10, 2019). Note that there are multiple Shader directories in the Spine-Unity runtime.

Alright, I'd like to be able to simply update the "Skeleton Lit" shader in the 3.7 runtime I have installed, but I'm very unfamiliar with writing/editing shaders. As per your bug tracking entry, I replaced the line:

clip(texcol.a - _Cutoff);

with the following line:

clip(texcol.a * i.vertexColor.a - _Cutoff);

I get the error "Shader error in 'Spine/Skeleton Lit': invalid subscript 'vertexColor' at line 200 (on d3d11)". I assume I need to declare the variable 'vertexColor' but I don't know how to do that. I assume its something similar to the 'texcol' declaration.