• Unity
  • Sprite Shaders for Unity

Hey there!

I've tried using your shaders, specifically for the Overlay color aspect of them! That does exactly what I needed it to.

There is a problem, though. I have multiple instances of enemy characters. They all use the same SkeletonDataAsset, the same AtlasAsset, and therefore the same Materials. Therefore when I make just one of them flash red when taking damage, it makes all enemies of that type - enemies that use the same material - flash red, too.

I thought at first that I could make instances of the materials, but then it would break the AtlasAssets, as they are ScriptableObjects. I could instantiate the AtlasAssets, too, but they break the SkeletonDataAssets, because they're ScriptableObjects, too. I mean, I tried it, but with all that going on something broke completely. And I'm not a fan of creating whole new instances of things anyway as that will take up lots of memory.

Is this something you could provide some guidance with? Although perhaps this is more an architectural issue with Spine. I know before that the tinting via the "SetColor()" method was done by modifying the vertices of the mesh (I think).

Thanks very much!

@[삭제됨]
I think you want MaterialPropertyBlocks.
We have a small writeup about it here: https://github.com/pharan/spine-unity-docs/blob/master/Rendering.md#setting-material-properties-per-instance
Sorry for the lack of images, but there's sample code.
Essentially, setting a specific Renderer's property block overrides the Material asset's property values with its own, which allows you to set values per renderer instance.

I've put up screenshots of the list of property IDs, which you can see yourself by selecting the Shader in your inspector.
https://github.com/traggett/UnitySpriteShaders/issues/9#issuecomment-303629612

For example, to set a MaterialPropertyBlock's Overlay ("OverlayColor") property, you'd go:

MaterialPropertyBlock mpb = new MaterialPropertyBlock();
mpb.SetColor("_OverlayColor", Color.red);
GetComponent<MeshRenderer>().SetPropertyBlock(mpb);

This has been the preferred way to set material properties per Renderer in Unity for a while.

You may have seen modifying the returns of renderer.material or renderer.sharedMaterial as the method in very old Unity code but that has historically resulted in too many bad sideeffects.)

This is also probably the wrong thread. I'll move this to a new topic after you reply.

NeatWolf wrote
ToddRivers wrote

the latest shaders only support Unity 5.6 unfortunately. I don't have time to backwards support old version of Unity

Ouch :-/
Are the official shaders going to be at least 3 months backwards compatible?

Don't know if anyone realizes this, but this is probably the most popular thread on Spine's Unity forum. Almost reaching 24,000 views at this point. It's even more read than Pharan's official post http://esotericsoftware.com/forum/Noteworthy-Spine-Unity-Topics-5924

It'd be nice if the Spine guys could pick up the torch and continue to iterate \ support Sprite Shaders or just contract out the support work (both legacy and current Unity versions) to ToddRivers?

His shader makes a significant impact to the visual quality of Spine's animations and helps keep it on par with Unity's Standard Shader. (Without it maybe Anima2D has a leg up?)

ToddRivers, your contribution to Spine's visuals is a huge one, hopefully you get the recognition you deserve. :rock:

With so many lurkers in this thread, it's a shame only a select few bother to get involved in the conversation. If you guys are using this tool and appreciate it, say something..

That being said, I'm more or less following alongside ToddRivers, I'm updated to 5.6 and the shaders are working beautifully. ToddRivers should we update to 5.6.1 now? :party: Haha

You have to admit the topic and content of the first post is pretty SEO optimized.
It literally says "Sprite Shaders for Unity". Imagine how many people google that.
I just googled it and it's the 4th result.
Which is apt, because it's actually not Spine-specific. He actually uses it for more than just his Spine stuff.

I don't call the shots regarding who contracts who. But absolutely, anyone who uses this should credit him with big bold text in their game. It should be the first logo when the game first boots up. 'cause he shares his Sprite shaders to the world freely.

The current spine-unity 3.5 unitypackage is actually packaged for Unity 5.4 and includes the shaders in a 5.4 compatible state, though it probably doesn't handle some of the gotchas like platform-specific depth or normal direction weirdness, if any of that exists.

8일 후

How to get sharp shadow edges ( toon shading ) like in this video?

SOLVED:
Create a new texture with any resolution (power of two preferably), and paint the left half of the texture with a dark color, and the right half with white. Then place the texture in the Spine/Sprite/VertexLit material's Diffuse Ramp texture slot in Unity.

Yes, that's what Diffuse Ramp is for. 🙂

Thanks for sharing.

Is there any way to fix the problem that the light doesn't come from the same direction all the time?
It's as if the light moves with the object as the object rotates, and half way through the rotation the light flips to the other side. It looks really weird.
 Loading Image
See how the directional light always points the same direction, but the light never hits directly from the top or the bottom relative to the texture.

Is this a bug with the shader?

EDIT: Solved after many hours frustrating hours. Solve Tangents must be enabled under "Advanced" in SkeletonAnimation.cs.

Hi @Pharan,
It would be interesting to see if the majority of the lurkers on this thread are also Spine owners or just guys that googled it looking for a Sprite Shader.

It's a complicated topic on this shader. Good mention on the credit bit, for sure we should all be crediting ToddRivers in the game if we're using it.

Pharan wrote

You have to admit the topic and content of the first post is pretty SEO optimized.
It literally says "Sprite Shaders for Unity". Imagine how many people google that.
I just googled it and it's the 4th result.
Which is apt, because it's actually not Spine-specific. He actually uses it for more than just his Spine stuff.

