• Runtimes
  • Unity lighting, shadows, and performance improvements

I've committed some changes for both spine-unity and spine-tk2d. There is a new shader, "Skeleton Lit" which allows your images to be affected by lights. The shaders also cast shadows now, though there is no alpha in the shadow edges. Maybe we can come up with a better way for that.

Computing normals is done much better now which was reported as a bottleneck before, so performance should be better when "calculate normals" is checked. Finally, meshes are now double buffered, which Unity says is ideal on mobile for meshes updated each frame, as ours are.

Some skeleton pron:

Image supprimée en raison de l'absence de support de HTTPS. | Afficher quand même

Image supprimée en raison de l'absence de support de HTTPS. | Afficher quand même

Image supprimée en raison de l'absence de support de HTTPS. | Afficher quand même

Related Discussions
...
  • Modifié

Thank you so much for this, it's utterly amazing. Was getting worried I wouldn't find a solution to my sprite-lighting woes.

You're awesome.

Thanks Dan! 🙂

One thing, it's using vertex lighting so it doesn't work well when the light is smaller than the distance between individual image vertices.

18 jours plus tard

Just a heads up. I was testing stuff on Android and the new Skeleton shader had this warning:

Shader is using clip instruction (usually caused by alpha test). It might cause problems on some Qualcomm/Adreno drivers.
UnityEditor.HostView😮nGUI()

probably harmless in most cases? I don't really know. Just something to note, I guess.

clip is only used for casting shadows in the Skeleton shader. Not sure if there is a better way.

3 mois plus tard

This shader doesn't seem to be casting shadows for me. Tried the default Unity demo and so far have failed miserably trying to make either the dragon or the boy to cast shadows.
Any suggestions?

I think something about the light settings and the 1:1 Spine scale prevents shadows from working.
I got cast shadows to work with the SkeletonDataAsset scaled down to 0.01 (like Unity 2D sprites), and using a directional light and enabling shadows on that directional light in the inspector.

Managed to get the goblin in the example casting shadows with your settings, Pharan. But it's a bit complicated to handle the sprite with that SkeletonData scale.
It's a bit disappointing that the shader doesn't cast shadows with point lights 🙁 But my priority right now is getting normal maps working anyway.

It's a bit complicated. But as far as I know, 1:100 scale is what Unity recommends, as its physics, default camera settings and default Sprite settings suggest. They also say so in their official videos.
To be honest, I don't like dealing with 0.01 numbers either. 1 unit : 1 pixel scale has numbers much cleaner to look at and doesn't cause weird floating point values in the Inspector.

But Unity has a lot of other things that causes it to act weird at 1:1. The physics system (both 2D and 3D) velocities cap out at I think around 100 or 300 per second. Which is just absolutely too slow for the kinds of games I like. 😃 And I think the reason why shadows don't work is because of LOD/shadow resolution caps.

That's why in the end, we just decided to go with the 0.01 scale anyway. Just don't forget that 1 Unity unit = 100 sprite pixels.

Are there other shaders that can cast shadows with point lights in Unity?

(btw, no I haven't gotten normal maps working. But I wasn't really trying it out at all anyway. I do hope to use it sometime though.)

Sure thing. By default, most of Unity shaders cast shadows with point lights as long as you are using Deferred Lighting (which is only available to Unity Pro users).
However, you can enable shadow casting with point lights on Forward lighting by adding the fullforwardshadows parameter to the shader.

For 2D sprites it requires some additional minor tweaking though. I worked on a couple of shaders that enabled normal mapping and shadows for 2DTK and Unity Sprites and for the example video I used point lights:
http://www.youtube.com/watch?v=LWrqgi3Lx-0

2 ans plus tard

Hi,

I have spine object in unity scene.

I want to add unity light so I changed the Shader to Spine/Skeleton Lit now it catches the light but it doesn't drop the shadow on 3d Plane(which catches the light as well)

any suggestions ?