• Unity
  • Sprite Shaders for Unity

Same here, using Todd's latest version:

Unity v5.4.2f2 (building for Android), Win7 Ultimate 64bit

Previous ones didn't trigger any error.

Related Discussions
...

Amazing!!, it's always so nice to have great support. Definitely loving everything related Spine!
Thanks again!

Hey sorry for the late response, yeah I've been on the 5.5 beta so stuck some 5.5 only shader stuff in there by mistake.
5.5 is now out properly so I guess I'll leave it in so the shaders are correct for the latest version of Unity.

I guess most people will be grabbing the shaders via the spine runtimes now anyhow though, don't know what version of Unity they're targeting but might need to change some of the Unity variables to match it ๐Ÿ™‚

Hi @ToddRivers,

Great progress as always! And also very much appreciated for all your hard work and continued support on this tool! I hope the Spine guys are compensating your excellent addition, to an already awesome animation tool.... maybe some free licenses or something if you aren't accepting cash ? :party:

I also have a question about normal intensity, maybe I'm doing something wrong? I can't seem to get the same level of "normal" map bump using your tool compared to Unity's normal "Standard" shader. Any idea on what I'm doing wrong? (The left mario is using the Standard Shader, right is your sprite shader)

Thanks again!

Image removed due to the lack of support for HTTPS. | Show Anyway

Pls find the settings below.

Image removed due to the lack of support for HTTPS. | Show Anyway

AlaNintendo wrote

Hi @ToddRivers,

Great progress as always! And also very much appreciated for all your hard work and continued support on this tool! I hope the Spine guys are compensating your excellent addition, to an already awesome animation tool.... maybe some free licenses or something if you aren't accepting cash ? :party:

I also have a question about normal intensity, maybe I'm doing something wrong? I can't seem to get the same level of "normal" map bump using your tool compared to Unity's normal "Standard" shader. Any idea on what I'm doing wrong? (The left mario is using the Standard Shader, right is your sprite shader)

Thanks again!

Image removed due to the lack of support for HTTPS. | Show Anyway

+1 for normal intensity float multiplier in the shader ๐Ÿ˜›

@[deleted]
Does your mesh have tangents?

On top of that, it looks like the Standard shader is adding speculars which ToddRivers' shaders current doesn't do.

Is it possible that the shader (Pixel Lit) not running on mobile? If I use a Spine object its works. When I use a normale sprite it does not render on mobile. This worked weeks ago without any problem. Maybe this shader will not work without Spine object now?

Edit: Maybe something to do with this warning?

Hi!, I wanted to post a bug I think.

Why whenever my Spine character gets near a point light with Pixel Lit shader it looks like this?

Image removed due to the lack of support for HTTPS. | Show Anyway

The normals are set to X= 0, Y = 0, Z = 1 (If I use normals -1 it's not lit), the same with use mesh normals by the way.
If I use Vertex Lit the problem fades away but is not accurate in terms of lighting so I want to use Pixel Lit.
The light is behind the character, if it's in front it doesn't get lit.

Also another question. Why in Vertex Lit mode everything needs to be lit from the front, and in Pixel Lit everything has to be lit from back? I have to manually change normals in the shader to not have to change every light Z position.

1) This is just how pixel lighting in Unity works.
The same thing will happen with any pixel lit shader in Unity that doesn't write to depth and sprites on the same batched pass.

To fix it, write to depth, and add z-spacing.
This will cause other artifacts related to alpha-blended things that write to depth. This is an extensive topic in graphics programming and in any engine.

Again, here, this is just how pixel lighting in Unity works.

2) Normals should be (0, 0, -1). If the light direction acts incorrectly despite using that normals value, that's where the bug is.

@AlaNintendo, yeah like Pharan says what you're seeing is just the specular from the standard shader. The shader doen't support specular (yet!) so a better comparison would be to compare it with the 'Legacy Shaders/Bumped Diffuse' shader which doesn't have specular.
Its something I'll prob add at somepoint, along with a specular map as don't think it makes sense for the whole sprite to be shiny but bits like armour etc would look cool ๐Ÿ™‚

@Pharan so NeatWolf pointed out a bug with vertex lighting a while ago which meant he had to set the normal to (0,0,1). I fixed it in my github a while ago but not sure if you guys have kept up to date with the shaders in your runtimes?

@alcyongames As Pharan says pixel lighting will always cause overdraw unless you write to depth. Pixel lighting is split into multiple passes for each light. The only way a pass wont draw on top of a previous one is using a depth test. For that to work you need to write to depth (which means a hard alpha edge).