I don't call the shots regarding who contracts who. But absolutely, anyone who uses this should credit him with big bold text in their game. It should be the first logo when the game first boots up. 'cause he shares his Sprite shaders to the world freely.

The current spine-unity 3.5 unitypackage is actually packaged for Unity 5.4 and includes the shaders in a 5.4 compatible state, though it probably doesn't handle some of the gotchas like platform-specific depth or normal direction weirdness, if any of that exists.

AlaNintendo wrote

It's a complicated topic on this shader. Good mention on the credit bit, for sure we should all be crediting ToddRivers in the game if we're using it.

Done 😉
(http://www.fatherandsongame.com)

 Loading Image

I noticed that after updating Unity the emission channel doesn't produce HDR effects, even if the Emission Power is set to very high values. To fix this I cannibalized the Standard Shader and its implementation of emission channel:

on line 704 of SpriteShaderGUI.cs - replaced this

_materialEditor.TexturePropertyWithHDRColor(_emissionText, _emissionMap, _emissionColor, new ColorPickerHDRConfig(0, 1, 0.01010101f, 3), true); 

with this

_materialEditor.TexturePropertyWithHDRColor(_emissionText, _emissionMap, _emissionColor, new ColorPickerHDRConfig(0f, 99f, 1 / 99f, 3f), true);
9일 후

Hello! Sorry to bother everyone. I'm kinda new to this lighting thing (and the programming side) in 2D games . I apologize if this isn't the right place to ask these types of questions. I'm using Unity and Spine Pro.

To create a normal map for a spine animation, I should take the atlas file that's exported from Spine then use software to create a normal map to it? Then apply the normal map to the material? Did I get that right? Is that the best way to do it?

Also, which software would you recommend for creating a normal map? So far I've seen SpriteLamp, Sprite Illuminator, Sprite Dlight, and the NVIDIA Texture Tools. I'm not sure which way to go.

Thanks for your time!

EDIT: Did a little more searching in the forum, seems like SpriteIlluminator is the way to go. Woo

Awesome credit! 8)

Btw congrats on the game release, I saw it on the new release list. Didn't know that was your game :party: ):

NeatWolf wrote
AlaNintendo wrote

It's a complicated topic on this shader. Good mention on the credit bit, for sure we should all be crediting ToddRivers in the game if we're using it.

Done 😉
(http://www.fatherandsongame.com)

 Loading Image


17 Jun 2017, 03:53


Hmm would it be possible to expose this into the Inspector for easier use?

new ColorPickerHDRConfig(0, 1, 0.01010101f, 3)
Gabriev wrote

I noticed that after updating Unity the emission channel doesn't produce HDR effects, even if the Emission Power is set to very high values. To fix this I cannibalized the Standard Shader and its implementation of emission channel:

on line 704 of SpriteShaderGUI.cs - replaced this

_materialEditor.TexturePropertyWithHDRColor(_emissionText, _emissionMap, _emissionColor, new ColorPickerHDRConfig(0, 1, 0.01010101f, 3), true); 

with this

_materialEditor.TexturePropertyWithHDRColor(_emissionText, _emissionMap, _emissionColor, new ColorPickerHDRConfig(0f, 99f, 1 / 99f, 3f), true);

Some real quality shaders, thanks for all the hard work ToddRivers!

Hey everyone!
Been a while. First cheers for all the thanks! I'm glad the shaders have been useful 🙂
I learnt to code by poking around other peoples open source code so feel it's good to give some back 😉

@NeatWolf thanks so much! You're game looks lovely, will have to try it! Did you play/see the Triennale Game Collection? That was a pretty cool collection of indie games put together by the art design museum in Milan.
I've added your emission fix as well 🙂

I stuck them on the asset store as well to try and help other peops find them.
https://www.assetstore.unity3d.com/en/#!/content/88191

24일 후

@ToddRivers Awesome!! Thanks for posting it onto the asset store 🙂

I'm sure lots of people will appreciate all your hard work !

한 달 후

Hey @ToddRivers we recently updated Spine-Unity and Spine-Csharp with the new runtime of Spine 3.6 and now all of our materials using your shaders look like this:

 Loading Image

We are using vertex lit with standard alpha (and the sprites come from Photoshop and they are being exported as standard alpha too) and they worked before.
Is this because we're using Unity 5.5.0f3?

Thanks!

7일 후

@ToddRivers I can attest to this bug as well. I'm on Unity2017 now

But I can't seem to reproduce it consistently... If I recall the fix was to use PNG and not TGA files. But that might not be a good choice? I heard TGA is supposedly better for alpha channel control :think:

17일 후

We fixed it!. The problem was that in the new shaders the combo box for the blend mode changed, so before we had Pre-multiplied Alpha (or whatever mode we were using like, soft add, add, etc) and with the update it changed every material to Opaque. That's why it looked like that 😉.

6일 후

Hi,
I am sorry for being a bit off topic. I am trying to modify Unity UI Sprite Default to support RectMask2d. But honestly i am totally a noob in shaders. I am trying to do this as with default UI shader am getting terrible fps drop. But I need masking and Sprite-Defult shader do not support it. I know that UI default shader uses stencil, but Sprite default does not. But this should not be problem as in unity documentation is stated that RectMask2d do not use stencil.