• Unity
  • Sprite Shaders for Unity

Hey AlaNintendo!

I have noticed spikes in the editor when you turn on/off features on a material for the first time. I haven't experienced them at run time though - looking a the profiler it looks like its the editor compiling a new version of the shader when defines get enabled / disabled. Thats taking 1131ms for me which is a bit scary!

图像因不支持 HTTPS 被隐藏。 | 仍然显示

I suspect I've either done something stupid or gone over the shader keyword limit or something.
Once the shader is compiled there should be no more spikes though (so shouldn't effect performance apart from in the editor)
Is your spike happening whilst playing? It strange it looks like its calling shader.editorloadvariant - the way I thought Unity worked was it makes a compiled version of your shader beforehand.... maybe i need to do something to make unity spit out variants properly when it builds:
https://blogs.unity3d.com/2014/05/06/shader-compilation-in-unity-4-5/

9 天 后

Hi ToddRivers,

I believe it's just lagging while in editor. My builds lag on occasion, but that may be because of other problems with my own code haha..

But just wanted to give you a heads up on what I was experiencing, in regards to your shader. 🙂

Thanks again for this. It's been a really awesome shader for Spine!

Hi @ToddRivers,

I'm keeping up with the updates and keep thanking you for creating these shaders.

Is there any chance you could add support for simple offset-shadows to the ubershader (or maybe also an outline?), as part of the ubershader, or as a separate single-coloured-shadow-shader, maybe with some configurable edge blurring that also supports fading the skeleton shadow as a whole (an alpha value for the whole skeleton, not made by overlaying each bone's alpha: i.e.: like a real shadow?)

I remember to have seen something like a skeleton trail FX but can't remember where, and if the trail was actually revealing each bone's borders when fading or was faded as a whole.

If it's not available right now, and you're available to work on it, I'd happily donate to have this feature 🙂 (working on mobile, I suppose some multiple passes could be needed, but I would be using this for the main chars only)

Cheers,
Alessandro Salvati

11 天 后

Hey! Added a little update which I think was requested a while ago - scaling for normal maps (I noticed Unity added it into their standard shader so just copied that code) that means you can tweak how bumpy your bump map is in the shader 🙂

As far as my normal map flow I use SpriteIlluminator to create my normal maps. I'm still paying around with the best way of solving 'pillowing' where joints or limbs that should be one continous shape look like seperately beveled parts.

One method is instead of using SpriteIlluminator to bump each sprite image seperately, export your full character or full limb from photoshop, bump that in SpriteIlluminator and then reimport it into photoshop and then cut it up and export it in the same way you cut up the character for animations.
This means the parts that should be one piece like a leg for example get bumped as they should.
Sure there's better methods though!

6 天 后

What are the limitations of these Shaders? I'm using this for my mobile game. The sprites (SpriteRenderer) flickering very hard on mobile. With flickering I mean appear / disappear of the sprites. Anyne facing the same issue?

Hi, I've been using your Shader extensively and I'm SUPER glad that it exists. Thank you very much for your effort, it's very much appreciated! 🙂

I have, however, one technical problem at the moment.
I've begun to realize that fading / tweening the alpha value from 1 to 0 or vice versa, when using your modified shader, produces a very strange behaviour: Whenever I do this it doesn't look like expected, the fading part of the spine object seems to be way too dark, almost like it mixes itself with pure black while fading. Very weird.

I illustrated what I mean by recording these 2 gifs:
1) This is how it SHOULD look, I recorded this using the default spine skeleton shaders.

图像因不支持 HTTPS 被隐藏。 | 仍然显示

2) This is how it looks when using the custom shader.

图像因不支持 HTTPS 被隐藏。 | 仍然显示

I hope you understand what I mean. Does anyone know what causes this? I already tried almost every export configuration I could think of and checked/unchecked almost every setting in the shader itself but it always looks like this.

Please help :S

This result looks like it's applying straight alpha to PMA colors.

If you are using the skeleton's alpha, make sure you disabled "PMA Vertex Colors" on the component.
If you are sliding the alpha on the material, the shader probably needs a flag somewhere, or needs to handle it. Or you need to use premultiplied alpha blending, which would mismatch if your exports are straight alpha.

Pharan :

This result looks like it's applying straight alpha to PMA colors.

If you are using the skeleton's alpha, make sure you disabled "PMA Vertex Colors" on the component.
If you are sliding the alpha on the material, the shader probably needs a flag somewhere, or needs to handle it. Or you need to use premultiplied alpha blending, which would mismatch if your exports are straight alpha.

Thank you so much! The disabling of "PMA Vertex Colors" did the trick, did not know that at all!

Thanks again, everything works perfectly, now! 🙂

2 个月 后

Hi there!

I was getting a bit worried not to receive any more notifications from this topic 😃

I had issues because I was using an older version of Unity. Now I upgraded to 5.5.3 and still have normal flipping issues.

The default shader works fine when building for android with normal (0,0,1), but in the editor they're reversed, making it harder to work with.

Unless I do some per-material runtime normal flipping when running on specific platforms.