If you're art style has hard edges anyways that's not a problem, use pixel lighting just turn on write to depth.
If it doesn't (ie you've got faded edges) then use vertex lighting and increase the number of verts used in your spine animation (ie use mesh attachments instead of just quads) to make it more accurate.
With a decent number of verts you'll struggle to notice the difference between vertex and pixel lighting most of the time, and vertex lighting is faster (though increased number of verts is slightly more CPU intensive, vertex lighting is less GPU intensive).

, yeah like Pharan says what you're seeing is just the specular from the standard shader. The shader doen't support specular (yet!) so a better comparison would be to compare it with the 'Legacy Shaders/Bumped Diffuse' shader which doesn't have specular.
Its something I'll prob add at somepoint, along with a specular map as don't think it makes sense for the whole sprite to be shiny but bits like armour etc would look cool ๐Ÿ™‚

@ToddRivers @Pharan Ahh that would explain the difference in appearance. 8)

Ok crossing fingers , you or the Spine team can get around adding a specular map option :happy: :happy:

@ToddRivers should be up to date until Nov 24. I think that includes the normals fix.

ToddRivers wrote

@Pharan so NeatWolf pointed out a bug with vertex lighting a while ago which meant he had to set the normal to (0,0,1). I fixed it in my github a while ago but not sure if you guys have kept up to date with the shaders in your runtimes?

I updated them yesterday as well, but I still have to set them to (0,0,1) for Vertex Lit to work. If I switch to Pixel lit, -1 is ok.
Unity v5.4.2f2

@NeatWolf Yeah me too! "Use Mesh Normals" doesn't work, I have to manually set the normals for Pixel Lit to Z = -1. It works in other things though (I use Todd's Rivers shader in other assets like Ferr2D) and if I use pixel lit with "Use Mesh Normals" It works haha. Well it's not a problem though, I just have to set it up manually that's all.

Hey sorry for the delay. OK had another look at the vertex lighting macro's and think I found a bug! (I was using the view matrix instead of the inverse view matrix). I've checked in a fix to github so might be worth grabbing latest and seeing if it helps.
I also made the material editor work with multiple materials at the same time (i.e. multi-edit).

Another think to look out for is it might be worth trying to 'reset' the material (by clicking on the cog in the top right corner of the material editor) and then reapplying any settings.
Unity materials tend to accumilate loads of flags/defines/values whilst your editing them and switching shaders, which can potentially cause things to break.
I've hopely cleaned up the sprite material editor so it always sets and resets things properly but worth trying too if the fix doesn't help!

was my post ignored? ๐Ÿ™ or it isn't a problem?

dothem wrote

Is it possible that the shader (Pixel Lit) not running on mobile? If I use a Spine object its works. When I use a normale sprite it does not render on mobile. This worked weeks ago without any problem. Maybe this shader will not work without Spine object now?

Edit: Maybe something to do with this warning?

ToddRivers wrote

Hey sorry for the delay. OK had another look at the vertex lighting macro's and think I found a bug! (I was using the view matrix instead of the inverse view matrix). I've checked in a fix to github so might be worth grabbing latest and seeing if it helps.
I also made the material editor work with multiple materials at the same time (i.e. multi-edit).

Another think to look out for is it might be worth trying to 'reset' the material (by clicking on the cog in the top right corner of the material editor) and then reapplying any settings.
Unity materials tend to accumilate loads of flags/defines/values whilst your editing them and switching shaders, which can potentially cause things to break.
I've hopely cleaned up the sprite material editor so it always sets and resets things properly but worth trying too if the fix doesn't help!

I tried to import these latest shaders but I got a compiler error (targeting Android, Unity v5.4.2f2):

Shader error in 'Hidden/Internal-SpriteDepthNormalsTexture': unrecognized identifier 'UNITY_VERTEX_INPUT_INSTANCE_ID' at line 213 (on d3d11)

Compiling Vertex program
Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING

in UnitySpriteShaders-master\SpriteShaders\SpriteDepthNormalsTexture.shader

๐Ÿ˜ข

Argh thats just because you're not on Unity 5.5.

Its only a warning about the SpriteDepthNormalsTexture shader which you prob won't be using - the rest of the shaders will be uneffected ๐Ÿ™‚

@dothem sorry must've missed your post - what do you mean by 'normale sprite'? Like a sprite with a normal map?
The shaders should work on mobile and with spine animations.

ToddRivers wrote

Argh thats just because you're not on Unity 5.5.

Its only a warning about the SpriteDepthNormalsTexture shader which you prob won't be using - the rest of the shaders will be uneffected ๐Ÿ™‚

@dothem sorry must've missed your post - what do you mean by 'normale sprite'? Like a sprite with a normal map?
The shaders should work on mobile and with spine animations.

Yes, I can't upgrade now, not all of the assets I'm using are 5.5 compatible. ๐Ÿ˜ข

Yet, previous version worked like a charm. It's not really a warning, the shader doesn't compile at all. What should I change to solve the issue?