Is this a known issue? Are you still supporting the shaders?

Thanks for your time 🙂

Updating this as well as it seems there's some problems since unity updated to 5.6 !

Now it still seems to work pretty well for spine exports as it goes. However I've been using them for "static" background objects as well and there's an odd transparency issue going on now

Any of you guys have issues with depth writing as well? I seem to get flickering on my character when he is running around in game. :doh:

6 天 后

This Shader is still not runing on mobile devices. I created e bug by Unity, multiple months ago, but no reaction. Maybe someone have a fix for this?

When using these Shader with a SpriteRenderer, it will flickering, or not even displayed. This is very annoying 🙁

Hey y'all! Been a while.
So I just realized I made a silly mistake in the shader fixed normal code which meant lighting would be incorrect on certain platforms. I've checked in a fix but it means from now on the fixed view normal should be defined as (0,0,1).
It should however now work consistently on all platforms.
Let me know if you see any bugs with it!

@AlaaNintendo I've had some Z fighting issues on 5.6, for some reason the depth buffer seems more compressed. Not entirely sure why yet but increasing the Z Spacing on your Skeleton Animation component should stop the Z fighting.

10 天 后

@ToddRivers good hearing back from ya! 🙂

I was getting flickering on 5.5, but I should update to 5.6 to test it out as well. It seems the flickering is gone on 5.5 at least, crossing fingers. Will let you know how it goes on 5.6!

Thanks again for the continued support on this amazing shader!! Let me know if there's anything I can help you out on.


22 Apr 2017, 04:55


@ToddRivers

Just updated to 5.6.0f3 Looks to be good on the flickering issue! Thanks alot for the shader support! We all owe ya a debt of gratitude~ :happy:

Getting this issue in the latest version.


25 Apr 2017, 12:29


ToddRivers :

...If in your game you rotate your sprites 180 degrees around Y to make sprites face the opposite way, you should also tick 'Allow Back Rendering' in order for lighting to work correctly when Sprites are facing away from the camera.
If you use negative scale or 'FlipX' instead then leave it unticked and it will save a little bit of processing time 🙂...

Where is this Allow Back Rendering? It is a Unity or Shader feature?

WARNING NOOB Questions below: :sweat:

  1. Vertex Lit: I can't figure out how to add more verts, is it done in Spine or Unity? EDIT: Yes you do it through the meshes in Spine Pro.

Is this bad for performance?

  1. Pixel Lit: When I drag the Z-spacing <0, the sorting orders get "messy". For example and initiated bullet goes below the character. What is the solution for this? Do I have to adjust the z of everything from now on, instead of the sorting orders?

  2. How do everyone do their fancy normal maps? Is there a plugin, or do people do these in Photoshop.

ps. love the shaders and Spine!

PeterBacall :

WARNING NOOB Questions below: :sweat:
Is this bad for performance?

I'm not an animator but I suppose it could be bad depending on how many chars like that you have on screen, but I simply don't have the required info about the use you want to do of it to provide a clear answer. Also, if you need the character to simply bend a bit (unless you're doing something procedural like applying a vertex shader which displaces the vertexes in some way), having that mesh is probably going to be a bit overkill, and I suppose you may end up having weird overlapping issues.

NeatWolf :
PeterBacall :

WARNING NOOB Questions below: :sweat:
Is this bad for performance?

I'm not an animator but I suppose it could be bad depending on how many chars like that you have on screen, but I simply don't have the required info about the use you want to do of it to provide a clear answer. Also, if you need the character to simply bend a bit (unless you're doing something procedural like applying a vertex shader which displaces the vertexes in some way), having that mesh is probably going to be a bit overkill, and I suppose you may end up having weird overlapping issues.

Thank you for the quick response! Here comes more info, correct me if I'm wrong:

I am using the Vertex Lit option in the Sprite Shaders. More verts (as ToddRivers stated earlier) gives a higher resolution light. So I generated a lot of them in Spine, mesh editor. I tried this and it surely results in a high resolution light.
My question is: at what point does the amount of verts get overkill for lighting (performance)?


I noticed I need a lot of vertices for the "Vertex Lit" option to be even near the result of "Pixel Lit". Why I'm not using "Pixel Lit" is because of the problems that occur, for example the Z-spacing making the sorting orders out of order. Overlapping characters were blending with each other etc. Therefore Vertex Lit seemed like a better choice. Can I have 400 verts on each character without really bad performance? I'm aiming for PC and MAC (no mobile).

I think the point here is that if you need to shine a spotlight-like thing on your sprite like in your gif, VertexLit is probably not the way to go.
VertexLit is more ideal for sort-of-ambient-but-slightly-directional light. (eg, "there's a campfire in front", or "there are floor lights in a dark room")

For performance metrics, you'd have to test on your slowest target machine.

Getting PixelLit on 2D Sprites in general is unfortunately still quite the conundrum, especially on Unity for now since its render pipeline is not programmable yet. Unity also has weird sorting bugs even if you set it up correctly. It's really weird.